-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sets.py
84 lines (75 loc) · 3.52 KB
/
test_sets.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
import unittest
from itertools import chain
from game import Sets
def unique_sets_length(d):
seen = {} # dict (value, key)
result = set() # keys with unique values
for k,v in d.iteritems():
if v in seen:
result.discard(seen[v])
else:
seen[v] = k
result.add(k)
return len(list(result))
class TestGameofSet(unittest.TestCase):
# Test for maximum number of sets in the traditional three card Set game
# Dimensions = 4, Dimension size = 3
def test_maximum_getsets(self):
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = len(set_object.get_sets())
self.assertEqual(1080, result, msg="")
# Test for maximum number of sets in the traditional three card Set game
# Dimensions = 4, Dimension size = 3 for the alternate computationally
# slower function that is used for higher dimensions and dimension sizes
def test_maximum_getsets_brute(self):
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = len(set_object.getsets_brute())
self.assertEqual(1080, result, msg="")
# Test for uniqueness of sets in the traditional three card Set game
# Dimensions = 4, Dimension size = 3
def test_unique_getsets(self):
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = set_object.get_sets()
self.assertEqual(1080, unique_sets_length(result), msg="")
# Test for uniqueness of sets in the traditional three card Set game
# Dimensions = 4, Dimension size = 3 for the alternate computationally
# slower function that is used for higher dimensions and dimension sizes
def test_unique_getsets_brute(self):
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = set_object.getsets_brute()
self.assertEqual(1080, unique_sets_length(result), msg="")
# Test to see if "Set definition" is honored in the traditional three card Set game
# Dimensions = 4, Dimension size = 3
def test_setdef_getsets(self):
def same_cards(ca_1,ca_2,ca_3):
return ca_1==ca_2 and ca_2==ca_3
def different_cards(ca_1,ca_2,ca_3):
return len({ca_1,ca_2,ca_3})==3
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = set_object.get_sets().values()
setdef_flag = False
for set_tuple in result:
setdef_flag = all(same_cards(i, j ,k) or different_cards(i, j, k)
for i, j, k in zip(set_tuple[0],set_tuple[1],set_tuple[2]))
if setdef_flag == False:
break
self.assertTrue(setdef_flag, msg="")
# Test to see if "Set definition" is honored in the traditional three card Set game
# Dimensions = 4, Dimension size = 3 for the alternate computationally
# slower function that is used for higher dimensions and dimension sizes
def test_setdef_getsets_brute(self):
def same_cards(ca_1,ca_2,ca_3):
return ca_1==ca_2 and ca_2==ca_3
def different_cards(ca_1,ca_2,ca_3):
return len({ca_1,ca_2,ca_3})==3
set_object = Sets(dims=4, dim_size=3, n_cards=81)
result = set_object.getsets_brute().values()
setdef_flag = False
for set_tuple in result:
setdef_flag = all(same_cards(i, j ,k) or different_cards(i, j, k)
for i, j, k in zip(set_tuple[0],set_tuple[1],set_tuple[2]))
if setdef_flag == False:
break
self.assertTrue(setdef_flag, msg="")
if __name__ == '__main__':
unittest.main()