Guest User

Untitled

a guest
Jul 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. require File.dirname(__FILE__) + '/spades'
  2. require 'minitest/autorun'
  3.  
  4. describe Deal do
  5.  
  6. before do
  7. @deal = Deal.new
  8. end
  9.  
  10. it "should default to 13 clubs dealt to the first player" do
  11. @deal.clubs.must_equal Array.new(13, 1)
  12. end
  13.  
  14. describe "iterating over deals" do
  15.  
  16. it "should increment the player of the first club that doesn't belong to the last player" do
  17. @deal.succ!
  18. @deal.clubs.must_equal [2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  19.  
  20. @deal.succ!
  21. @deal.clubs.must_equal [3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  22. end
  23.  
  24. it "should reset and increment the next club not belonging to the last player" do
  25. @deal.clubs = [4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  26. @deal.succ!.clubs.must_equal [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  27.  
  28. @deal.clubs = [4, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  29. @deal.succ!.clubs.must_equal [1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  30. end
  31.  
  32. it "should return nil when all clubs belong to the last player" do
  33. @deal.clubs = [4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
  34. @deal.succ!.must_equal nil
  35. end
  36.  
  37. end
  38.  
  39. describe "winning" do
  40.  
  41. it "should know the highest of the players' lowest clubs wins" do
  42. @deal.winner.must_equal 1
  43.  
  44. @deal.clubs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2]
  45. @deal.winner.must_equal 13
  46.  
  47. @deal.clubs = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]
  48. @deal.winner.must_equal 12
  49.  
  50. @deal.clubs = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1]
  51. @deal.winner.must_equal 4
  52. end
  53.  
  54. end
  55.  
  56. describe "summary" do
  57.  
  58. it "should be able to generate and score all of the deals" do
  59. total = 0
  60. wins = Array.new(13, 0)
  61. begin
  62. wins[@deal.winner - 1] += 1
  63. total += 1
  64. end while @deal.succ!
  65. subtotal = 0
  66. wins.each_with_index do |number, i|
  67. puts "#{i + 1}\t#{number}\t#{number.to_f / total}"
  68. subtotal += number
  69. end
  70. total.must_equal 4 ** 13
  71. subtotal.must_equal total
  72. end
  73.  
  74. end
  75.  
  76. end
Add Comment
Please, Sign In to add comment