-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtc_deck.rb
executable file
·58 lines (50 loc) · 1.39 KB
/
tc_deck.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/ruby -w
require 'Deck'
require 'test/unit'
# = Description
#
# This class is used to test the Deck class.
#
# = Author
#
# Author:: Christopher Kline (mailto:[email protected])
# Copyleft:: Copyleft 2007 Christopher Kline
# License:: Distributes under the same terms as Ruby
class TestDeck < Test::Unit::TestCase
# Create a deck for all of the tests.
def setup
@deck = Deck.new
@cards = @deck.cards
end
# Check the original deck.
def test_deck_card_counts
print "\nOriginal Deck:\n#{@deck.to_s}\n"
assert_equal(52, @cards.length, "Num Cards")
end
# Check for all unique cards.
def test_deck_cards_uniq
arr = @deck.cards.uniq
assert_equal(52, arr.length, "Num unique cards")
end
# Check the shuffled deck 3 times.
def test_deck_shuffle
1.upto(3) do |x|
@deck.shuffle
print "\nShuffled Deck [#{x}]:\n#{@deck.to_s}\n"
assert_equal(52, @cards.length, "Num Cards")
end
end
# Check the cut deck 3 times with random cut points.
def test_deck_cut
1.upto(3) do |x|
cut_at = rand(51) + 1
x = @cards[cut_at - 1]
y = @cards[cut_at]
@deck.cut(cut_at)
print "\nCut Deck at #{cut_at} [#{x}|#{y}]:\n#{@deck.to_s}\n\n"
assert_equal(52, @cards.length, "Num Cards")
assert_equal(@cards[(@cards.length - 1)], x, "Card Before")
assert_equal(@cards[0], y, "Card After")
end
end
end