gift-parser 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ require 'pp'
2
+ require 'test/unit'
3
+ require 'test/unit/ui/console/testrunner'
4
+
5
+ require File.expand_path('../../lib/gift', __FILE__)
6
+
7
+ class GiftTest < Test::Unit::TestCase
8
+
9
+ def test_create_from_string
10
+ gift = Gift::Gift.new("This is a description")
11
+ assert gift.questions.length == 1
12
+ assert gift.questions.first.class == Gift::DescriptionQuestion
13
+ assert gift.questions.first.text == "This is a description"
14
+ end
15
+
16
+ def test_create_from_file
17
+ gift = Gift::Gift.new(File.open(File.expand_path("../GIFT-examples.txt", __FILE__)))
18
+ assert !gift.root.nil?, "Cannot parse the file."
19
+ assert gift.questions.length == 8, "Expected 8 questions got: #{gift.questions.length}"
20
+ end
21
+
22
+ def test_raising_error_when_input_is_bad
23
+ assert_raises ArgumentError do
24
+ Gift::Gift.new("This is bad gift{}..")
25
+ end
26
+ end
27
+
28
+ def test_true_false_question_answers
29
+ g = Gift::Gift.new(File.open(File.expand_path("../GIFT-examples.txt", __FILE__)))
30
+ assert g.questions[0].mark_answer(true) == 100
31
+ assert g.questions[0].mark_answer(false) == 0
32
+ end
33
+
34
+ def test_multiple_choice_answers
35
+ g = Gift::Gift.new(File.open(File.expand_path("../GIFT-examples.txt", __FILE__)))
36
+ assert g.questions[1].mark_answer("yellow") == 100
37
+ assert g.questions[1].mark_answer("red") == 0
38
+ assert g.questions[1].mark_answer("blue") == 0
39
+ end
40
+
41
+ def test_fill_in_the_blank
42
+ g = Gift::Gift.new(File.open(File.expand_path("../GIFT-examples.txt", __FILE__)))
43
+ assert g.questions[2].mark_answer("two") == 100
44
+ assert g.questions[2].mark_answer("2") == 100
45
+ assert g.questions[2].mark_answer("red") == 0
46
+ end
47
+
48
+ def test_matching_question
49
+ g = Gift::Gift.new(File.open(File.expand_path("../GIFT-examples.txt", __FILE__)))
50
+ assert g.questions[3].mark_answer({"cat" => "cat food", "dog" => "dog food"}) == 100
51
+ assert g.questions[3].mark_answer({"cat" => "dog food", "dog" => "cat food"}) == 0
52
+ end
53
+ end
54
+
55
+ Test::Unit::UI::Console::TestRunner.run(GiftTest)
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gift-parser
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Stuart Coyle
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-23 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A library for parsing the Moodle GIFT question format.
22
+ email: stuart.coyle@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README
29
+ files:
30
+ - .gitignore
31
+ - LICENCE
32
+ - README
33
+ - RakeFile
34
+ - VERSION
35
+ - gift-parser.gemspec
36
+ - github.com
37
+ - lib/gift.rb
38
+ - lib/gift_parser.rb
39
+ - src/gift_parser.treetop
40
+ - test/GIFT-examples.rb
41
+ - test/GIFT-examples.txt
42
+ - test/gift_semantic_test.rb
43
+ - test/gift_syntax_test.rb
44
+ - test/gift_test.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/stuart/gift-parser
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Moodle GIFT format parser
75
+ test_files:
76
+ - test/GIFT-examples.rb
77
+ - test/gift_semantic_test.rb
78
+ - test/gift_syntax_test.rb
79
+ - test/gift_test.rb