-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
119 lines (113 loc) · 3.62 KB
/
tests.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
from blackjack import calculate_score, compare
from termcolor import colored
def test_calculate_score():
tests = []
#Loop
for element in tests:
calculate_score(hand)
hands = []
expected_values = []
test_names = []
test_names.append("Blackjack 1")
hands.append([11, 10])
expected_values.append(0)
test_names.append("Blackjack 2")
hands.append([10, 11])
expected_values.append(0)
test_names.append("1 Ace with value of 11")
hands.append([11, 9])
expected_values.append(20)
test_names.append("1 Ace with value of 1")
hands.append([1, 9, 10])
expected_values.append(20)
test_names.append("Busted version")
hands.append([1, 9, 10, 5])
expected_values.append(25)
test_names.append("2 Aces with value 11 & 1")
hands.append([1, 9, 11])
expected_values.append(21)
test_names.append("2 Aces with values 1")
hands.append([10, 5, 1, 11])
expected_values.append(17)
test_names.append("Busted version")
hands.append([10, 5, 1, 1, 8])
expected_values.append(25)
test_names.append("3 Aces with values 11, 1 & 1")
hands.append([11, 5, 1, 11])
expected_values.append(18)
test_names.append("3 Aces with values 1")
hands.append([10, 5, 1, 1, 11])
expected_values.append(18)
test_names.append("Busted version")
hands.append([10, 5, 1, 1, 1, 7])
expected_values.append(25)
test_names.append("No aces")
hands.append([10, 5])
expected_values.append(15)
test_names.append("Busted version")
hands.append([10, 5, 10])
expected_values.append(25)
for i in range(len(test_names)):
tests.append([test_names[i], hands[i], expected_values[i], calculate_score(hands[i])])
for test in tests:
if test[2] == test[3]:
result = "PASS"
color = "green"
else:
result = "FAIL"
color = "red"
print(colored(f"{test}: {result}", color))
def test_compare():
tests = []
test_names = []
user_scores = []
computer_scores = []
expected_values = []
test_names.append("Same score")
user_scores.append(10)
computer_scores.append(10)
expected_values.append(0)
test_names.append("Computer blackjack")
user_scores.append(12)
computer_scores.append(0)
expected_values.append(-1)
test_names.append("User blackjack")
user_scores.append(0)
computer_scores.append(20)
expected_values.append(1)
test_names.append("Both blackjack")
user_scores.append(0)
computer_scores.append(0)
expected_values.append(-1)
test_names.append("User busted")
user_scores.append(24)
computer_scores.append(20)
expected_values.append(-1)
test_names.append("Computer busted")
user_scores.append(20)
computer_scores.append(25)
expected_values.append(1)
test_names.append("Nobody busted, player wins")
user_scores.append(19)
computer_scores.append(17)
expected_values.append(1)
test_names.append("Nobody busted, computer wins")
user_scores.append(19)
computer_scores.append(20)
expected_values.append(-1)
for i in range(len(test_names)):
tests.append([test_names[i], user_scores[i], computer_scores[i],
expected_values[i],
compare(user_scores[i], computer_scores[i])])
for test in tests:
if test[3] == test[4]:
result = "PASS"
color = "green"
else:
result = "FAIL"
color = "red"
print(colored(f"{test}: {result}", color))
print("Test 1, test_calculate_score")
test_calculate_score()
print("\nTest 2, test_compare")
test_compare()