Skip to content
Browse files

AV hole

  • Loading branch information...
1 parent 4054926 commit e78d2d39acb6f1393c1d599b734f8ffb34802df8 @andrewmcdonough andrewmcdonough committed May 9, 2011
Showing with 100 additions and 14 deletions.
  1. +22 −3 .gitignore
  2. +6 −0 Gemfile
  3. +13 −0 fixtures/av-example1.txt
  4. +9 −0 fixtures/av-example2.txt
  5. +12 −0 fixtures/av-example3.txt
  6. +9 −0 fixtures/av-example4.txt
  7. +29 −11 spec/golf_spec.rb
View
25 .gitignore
@@ -1,4 +1,23 @@
-**/*.sw*
-*.sw*
-lib/golf.rb
+.## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+
+.bundle
spec/*.report
+Gemfile.lock
View
6 Gemfile
@@ -0,0 +1,6 @@
+source "http://rubygems.org"
+
+group :development do
+ gem "rspec", "~> 1.3"
+ gem "rake"
+end
View
13 fixtures/av-example1.txt
@@ -0,0 +1,13 @@
+blue, yellow, red
+blue, yellow, green, red
+blue
+blue, green, yellow, red
+blue, red
+blue, green, yellow, red
+blue, yellow
+yellow, blue, green, red
+red, green, yellow, blue
+red, green
+red, blue, yellow, green
+red
+red, green
View
9 fixtures/av-example2.txt
@@ -0,0 +1,9 @@
+red, blue
+red, blue
+red, blue
+red, blue
+blue
+blue
+blue
+blue
+green, red
View
12 fixtures/av-example3.txt
@@ -0,0 +1,12 @@
+blue, yellow, red
+blue, yellow, green, red
+blue
+blue, green, yellow, red
+yellow, blue, red
+green, yellow, blue, red
+yellow, blue, green, red
+red, green, yellow, blue
+red, green
+red, blue, yellow, green
+red
+red, green
View
9 fixtures/av-example4.txt
@@ -0,0 +1,9 @@
+red
+red
+red
+red
+blue
+blue
+blue
+blue
+green, yellow
View
40 spec/golf_spec.rb
@@ -4,50 +4,68 @@
describe ".hole1" do
it "should multiply the numbers in an array" do
- Golf.hole1([1,2,3,4]).should == 24
+ Golf.hole1([1,2,3,4]).should eql 24
end
it "should be 600 for [5,2,10,6]" do
- Golf.hole1([5,2,10,6]).should == 600
+ Golf.hole1([5,2,10,6]).should eql 600
end
end
+ describe ".hole2" do
+ it "should sort a sentence by the second letter of each word" do
+ Golf.hole2("the quick brown fox").should eql "the fox brown quick"
+ end
+
+ end
+
describe ".hole3" do
it "should calculate the factorial of 4, i.e. 4*3*2*1" do
- Golf.hole3(4).should == 24
+ Golf.hole3(4).should eql 24
end
end
describe ".hole6" do
it "should play fizzbuzz to 3, where multiples of 3 are 'fizz'" do
- Golf.hole6(3).should == [1,2,"fizz"]
+ Golf.hole6(3).should eql [1,2,"fizz"]
end
it "should play fizzbuzz to 5, with rules above and multiples of 5 are 'buzz'" do
- Golf.hole6(5).should == [1,2,"fizz",4,"buzz"]
+ Golf.hole6(5).should eql [1,2,"fizz",4,"buzz"]
end
it "should play fizzbuzz to 10 with rules above and muliples of 3 and 5 are 'fizzbuzz'" do
- Golf.hole6(15).should == [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz"]
+ Golf.hole6(15).should eql [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz"]
end
it "should play fizzbuzz to 30" do
- Golf.hole6(30).should == [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz",16,17,"fizz",19,"buzz","fizz",22,23,"fizz","buzz",26,"fizz",28,29,"fizzbuzz"]
+ Golf.hole6(30).should eql [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz",16,17,"fizz",19,"buzz","fizz",22,23,"fizz","buzz",26,"fizz",28,29,"fizzbuzz"]
end
end
describe ".hole8" do
it "should give the first N numbers of the fibonacci sequence" do
- Golf.hole8(5).should == [1,1,2,3,5]
+ Golf.hole8(5).should eql [1,1,2,3,5]
end
it "should give the first 9 numbers" do
- Golf.hole8(9).should == [1,1,2,3,5,8,13,21,34]
+ Golf.hole8(9).should eql [1,1,2,3,5,8,13,21,34]
end
it "should give the first 15 numbers" do
- Golf.hole8(15).should == [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]
+ Golf.hole8(15).should eql [1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]
end
end
describe ".hole9" do
-
+ it "should return the winner of an AV election where winner has a first round majority" do
+ Golf.hole9('fixtures/av-example1.txt').should eql "blue"
+ end
+ it "should eliminate the last candidate if there is no first round majority and allocate their second choices" do
+ Golf.hole9('fixtures/av-example2.txt').should eql "red"
+ end
+ it "should continue to eliminate the losing candidate until a majority is reached" do
+ Golf.hole9('fixtures/av-example3.txt').should eql "blue"
+ end
+ it "should be the candidate with most votes if there are only two left, even witout a majority" do
+ Golf.hole9('fixtures/av-example4.txt').should eql "blue"
+ end
end

0 comments on commit e78d2d3

Please sign in to comment.
Something went wrong with that request. Please try again.