diff --git a/spec/extreme_startup/intersection_rect_question_spec.rb b/spec/extreme_startup/intersection_rect_question_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..126385ef3c4216406c2cb3078a4759e781676bd2 --- /dev/null +++ b/spec/extreme_startup/intersection_rect_question_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' +require 'extreme_startup/question_factory' +require 'extreme_startup/player' + +module ExtremeStartup + describe RectangleIntersectionQuestion do + let(:question) { RectangleIntersectionQuestion.new(Player.new) } + + it "converts to a string" do + question.as_text.should =~ /give the intersection of those rectangles \(x0,y0,width,height\): \(\d+,\d+,\d+,\d+\) x \(\d+,\d+,\d+,\d+\)/i + end + + context "when the numbers and known" do + let(:question) { RectangleIntersectionQuestion.new(Player.new, 1,1,10,10, 5,5,20,20) } + + it "converts to the right string" do + question.as_text.should =~ /give the intersection of those rectangles \(x0,y0,width,height\): \(1,1,10,10\) x \(5,5,20,20\)/i + end + + it "identifies a correct answer" do + question.answered_correctly?("( 5, 5, 6, 6 )").should be_true + end + + it "identifies an incorrect answer" do + question.answered_correctly?("(5,5,6,20)").should be_false + end + end + context "when the rectangles does not intersect" do + let(:question) { RectangleIntersectionQuestion.new(Player.new, 1,1,2,2, 5,5,2,2) } + + it "identifies empty answer as correct" do + question.answered_correctly?("").should be_true + end + end + end +end diff --git a/spec/extreme_startup/question_factory_spec.rb b/spec/extreme_startup/question_factory_spec.rb index 5512ff2ab1dcfdf9f2a52947e86c9c4058f558fa..2b8d8040b2fd3ed3a73c4b6f2d712b7483548821 100644 --- a/spec/extreme_startup/question_factory_spec.rb +++ b/spec/extreme_startup/question_factory_spec.rb @@ -6,7 +6,7 @@ module ExtremeStartup describe QuestionFactory do let(:player) { Player.new("player one") } let(:factory) { QuestionFactory.new } - + context "in the first round" do it "creates both AdditionQuestions and SquareCubeQuestion" do questions = 10.times.map { factory.next_question(player) } @@ -15,12 +15,12 @@ module ExtremeStartup questions.all? { |q| [AdditionQuestion, MaximumQuestion].include? q.class } end end - + context "in the second round" do before(:each) do factory.advance_round end - + it "creates four different types of question" do questions = 20.times.map { factory.next_question(player) } questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_true @@ -29,15 +29,15 @@ module ExtremeStartup questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true questions.all? { |q| [AdditionQuestion, MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, ].include? q.class } end - + end - + context "in the third round" do before(:each) do factory.advance_round factory.advance_round end - + it "moves a sliding window forward, keeping 5 question types, so AdditionQuestions no longer appear" do questions = 30.times.map { factory.next_question(player) } questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_false @@ -48,8 +48,8 @@ module ExtremeStartup questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true questions.all? { |q| [MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, GeneralKnowledgeQuestion, PrimesQuestion].include? q.class } end - + end - + end end diff --git a/spec/extreme_startup/sha1_spec.rb b/spec/extreme_startup/sha1_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..4a9d9361c7ac7d2d6c73ef96de8a2a9940c8c3f3 --- /dev/null +++ b/spec/extreme_startup/sha1_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' +require 'extreme_startup/question_factory' +require 'extreme_startup/player' + +module ExtremeStartup + describe Sha1Question do + let(:question) { Sha1Question.new(Player.new) } + + it "converts to a string" do + question.as_text.should =~ /what is the SHA-1 hash of \w+/i + end + + context "when the word is known" do + let(:question) { Sha1Question.new(Player.new, "hello") } + + it "converts to the right string" do + question.as_text.should =~ /what is the SHA-1 hash of hello/i + end + + it "identifies a correct answer" do + question.answered_correctly?("aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d").should be_true + end + + it "identifies an incorrect answer" do + question.answered_correctly?("12345").should be_false + end + end + + end +end