Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require File.dirname(__FILE__) + '/spades'
- require 'minitest/autorun'
- describe Deal do
- before do
- @deal = Deal.new
- end
- it "should default to 13 clubs dealt to the first player" do
- @deal.clubs.must_equal Array.new(13, 1)
- end
- describe "iterating over deals" do
- it "should increment the player of the first club that doesn't belong to the last player" do
- @deal.succ!
- @deal.clubs.must_equal [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- @deal.succ!
- @deal.clubs.must_equal [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- end
- it "should reset and increment the next club not belonging to the last player" do
- @deal.clubs = [4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- @deal.succ!.clubs.must_equal [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- @deal.clubs = [4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- @deal.succ!.clubs.must_equal [1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- end
- it "should return nil when all clubs belong to the last player" do
- @deal.clubs = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
- @deal.succ!.must_equal nil
- end
- end
- describe "winning" do
- it "should know the highest of the players' lowest clubs wins" do
- @deal.winner.must_equal 1
- @deal.clubs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
- @deal.winner.must_equal 13
- @deal.clubs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]
- @deal.winner.must_equal 12
- @deal.clubs = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1]
- @deal.winner.must_equal 4
- end
- end
- describe "summary" do
- it "should be able to generate and score all of the deals" do
- total = 0
- wins = Array.new(13, 0)
- begin
- wins[@deal.winner - 1] += 1
- total += 1
- end while @deal.succ!
- subtotal = 0
- wins.each_with_index do |number, i|
- puts "#{i + 1}\t#{number}\t#{number.to_f / total}"
- subtotal += number
- end
- total.must_equal 4 ** 13
- subtotal.must_equal total
- end
- end
- end
Add Comment
Please, Sign In to add comment