Skip to content
Snippets Groups Projects
Commit 92b7e8ad authored by François Sarradin's avatar François Sarradin
Browse files

add test on SHA-1

parent adb019bd
No related branches found
No related tags found
No related merge requests found
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
...@@ -6,7 +6,7 @@ module ExtremeStartup ...@@ -6,7 +6,7 @@ module ExtremeStartup
describe QuestionFactory do describe QuestionFactory do
let(:player) { Player.new("player one") } let(:player) { Player.new("player one") }
let(:factory) { QuestionFactory.new } let(:factory) { QuestionFactory.new }
context "in the first round" do context "in the first round" do
it "creates both AdditionQuestions and SquareCubeQuestion" do it "creates both AdditionQuestions and SquareCubeQuestion" do
questions = 10.times.map { factory.next_question(player) } questions = 10.times.map { factory.next_question(player) }
...@@ -15,12 +15,12 @@ module ExtremeStartup ...@@ -15,12 +15,12 @@ module ExtremeStartup
questions.all? { |q| [AdditionQuestion, MaximumQuestion].include? q.class } questions.all? { |q| [AdditionQuestion, MaximumQuestion].include? q.class }
end end
end end
context "in the second round" do context "in the second round" do
before(:each) do before(:each) do
factory.advance_round factory.advance_round
end end
it "creates four different types of question" do it "creates four different types of question" do
questions = 20.times.map { factory.next_question(player) } questions = 20.times.map { factory.next_question(player) }
questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_true questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_true
...@@ -29,15 +29,15 @@ module ExtremeStartup ...@@ -29,15 +29,15 @@ module ExtremeStartup
questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true
questions.all? { |q| [AdditionQuestion, MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, ].include? q.class } questions.all? { |q| [AdditionQuestion, MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, ].include? q.class }
end end
end end
context "in the third round" do context "in the third round" do
before(:each) do before(:each) do
factory.advance_round factory.advance_round
factory.advance_round factory.advance_round
end end
it "moves a sliding window forward, keeping 5 question types, so AdditionQuestions no longer appear" do 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 = 30.times.map { factory.next_question(player) }
questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_false questions.any? { |q| q.is_a?(AdditionQuestion) }.should be_false
...@@ -48,8 +48,8 @@ module ExtremeStartup ...@@ -48,8 +48,8 @@ module ExtremeStartup
questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true questions.any? { |q| q.is_a?(SquareCubeQuestion) }.should be_true
questions.all? { |q| [MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, GeneralKnowledgeQuestion, PrimesQuestion].include? q.class } questions.all? { |q| [MaximumQuestion, MultiplicationQuestion, SquareCubeQuestion, GeneralKnowledgeQuestion, PrimesQuestion].include? q.class }
end end
end end
end end
end end
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment