-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
68 lines (55 loc) · 1.96 KB
/
test.py
File metadata and controls
68 lines (55 loc) · 1.96 KB
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
#!/usr/bin/python
import setsolve
CARDS = [("3rfs", "2021"),
("1gbd", "0100"),
("2pfo", "1222")]
CARD_VECTORS = [("2012", [[2,],[0,],[1,],[2,]]),
("1001", [[1,],[0,],[0,],[1,]])]
TEST_DECK = "fixtures/good_deck_sets.txt"
TEST_DECK_SETS = "fixtures/good_deck_sets_answers.txt"
def test_readCard():
for card_in,card_out in CARDS:
assert setsolve.readCard(card_in) == card_out
def test_readDeck():
deck_len = len(open(TEST_DECK, "r").readlines())
out_deck = setsolve.readDeck(TEST_DECK)
assert len(out_deck) == deck_len
for card in out_deck:
for c in card:
assert c in ["0","1","2"]
def test_reprVectorConversions():
for rep,vec in CARD_VECTORS:
assert setsolve.reprFromVector(vec) == rep
assert setsolve.vectorFromRepr(rep) == vec
def test_checkExists():
VECTOR = [[1,],[2,],[4,]]
DECK_YES = ["425", "264", "124"]
DECK_NO = ["542", "274", "241"]
assert setsolve.cardExists(VECTOR, DECK_YES) == True
assert setsolve.cardExists(VECTOR, DECK_NO) == False
def test_findCardPermutations():
VECTOR = [[1,2],[3,],[4,]]
PERMS = [[[1,],[3,],[4,]],
[[2,],[3,],[4,]]]
for p in setsolve.findPermutations(VECTOR):
assert p in PERMS
def test_findCardVectorComplement():
VECTOR = [[1,2,5],[3,],[4,]]
CARD = [[2,],[3,],[4,]]
assert setsolve.cardVectorComplement(VECTOR, CARD) == [[1,5],[3,],[4,]]
def test_cardVariantDims():
VECTORS = [
([[1,2,3],[3,],[4,]], [0,]),
([[2,3], [4,5], [6,]], [0,1]),
([[2,],[3,],[4,]], [])]
for v_in, dims in VECTORS:
assert setsolve.cardVectorVariantDims(v_in) == dims
def test_findSets():
res = setsolve.findSets(TEST_DECK)
sets = [["1gbo","2gbo","3gbo"], ["2gcs","2pcs","2rcs"]]
print "SETS:%s" % (res,)
assert len(res) == len(sets)
for res_set in res:
assert res_set in sets
for ans_set in sets:
assert ans_set in res