Created
September 29, 2010 00:24
-
-
Save noelrappin/602077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'rspec' | |
require 'sequence' | |
describe Sequence do | |
describe "validation" do | |
it "should be able to sum its items" do | |
sequence = Sequence.new(1, 2, 3, 4) | |
sequence.sum.should == 10 | |
end | |
it "is valid if the sum is 15" do | |
sequence = Sequence.new(1, 1, 7, 6) | |
sequence.should be_valid | |
sequence = Sequence.new(1, 1, 7, 7) | |
sequence.should_not be_valid | |
end | |
it "is invalid if there is no pair" do | |
sequence = Sequence.new(8, 7) | |
sequence.should_not have_digit_pair | |
sequence.should_not be_valid | |
end | |
it "is invalid if there is a digit trio" do | |
sequence = Sequence.new(1, 1, 1, 5, 7) | |
sequence.should have_digit_trio | |
sequence.should_not be_valid | |
end | |
end | |
describe "sequencing" do | |
it "should start with 1" do | |
sequence = Sequence.new | |
sequence.next.elements.should == [1] | |
end | |
it "a sequence with a low sum should spawn a new element" do | |
sequence = Sequence.new(1) | |
sequence.next.elements.should == [1, 1] | |
end | |
it "a sequence with a low sum should spawn a new element in numerical order" do | |
sequence = Sequence.new(1, 1, 2) | |
sequence.next.elements.should == [1, 1, 2, 2] | |
end | |
it "a sequence with a trio should increase its last element" do | |
sequence = Sequence.new(1, 1, 1) | |
sequence.next.elements.should == [1, 1, 2] | |
end | |
it "a sequence whose sum is too high should back up an element" do | |
sequence = Sequence.new(1, 1, 2, 2, 3, 3, 4) | |
sequence.next.elements.should == [1, 1, 2, 2, 3, 4] | |
end | |
it "a sequence should not let a digit get over 9" do | |
sequence = Sequence.new(1, 9, 5) | |
sequence.next.elements.should == [2] | |
end | |
it "the last sequence should end" do | |
sequence = Sequence.new(9, 6) | |
sequence.next.should be_nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment