-
Notifications
You must be signed in to change notification settings - Fork 0
/
montecarlo_tests.py
145 lines (136 loc) · 4.05 KB
/
montecarlo_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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import unittest
import numpy as np
import pandas as pd
from pandas.testing import assert_frame_equal
from montecarlo import Die, Game, Analyzer
class MontecarloTestSuite(unittest.TestCase):
'''
Tests the classes containted in the module "montecarlo".
'''
def test_1_change_weight(self):
'''
Tests the Die.change_weight() function.
'''
# create die instance
die = Die([1,2,3,4,5,6])
# change weight
die.change_weight(1,3)
# check
actual = die.show()
expected = pd.DataFrame({'Weight': [3.0,1.0,1.0,1.0,1.0,1.0]}, \
index = [1,2,3,4,5,6])
pd.testing.assert_frame_equal(actual, expected)
def test_2_roll(self):
'''
Tests the Die.roll() function.
'''
# create die instance
die = Die([1,2,3,4,5,6])
# roll
roll = die.roll()
# check
actual = 1 <= roll[0] <= 6
message = "Test value is not True."
self.assertTrue(actual, message)
def test_3_show(self):
'''
Tests the Die.show() function.
'''
# create die instance
die = Die([1,2,3,4,5,6])
# check
actual = die.show()
expected = pd.DataFrame({'Weight': [1.0,1.0,1.0,1.0,1.0,1.0]}, index = [1,2,3,4,5,6])
pd.testing.assert_frame_equal(actual, expected)
# GAME TESTS
def test_4_play(self):
'''
Tests the Game.play() function.
'''
# create game instance
die1 = Die([1,2,3,4,5,6])
die2 = Die([1,2,3,4,5,6])
game = Game([die1, die2])
# play
game.play(3)
result = game.show()
# check
actual = np.shape(result.values)
expected = (3,2)
self.assertEqual(actual, expected)
def test_5_show(self):
'''
Tests the Game.show() function.
'''
# create game instance
die1 = Die([1,2,3,4,5,6])
die2 = Die([1,2,3,4,5,6])
game = Game([die1, die2])
game.play(5)
result = game.show()
# check
actual = np.shape(result.values)
expected = (5,2)
self.assertEqual(actual, expected)
# ANALYZER TESTS
def test_6_jackpot(self):
'''
Tests the Analyzer.jackpot() function.
'''
# create analyzer instance
die1 = Die([1,2,3,4,5,6])
die2 = Die([1,2,3,4,5,6])
game = Game([die1, die2])
game.play(50)
analyzer = Analyzer(game)
# find jackpots
analyzer.jackpot()
jackpots = analyzer.jackpots
list = jackpots.values.tolist()
# check
actual = 0
for i in range(0,len(list)):
if all(x == list[i][0] for x in list[i]) == True:
actual += 1
expected = len(list)
self.assertEqual(actual, expected)
def test_7_combo(self):
'''
Tests the Analyzer.combo() function.
'''
# create analyzer instance
die1 = Die([1,2,3,4,5,6])
die2 = Die([1,2,3,4,5,6])
game = Game([die1, die2])
game.play(50)
analyzer = Analyzer(game)
# find combos
analyzer.combo()
combos = analyzer.combos
list = combos.index.tolist()
# check
actual = sorted(set(item for item in list))
expected = sorted(list)
self.assertEqual(actual, expected)
def test_8_face_count(self):
'''
Tests the Analyzer.face_count() function.
'''
# create analyzer instance
die1 = Die([1,2,3])
die2 = Die([1,2,3])
game = Game([die1, die2])
game.play(10)
analyzer = Analyzer(game)
# find face_count
analyzer.face_count()
list = analyzer.face_counts.values
# check
actual = 0
for i in range(0,len(list)):
if sum(list[i]) == 2:
actual += 1
expected = len(list)
self.assertEqual(actual, expected)
if __name__ == '__main__':
unittest.main(verbosity=3)