gipper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.gitignore +7 -0
  2. data/PostInstall.txt +5 -0
  3. data/README.rdoc +49 -0
  4. data/Rakefile +69 -0
  5. data/VERSION.yml +4 -0
  6. data/docs/gift_reference.pdf +0 -0
  7. data/features/fixtures/matching.gift +9 -0
  8. data/features/fixtures/missing_word.gift +8 -0
  9. data/features/fixtures/multiple_choice.gift +41 -0
  10. data/features/fixtures/numerical.gift +10 -0
  11. data/features/fixtures/short_answer.gift +10 -0
  12. data/features/fixtures/super_gift.txt +169 -0
  13. data/features/fixtures/true_or_false.gift +19 -0
  14. data/features/gift_parsing.feature +10 -0
  15. data/features/parse_matching_questions.feature +10 -0
  16. data/features/parse_missing_word.feature +10 -0
  17. data/features/parse_multiple_choice_questions.feature +10 -0
  18. data/features/parse_numerical_questions.feature +10 -0
  19. data/features/parse_short_answer_questions.feature +10 -0
  20. data/features/parse_true_or_false_questions.feature +10 -0
  21. data/features/steps/gift_parsing_steps.rb +546 -0
  22. data/features/steps/parse_matching_steps.rb +30 -0
  23. data/features/steps/parse_missing_word_steps.rb +58 -0
  24. data/features/steps/parse_multiple_choice_steps.rb +107 -0
  25. data/features/steps/parse_numerical_steps.rb +35 -0
  26. data/features/steps/parse_short_answer_steps.rb +42 -0
  27. data/features/steps/parse_steps.rb +7 -0
  28. data/features/steps/parse_true_or_false_steps.rb +61 -0
  29. data/features/support/env.rb +10 -0
  30. data/lib/answer.rb +165 -0
  31. data/lib/answers.rb +99 -0
  32. data/lib/gipper.rb +15 -0
  33. data/lib/question.rb +53 -0
  34. data/lib/quiz.rb +31 -0
  35. data/lib/special_charater_handler.rb +8 -0
  36. data/script/txt2html +71 -0
  37. data/script/txt2html.cmd +1 -0
  38. data/tasks/rspec.rake +21 -0
  39. data/test/answer_test.rb +152 -0
  40. data/test/answers_test.rb +126 -0
  41. data/test/custom_assertions.rb +68 -0
  42. data/test/fixtures/begins_with_comment.txt +6 -0
  43. data/test/question_test.rb +86 -0
  44. data/test/quiz_test.rb +65 -0
  45. data/test/special_character_handler_test.rb +43 -0
  46. data/test/test_helper.rb +19 -0
  47. metadata +125 -0
@@ -0,0 +1,126 @@
1
+ require 'test_helper'
2
+
3
+ class AnswersTest < Test::Unit::TestCase
4
+ def setup
5
+ @answers = Gipper::Answers.new
6
+ end
7
+
8
+
9
+ context "answer splitting" do
10
+ should "not split strings that do not contain answer delimiters" do
11
+ answers = @answers.send :split_apart, "this is a single answer"
12
+ assert_answers ["this is a single answer"], answers
13
+ end
14
+
15
+ should "split strings on twiddle" do
16
+ answers = @answers.send :split_apart, "~this ~answer has ~three parts"
17
+ assert_answers ["~this", "~answer has", "~three parts"], answers
18
+ end
19
+
20
+ should "split strings on equals" do
21
+ answers = @answers.send :split_apart, "=this =answer has =three parts"
22
+ assert_answers ["=this", "=answer has", "=three parts"], answers
23
+ end
24
+
25
+ should "split strings on equals and twiddles" do
26
+ answers = @answers.send :split_apart, "~this =answer has ~three parts"
27
+ assert_answers ["~this", "=answer has", "~three parts"], answers
28
+ end
29
+
30
+ should "not split strings on escaped equals and twiddles" do
31
+ answers = @answers.send :split_apart, "~this \\=answer has ~two parts"
32
+ assert_answers ["~this \\=answer has", "~two parts"], answers
33
+ end
34
+
35
+ should "split matching correctly" do
36
+ answers = @answers.send :split_apart, "=waffle -> cone =cheese -> cheddar"
37
+ assert_answers ["=waffle -> cone", "=cheese -> cheddar"], answers
38
+ end
39
+
40
+ should "be tolerant of input variance" do
41
+ answers = @answers.send :split_apart, " ~ %%%%%%% ~ UUUUUUUUU ~@@%^&* ~ 232323 = 2345 "
42
+ assert_answers ["~ %%%%%%%", "~ UUUUUUUUU", "~@@%^&*", "~ 232323", "= 2345"], answers
43
+ end
44
+
45
+ should "get answer conmments" do
46
+ answers = @answers.send :split_apart, " ~ %%%%%%%#foo = UUUUUUUUU #bar"
47
+ assert_answers ["~ %%%%%%%#foo", "= UUUUUUUUU #bar"], answers
48
+ end
49
+
50
+ should "get answer conmments when preceeded by a new line" do
51
+ answers = @answers.send :split_apart, "~ Oompa\r\n#kun\r\n = Loompa\r\n #pyakun"
52
+ assert_answers ["~ Oompa\r\n#kun", "= Loompa\r\n #pyakun"], answers
53
+ end
54
+
55
+ # If you want to use curly braces, { or }, or equal sign, =,
56
+ # or # or ~ in a GIFT file (for example in a math question including
57
+ # TeX expressions) you must "escape" them by preceding them with a \
58
+ # directly in front of each { or } or =.
59
+ should "ignore all escaped characters" do
60
+ answers = @answers.send :split_apart, "~ \\{\\}\\~\\=\\#foo =\\{\\}\\~\\=\\#bar"
61
+ assert_answers ["~ \\{\\}\\~\\=\\#foo", "=\\{\\}\\~\\=\\#bar"], answers
62
+ end
63
+ end
64
+
65
+ context "splitting numerical answers" do
66
+ setup do
67
+ @answers = Gipper::Answers.new
68
+ end
69
+
70
+ should "determine numerical by a leading pound" do
71
+ assert @answers.send :is_numerical?, "#333"
72
+ end
73
+
74
+ should "understand numerical answer format" do
75
+ result = @answers.send :split_apart, "2000:3"
76
+ assert_answers ["2000:3"], result
77
+ end
78
+
79
+ should "understand multiple numerical answer format" do
80
+ result = @answers.send :split_apart, "=2000:0 #Whoopdee do! =%50%2000:3 #Yippers"
81
+ assert_answers ["=2000:0 #Whoopdee do!", "=%50%2000:3 #Yippers"], result
82
+ end
83
+ end
84
+
85
+ context "when determining the answer style" do
86
+ should "return a style of true_false when it has one answer of true and no text" do
87
+ @answers.parse("T")
88
+ assert_equal :true_false, @answers.find_style
89
+ end
90
+
91
+ should "return a style of true_false when it has one answer of false and no text" do
92
+ @answers.parse("F")
93
+ assert_equal :true_false, @answers.find_style
94
+ end
95
+
96
+ should "return a style of multiple choice when it has more than one answer and text and only one answer is true" do
97
+ @answers.parse("~foo =bar")
98
+ assert_equal :multiple_choice, @answers.find_style
99
+ end
100
+
101
+ should "return a style of short answer when it has more than one answer and text and all answers are true" do
102
+ @answers.parse("=foo =bar")
103
+ assert_equal :short_answer, @answers.find_style
104
+ end
105
+
106
+ should "return a style of short answer when it has one true answer and text" do
107
+ @answers.parse("=foo")
108
+ assert_equal :short_answer, @answers.find_style
109
+ end
110
+
111
+ should "return a style of short answer when it has one true answer and text without equals" do
112
+ @answers.parse("5")
113
+ assert_equal :short_answer, @answers.find_style
114
+ end
115
+
116
+ should "return a style of matching when correct contains a string ->" do
117
+ @answers.parse("=foo -> bar")
118
+ assert_equal :matching, @answers.find_style
119
+ end
120
+
121
+ should "return a style of matching when correct contains a symbols ->" do
122
+ @answers.parse("=:) -> smiley")
123
+ assert_equal :matching, @answers.find_style
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,68 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ module CustomAssertions
5
+ def assert_answers correct, results
6
+ assert_equal correct.length, results.length
7
+ correct.each_with_index do |s, i|
8
+ assert_equal s, results[i]
9
+ end
10
+ end
11
+
12
+ def assert_question question, expected={}
13
+ check_expected question, expected, :text_post
14
+ check_expected question, expected, :answer
15
+ check_expected question, expected, :title
16
+ check_expected question, expected, :text
17
+ check_expected question, expected, :style
18
+ check_expected question, expected, :format
19
+ end
20
+
21
+ def assert_answer answer, expected={}
22
+ check_expected answer, expected, :correct
23
+ check_expected answer, expected, :text
24
+ check_expected answer, expected, :comment
25
+ check_expected answer, expected, :range
26
+ check_expected answer, expected, :weight
27
+ end
28
+
29
+ def assert_false value
30
+ assert FalseClass, value.class
31
+ end
32
+
33
+ def assert_question_parsing text, expected={}
34
+ question = Gipper::Question.new
35
+
36
+ question.parse text
37
+
38
+ assert_question question, expected
39
+ end
40
+
41
+ def assert_answer_parsing text, expected={}
42
+ answer = Gipper::Answer.new
43
+
44
+ if expected[:numerical]
45
+ answer.parse text, :numerical
46
+ else
47
+ answer.parse text
48
+ end
49
+
50
+ assert_answer answer, expected
51
+ end
52
+
53
+ def check_expected obj, expected, key
54
+ if expected.has_key? key
55
+ actual = (obj.send key.to_s)
56
+ if expected[key].nil?
57
+ assert_nil actual, "key #{key.to_s} expected to be nil got #{actual}"
58
+ else
59
+ if actual.class == Float
60
+ assert_in_delta expected[key], actual, 0.00001, "key #{key.to_s} expected #{expected[key]} got #{actual} with tolerence of .00001"
61
+ else
62
+ assert_equal expected[key], actual, "key #{key.to_s} expected #{expected[key]} got #{actual}"
63
+ end
64
+
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,6 @@
1
+ // Basic GIFT questions
2
+ // GIFT filter and documentation by Paul Tsuchido Shew http://ac.shew.jp.
3
+ //---------------------------
4
+
5
+ 1=1{T}
6
+
@@ -0,0 +1,86 @@
1
+ require 'test_helper'
2
+
3
+ class QuestionTest < Test::Unit::TestCase
4
+ def setup
5
+ @q = Gipper::Question.new
6
+ end
7
+
8
+ context "(when passed a single question without comments or title)" do
9
+
10
+ setup do
11
+ @single_question = "wubble."
12
+ @single_answer = "{=:) -> smiley}"
13
+ single_input = @single_question + @single_answer
14
+
15
+ @q.parse(single_input)
16
+ end
17
+
18
+ should "return the question" do
19
+ assert_equal "wubble.", @q.text
20
+ end
21
+
22
+ should "return the answer" do
23
+ assert_equal "smiley", @q.answer[0].correct
24
+ end
25
+
26
+ should "return the answer match" do
27
+ assert_equal ":)", @q.answer[0].text
28
+ end
29
+
30
+ should "return the style" do
31
+ assert_equal :matching, @q.style
32
+ end
33
+ end
34
+
35
+ context "(when passed a single question with title but without comments)" do
36
+
37
+ setup do
38
+ @single_title = "SuperTitle"
39
+ @single_question = "Titles are bad."
40
+ @single_answer = "{F}"
41
+ single_input = "::#{@single_title}::#{@single_question}#{@single_answer}"
42
+
43
+ @q.parse(single_input)
44
+ end
45
+
46
+ should "return the question" do
47
+ assert_equal @single_question, @q.text
48
+ end
49
+
50
+ should "return the answer" do
51
+ assert_false @q.answer[0].correct
52
+ end
53
+
54
+ should "return the style" do
55
+ assert_equal :true_false, @q.style
56
+ end
57
+
58
+ should "return the title" do
59
+ assert_equal @single_title, @q.title
60
+ end
61
+ end
62
+
63
+ context "when passed a question with escaped brackets" do
64
+ should "ignore the brackets" do
65
+ assert_question_parsing ' foo \\{escaped bracketed text\\}{T}',
66
+ :text => "foo {escaped bracketed text}",
67
+ :style => :true_false
68
+ end
69
+
70
+
71
+ should "handle all kinds of escaped stuff" do
72
+ assert_question_parsing ' my crazy \\#\\~\\= question \\{escaped bracketed text\\}{=\\=\\#\\~foo#hi-yah}',
73
+ :text => "my crazy #~= question {escaped bracketed text}",
74
+ :style => :short_answer
75
+ end
76
+ end
77
+
78
+ context "when determining the answer style" do
79
+ should "return missing word when question_post is present" do
80
+ assert_question_parsing "foo {=bar ~baz} cheese.",
81
+ :text => "foo",
82
+ :text_post => "cheese.",
83
+ :style => :missing_word
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,65 @@
1
+ require 'test_helper'
2
+
3
+ class QuizTest < Test::Unit::TestCase
4
+ context "simple question" do
5
+ setup do
6
+ @single_question = "This is a really lame question"
7
+ @single_answer = "{T}"
8
+ end
9
+
10
+ should "remove commented lines before parsing" do
11
+ file = File.open(File.join(File.dirname(__FILE__), *%w[fixtures begins_with_comment.txt]))
12
+ Gipper::Quiz.new.iterate_through file.read do |q|
13
+ assert_equal "1=1{T}", q
14
+ end
15
+ end
16
+ end
17
+
18
+ should "return just a question mark for question_post when question_post is just a question mark" do
19
+ quiz = Gipper::Quiz.parse 'You say that, "money is the root of all evil", I ask you "what is the root of all {~honey ~bunnies =money}?"'
20
+ assert_equal 'You say that, "money is the root of all evil", I ask you "what is the root of all', quiz[0].text
21
+ assert_equal '?"', quiz[0].text_post
22
+
23
+ answers = quiz[0].answer
24
+ assert_false answers[0].correct
25
+ assert_equal "honey", answers[0].text
26
+ assert_false answers[1].correct
27
+ assert_equal "bunnies", answers[1].text
28
+ assert answers[2].correct
29
+ assert_equal "money", answers[2].text
30
+ end
31
+
32
+ context "(when passed an empty string)" do
33
+ should "should return an empty array" do
34
+ quiz = Gipper::Quiz.parse("")
35
+ assert_equal [], quiz
36
+ end
37
+ end
38
+
39
+ context "(when passed more than one question)" do
40
+ should "should return an array with questions" do
41
+ q = []
42
+ q << true_false_question("Weather Patterns in the Pacific Northwest", "Seattle is rainy.", "{T}")
43
+ q << true_false_question("", "Seattle has lots of water.", "{T}")
44
+ q << true_false_question("Accessories in the Pacific Northwest", "People in Seattle use umbrellas:", "{T}")
45
+
46
+ multiple_input = "//opening comment\r\n//another comment\r\n\r\n\r\n#{q[0]}\r\n//this is a \r\n//couple rows of comments\r\n\r\n#{q[1]}\r\n\r\n#{q[2]}"
47
+
48
+ Gipper::Quiz.new.iterate_through(multiple_input) do |qu|
49
+ assert q.include?(qu)
50
+ end
51
+ end
52
+
53
+ should "ignore whitespace between questions" do
54
+ quiz = "a\r\n\t\r\nb\r\n \r\nc\r\n\r\nd"
55
+ count = 0
56
+
57
+ Gipper::Quiz.new.iterate_through(quiz) do |qu|
58
+ expected = ['a', 'b', 'c', 'd']
59
+ assert_equal expected[count], qu
60
+ count = count + 1
61
+ end
62
+ assert_equal 4, count
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class SpecialCharacterHandlerTest < Test::Unit::TestCase
4
+ include Gipper::SpecialCharacterHandler
5
+
6
+ context "striping escapes" do
7
+ should "leave normal text alone" do
8
+ result = unescape("This is some normal text.")
9
+ assert_equal "This is some normal text.", result
10
+ end
11
+
12
+ #(~|=|#|\{|\})
13
+ should "remove escape from escaped twiddles" do
14
+ result = unescape("This is some twiddled \\~ text.")
15
+ assert_equal "This is some twiddled ~ text.", result
16
+ end
17
+
18
+ should "remove escape from escaped equals" do
19
+ result = unescape("This is some equaled \\= text.")
20
+ assert_equal "This is some equaled = text.", result
21
+ end
22
+
23
+ should "remove escape from escaped pounded" do
24
+ result = unescape("This is some pounded \\# text.")
25
+ assert_equal "This is some pounded # text.", result
26
+ end
27
+
28
+ should "remove escape from escaped left brackets" do
29
+ result = unescape("This is some left bracketed \\{ text.")
30
+ assert_equal "This is some left bracketed { text.", result
31
+ end
32
+
33
+ should "remove escape from escaped right brackets" do
34
+ result = unescape("This is some right bracketed \\} text.")
35
+ assert_equal "This is some right bracketed } text.", result
36
+ end
37
+
38
+ should "not remove escapes from other characters" do
39
+ result = unescape("\\This \\is \\some \\normal \\text\\.")
40
+ assert_equal "\\This \\is \\some \\normal \\text\\.", result
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'custom_assertions'
8
+ require 'gipper'
9
+
10
+ class Test::Unit::TestCase
11
+ include CustomAssertions
12
+ def true_false_question title, question, answer
13
+ if title
14
+ "::#{title}::#{question}#{answer}"
15
+ else
16
+ "#{question}#{answer}"
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gipper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamal Hansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-22 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: oniguruma
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: technicalpickles-shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description:
36
+ email: jamal.hansen@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ files:
44
+ - .gitignore
45
+ - PostInstall.txt
46
+ - README.rdoc
47
+ - Rakefile
48
+ - VERSION.yml
49
+ - docs/gift_reference.pdf
50
+ - features/fixtures/matching.gift
51
+ - features/fixtures/missing_word.gift
52
+ - features/fixtures/multiple_choice.gift
53
+ - features/fixtures/numerical.gift
54
+ - features/fixtures/short_answer.gift
55
+ - features/fixtures/super_gift.txt
56
+ - features/fixtures/true_or_false.gift
57
+ - features/gift_parsing.feature
58
+ - features/parse_matching_questions.feature
59
+ - features/parse_missing_word.feature
60
+ - features/parse_multiple_choice_questions.feature
61
+ - features/parse_numerical_questions.feature
62
+ - features/parse_short_answer_questions.feature
63
+ - features/parse_true_or_false_questions.feature
64
+ - features/steps/gift_parsing_steps.rb
65
+ - features/steps/parse_matching_steps.rb
66
+ - features/steps/parse_missing_word_steps.rb
67
+ - features/steps/parse_multiple_choice_steps.rb
68
+ - features/steps/parse_numerical_steps.rb
69
+ - features/steps/parse_short_answer_steps.rb
70
+ - features/steps/parse_steps.rb
71
+ - features/steps/parse_true_or_false_steps.rb
72
+ - features/support/env.rb
73
+ - lib/answer.rb
74
+ - lib/answers.rb
75
+ - lib/gipper.rb
76
+ - lib/question.rb
77
+ - lib/quiz.rb
78
+ - lib/special_charater_handler.rb
79
+ - script/txt2html
80
+ - script/txt2html.cmd
81
+ - tasks/rspec.rake
82
+ - test/answer_test.rb
83
+ - test/answers_test.rb
84
+ - test/custom_assertions.rb
85
+ - test/fixtures/begins_with_comment.txt
86
+ - test/question_test.rb
87
+ - test/quiz_test.rb
88
+ - test/special_character_handler_test.rb
89
+ - test/test_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://github.com/rubyyot/gipper
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options:
96
+ - --charset=UTF-8
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: "0"
110
+ version:
111
+ requirements: []
112
+
113
+ rubyforge_project: gipper
114
+ rubygems_version: 1.3.5
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: A gem for parsing the GIFT quiz file format
118
+ test_files:
119
+ - test/custom_assertions.rb
120
+ - test/quiz_test.rb
121
+ - test/question_test.rb
122
+ - test/test_helper.rb
123
+ - test/answer_test.rb
124
+ - test/special_character_handler_test.rb
125
+ - test/answers_test.rb