quiz_master 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Reorderer do
4
+ describe "reorder" do
5
+ it "should reorder an array as specified" do
6
+ Reorderer.new(0, 2, 1, 3).reorder(%w(a b c d)).must_equal(%w(a c b d))
7
+ end
8
+
9
+ it "should fail if the array to be sorted is the wrong size" do
10
+ lambda do
11
+ Reorderer.new(0, 2, 1, 3).reorder(%w(a b c))
12
+ end.must_raise(ArgumentError)
13
+ end
14
+ end
15
+
16
+ describe "initialize" do
17
+ it "should fail with no arguments" do
18
+ -> { Reorderer.new }.must_raise(ArgumentError)
19
+ end
20
+
21
+ it "should fail with an empty indices argument" do
22
+ -> { Reorderer.new([]) }.must_raise(ArgumentError)
23
+ end
24
+
25
+ it 'should fail with a "bad" set of arguments' do
26
+ -> { Reorderer.new(0, 1, 3, 4) }.must_raise(ArgumentError)
27
+ end
28
+
29
+ it "should succeed when passed a list" do
30
+ Reorderer.new(0, 1).must_be_kind_of(Reorderer)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_helper"
2
+
3
+ describe ReorderingVector do
4
+ describe "initialize" do
5
+ it "should fail with no arguments" do
6
+ -> { ReorderingVector.new }.must_raise(ArgumentError)
7
+ end
8
+
9
+ it "should contain all the indices" do
10
+ ReorderingVector.new([false] * 10).to_a.sort.must_equal((0 .. 9).to_a)
11
+ end
12
+
13
+ it 'should "shuffle" non anchored indices' do
14
+ # [0, 1, 2, 3, 4, 5] has 1 & 5 anchored, and we use "reverse" as the
15
+ # shuffling function, so we should get back [4, 1, 3, 2, 0, 5]
16
+ anchored = [false, true, false, false, false, true]
17
+ r = ReorderingVector.new(anchored) { |a| a.reverse }
18
+ r.to_a.must_equal([4, 1, 3, 2, 0, 5])
19
+ end
20
+ end
21
+
22
+ describe "[]" do
23
+ it "should pull the right values out of the vector" do
24
+ r = ReorderingVector.new([true, true])
25
+ r[0].must_equal(0)
26
+ r[1].must_equal(1)
27
+ end
28
+ end
29
+
30
+ describe "to_a" do
31
+ it "should convert to an array" do
32
+ ReorderingVector.new([true, true]).to_a.must_equal([0, 1])
33
+ end
34
+ end
35
+
36
+ describe "to_ary" do
37
+ it "should convert to an array" do
38
+ a, b = ReorderingVector.new([true, true])
39
+ [a, b].must_equal([0, 1])
40
+ end
41
+ end
42
+
43
+ describe "size" do
44
+ it "should be the right size" do
45
+ ReorderingVector.new([false] * 10).size.must_equal(10)
46
+ end
47
+ end
48
+
49
+ describe "each" do
50
+ it "should do each" do
51
+ res = []
52
+ ReorderingVector.new([false] * 10).each do |i|
53
+ res << i
54
+ end
55
+
56
+ res.sort.must_equal((0 ... 10).to_a)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,58 @@
1
+ require "minitest/autorun"
2
+
3
+ require "quiz_master"
4
+ include QuizMaster
5
+
6
+ # For simple testing I wanted a pool of example questions.
7
+ EXAMPLE_QUESTION_PARAMS = [
8
+ {
9
+ prompt: "Example 1 prompt",
10
+ answers: [
11
+ Answer.new("This is the first answer", false, tag: "5"),
12
+ Answer.new("This is the second answer", true),
13
+ Answer.new("This is the third answer", false, tag: "3"),
14
+ Answer.new("{{3}} and {{5}}", false)
15
+ ]
16
+ },
17
+ {
18
+ prompt: "Example 2 prompt",
19
+ answers: [
20
+ Answer.new("This is the first answer", false, tag: "tag"),
21
+ Answer.new("This is the second answer", false),
22
+ Answer.new("This is the third answer", false),
23
+ Answer.new("This is the fourth answer {{tag}}", true)
24
+ ]
25
+ },
26
+ {
27
+ prompt: "What is the colour of a Banana?",
28
+ answers: [
29
+ Answer.new("Green", false),
30
+ Answer.new("Red", false, tag: "red"),
31
+ Answer.new("Yellow", false),
32
+ Answer.new("Black", false),
33
+ Answer.new("Brown", false),
34
+ Answer.new("Blue", false, tag: "blue"),
35
+ Answer.new("All of the colours above", false, anchored: true),
36
+ Answer.new("All of the colours above except {{blue}} and {{red}}", true,
37
+ anchored: true)
38
+ ]
39
+ }
40
+ ]
41
+
42
+ # Render the example Questions.
43
+ #
44
+ # first_tag - The initial tag, defaults to 'a'
45
+ #
46
+ # Returns an Array of RenderedQuestions.
47
+ def example_rendered_questions(first_tag: "a")
48
+ EXAMPLE_QUESTION_PARAMS
49
+ .map { |p| p.merge(first_tag: first_tag) }
50
+ .map { |p| RenderedQuestion.new(p) }
51
+ end
52
+
53
+ # Construct the example Questions.
54
+ #
55
+ # Returns an Array of Quesitons.
56
+ def example_questions
57
+ EXAMPLE_QUESTION_PARAMS.map { |p| Question.new(p) }
58
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ expected_output = <<ETX
4
+ 1) b
5
+ 2) d
6
+ ETX
7
+
8
+ quiz = Quiz.new(example_rendered_questions.values_at(0, 1))
9
+
10
+ describe TextAnswerSheetFormatter do
11
+ it "formats a quiz answer sheet as text correctly" do
12
+ TextAnswerSheetFormatter.new.format(quiz).must_equal expected_output
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ expected_output = <<ETX
4
+ 1) Example 1 prompt
5
+
6
+ a) This is the first answer
7
+ b) This is the second answer
8
+ c) This is the third answer
9
+ d) (a) and (c)
10
+ ETX
11
+
12
+ q = example_questions.first
13
+
14
+ describe TextQuestionFormatter do
15
+ it "formats a single question correctly" do
16
+ TextQuestionFormatter.new.format(q, 1).must_equal expected_output
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ expected_output = <<ETX
4
+ Header
5
+
6
+ 1) Example 1 prompt
7
+
8
+ a) This is the first answer
9
+ b) This is the second answer
10
+ c) This is the third answer
11
+ d) (a) and (c)
12
+
13
+ 2) What is the colour of a Banana?
14
+
15
+ a) Green
16
+ b) Red
17
+ c) Yellow
18
+ d) Black
19
+ e) Brown
20
+ f) Blue
21
+ g) All of the colours above
22
+ h) All of the colours above except (b) and (f)
23
+
24
+ Footer
25
+ ETX
26
+
27
+ quiz = Quiz.new(example_rendered_questions.values_at(0, 2),
28
+ header: "Header", footer: "Footer")
29
+
30
+ describe TextQuestionSheetFormatter do
31
+ it "formats a test OK" do
32
+ TextQuestionSheetFormatter.new.format(quiz).must_equal expected_output
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require "spec_helper"
2
+
3
+ describe VERSION do
4
+ it "has the correct format" do
5
+ VERSION.must_match(/\A \d+ \. \d+ \. \d+ \Z/x)
6
+ end
7
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quiz_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Stok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,16 +114,26 @@ files:
114
114
  - lib/quiz_master/answers_renderer.rb
115
115
  - lib/quiz_master/question.rb
116
116
  - lib/quiz_master/quiz.rb
117
+ - lib/quiz_master/quiz_variant.rb
117
118
  - lib/quiz_master/rendered_question.rb
119
+ - lib/quiz_master/reorderer.rb
120
+ - lib/quiz_master/reordering_vector.rb
118
121
  - lib/quiz_master/text_answer_sheet_formatter.rb
119
122
  - lib/quiz_master/text_assembler.rb
120
123
  - lib/quiz_master/text_question_formatter.rb
121
124
  - lib/quiz_master/text_question_sheet_formatter.rb
122
125
  - lib/quiz_master/version.rb
123
126
  - quiz_master.gemspec
124
- - test/test_text_answer_sheet_formatter.rb
125
- - test/test_text_question_formatter.rb
126
- - test/test_text_question_sheet_formatter.rb
127
+ - test/question_spec.rb
128
+ - test/quiz_spec.rb
129
+ - test/quiz_variant_spec.rb
130
+ - test/reorderer_spec.rb
131
+ - test/reordering_vector_spec.rb
132
+ - test/spec_helper.rb
133
+ - test/text_answer_sheet_formatter_spec.rb
134
+ - test/text_question_formatter_spec.rb
135
+ - test/text_question_sheet_formatter_spec.rb
136
+ - test/version_spec.rb
127
137
  homepage: https://github.com/mikestok/quiz_master
128
138
  licenses:
129
139
  - MIT
@@ -134,9 +144,9 @@ require_paths:
134
144
  - lib
135
145
  required_ruby_version: !ruby/object:Gem::Requirement
136
146
  requirements:
137
- - - ">="
147
+ - - "~>"
138
148
  - !ruby/object:Gem::Version
139
- version: '0'
149
+ version: '2.1'
140
150
  required_rubygems_version: !ruby/object:Gem::Requirement
141
151
  requirements:
142
152
  - - ">="
@@ -149,7 +159,14 @@ signing_key:
149
159
  specification_version: 4
150
160
  summary: Simple manager for multiple choice quizzes
151
161
  test_files:
152
- - test/test_text_answer_sheet_formatter.rb
153
- - test/test_text_question_formatter.rb
154
- - test/test_text_question_sheet_formatter.rb
162
+ - test/question_spec.rb
163
+ - test/quiz_spec.rb
164
+ - test/quiz_variant_spec.rb
165
+ - test/reorderer_spec.rb
166
+ - test/reordering_vector_spec.rb
167
+ - test/spec_helper.rb
168
+ - test/text_answer_sheet_formatter_spec.rb
169
+ - test/text_question_formatter_spec.rb
170
+ - test/text_question_sheet_formatter_spec.rb
171
+ - test/version_spec.rb
155
172
  has_rdoc:
@@ -1,39 +0,0 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'quiz_master'
4
-
5
- include QuizMaster
6
-
7
- expected_output = <<ETX
8
- 1) b
9
- 2) d
10
- ETX
11
-
12
- q1 = RenderedQuestion.new(
13
- prompt: 'This is the prompt. It poses the question.',
14
- answers: [
15
- Answer.new('This is the first answer', false, '5'),
16
- Answer.new('This is the second answer', true),
17
- Answer.new('This is the third answer', false, '3'),
18
- Answer.new('This is the fourth answer {{tag', false)
19
- ],
20
- first_tag: 'a'
21
- )
22
- q2 = RenderedQuestion.new(
23
- prompt: 'This is the prompt. It poses the question.',
24
- answers: [
25
- Answer.new('This is the first answer', false, 'tag'),
26
- Answer.new('This is the second answer', false),
27
- Answer.new('This is the third answer', false),
28
- Answer.new('This is the fourth answer {{tag}}', true)
29
- ],
30
- first_tag: 'a'
31
- )
32
-
33
- quiz = Quiz.new([q1, q2])
34
-
35
- describe TextAnswerSheetFormatter do
36
- it 'formats a single question test OK' do
37
- TextAnswerSheetFormatter.new.format(quiz).must_equal expected_output
38
- end
39
- end
@@ -1,30 +0,0 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'quiz_master'
4
-
5
- include QuizMaster
6
-
7
- expected_output = <<ETX
8
- 1) This is the prompt. It poses the question.
9
-
10
- a) This is the first answer
11
- b) This is the second answer
12
- c) This is the third answer
13
- d) (a) and (c)
14
- ETX
15
-
16
- q = Question.new(
17
- prompt: 'This is the prompt. It poses the question.',
18
- answers: [
19
- Answer.new('This is the first answer', false, '5'),
20
- Answer.new('This is the second answer', true),
21
- Answer.new('This is the third answer', false, '3'),
22
- Answer.new('{{3}} and {{5}}', false)
23
- ]
24
- )
25
-
26
- describe TextQuestionFormatter do
27
- it 'formats a single question test OK' do
28
- TextQuestionFormatter.new.format(q, 1).must_equal expected_output
29
- end
30
- end
@@ -1,56 +0,0 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'quiz_master'
4
-
5
- include QuizMaster
6
-
7
- expected_output = <<ETX
8
- Header
9
-
10
- 1) This is the prompt. It poses the question.
11
-
12
- a) This is the first answer
13
- b) This is the second answer
14
- c) This is the third answer
15
- d) (a) and (c)
16
-
17
- 2) What is the colour of a Banana?
18
-
19
- a) Red
20
- b) Green
21
- c) Yellow
22
- d) Brown
23
- e) Black
24
- f) All of the above except (a)
25
-
26
- Footer
27
- ETX
28
-
29
- q = Question.new(
30
- prompt: 'This is the prompt. It poses the question.',
31
- answers: [
32
- Answer.new('This is the first answer', false, '5'),
33
- Answer.new('This is the second answer', false),
34
- Answer.new('This is the third answer', true, '3'),
35
- Answer.new('{{3}} and {{5}}', false)
36
- ]
37
- )
38
- q2 = Question.new(
39
- prompt: 'What is the colour of a Banana?',
40
- answers: [
41
- Answer.new('Red', false, 'red'),
42
- Answer.new('Green', false),
43
- Answer.new('Yellow', false),
44
- Answer.new('Brown', false),
45
- Answer.new('Black', false),
46
- Answer.new('All of the above except {{red}}', true)
47
- ]
48
- )
49
-
50
- quiz = Quiz.new([q, q2], header: 'Header', footer: 'Footer')
51
-
52
- describe TextQuestionSheetFormatter do
53
- it 'formats a test OK' do
54
- TextQuestionSheetFormatter.new.format(quiz).must_equal expected_output
55
- end
56
- end