-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.rb
106 lines (76 loc) · 2.51 KB
/
test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require "./farkle.rb"
def good
puts "Pass!"
end
def bad
puts "Fail!"
end
game = System.new
begin # Test `system`'s basic rolling and scoring
six_dice = System.roll
six_dice.length == 6 ? good : bad
dice_count = 4
less_dice = System.roll dice_count
less_dice.length == dice_count ? good : bad
ace = [1,1,1,1,1,1] # Perfect roll
# Because I can't seem to remember we're zero-indexed...
begin
System.score(ace, [6]) # Draft an out-of-bounds die
bad
rescue
good # Raised an exception
end
score = System.score(ace, [0, 1, 2, 3, 4, 5])
score == 2000 ? good : bad
# If I were unsmart and only drafted a few of the perfect-roll 1s
score = System.score(ace, [0])
score == 100 ? good : bad
score = System.score(ace, [1, 3, 5])
score == 1000 ? good : bad
score = System.score(ace, [0, 3])
score == 200 ? good : bad
score = System.score(ace, [2, 3, 4, 5])
score == 1100 ? good : bad
# Some other arbitrary rolls
score = System.score([1, 2, 2, 2, 4, 6], [0, 1, 2, 3])
score == 300 ? good : bad
score = System.score([5, 5, 1, 4, 4, 3], [0, 1, 2])
score == 200 ? good : bad
score = System.score([1, 2], [0])
score == 100 ? good : bad
score = System.score([5, 5, 5], [0, 1, 2])
score == 500 ? good : bad
# Attempting to double-keep should not double score
score = System.score([1, 2, 3], [0, 0])
score == 100 ? good : bad
System.farkle?( [2] ) == true ? good : bad
System.farkle?( [2, 2] ) == true ? good : bad
System.farkle?( [2, 2, 2] ) == false ? good : bad
System.farkle?( [1, 2] ) == false ? good : bad
System.farkle?( [1, 2, 3] ) == false ? good : bad
System.farkle?( [2, 3, 4, 5, 6]) == false ? good : bad
System.farkle?( [1, 2, 2, 3, 3, 4]) == false ? good : bad
System.farkle?( [2, 2, 3, 3, 4, 4]) == true ? good : bad
end
srand 1
turn = Turn.new
turn.puts_last_roll
turn.play(:keep => [3], :puts => true)
# Should have 100 points after first `srand 1` keep
# turn.score == 100 ? good : bad
turn.play(:keep => [1, 2], :puts => true)
# Should have 300 points after second `srand 1` keep
# turn.score == 300 ? good : bad
turn.play(:keep => [1], :puts => true)
# Should have 350 points after third `srand 1` keep
# turn.score == 350 ? good : bad
turn.play(:keep => [1], :puts => true)
# Fourth `srand 1` keep results in a farkle.
# turn.score == 0 ? good : bad
puts; puts;
srand 2
turn = Turn.new
turn.puts_last_roll
turn.play(:keep => [0], :puts => true)
turn.play(:keep => [0], :puts => true)
turn.play(:keep => [1, 2, 3], :pass => true, :puts => true)