-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
93 lines (69 loc) · 2.85 KB
/
test.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
import sys
sys.path.append('./lib')
from functools import partial
from game import Game
from bot import Bot
from util import compose, dedupe
game = Game()
bot = Bot()
assert True == True, 'sanity check'
print("collapse_line")
assert [4, 0, 0, 0] == game.collapse_line([0, 2, 2, 0]), game.collapse_line([0, 2, 2, 0])
assert [4, 4, 0, 0] == game.collapse_line([2, 2, 2, 2]), game.collapse_line([2, 2, 2, 2])
assert [2, 0, 0, 0] == game.collapse_line([0, 0, 2, 0]), game.collapse_line([0, 0, 2, 0])
assert [4, 4, 0, 0] == game.collapse_line([4, 2, 2, 0]), game.collapse_line([4, 2, 2, 0])
assert [4, 4, 0, 0] == game.collapse_line([4, 0, 2, 2]), game.collapse_line([4, 0, 2, 2])
assert [4, 4, 0, 0] == game.collapse_line([4, 0, 2, 2]), game.collapse_line([4, 0, 2, 2])
assert [8, 0, 0, 0] == game.collapse_line([0, 0, 4, 4]), game.collapse_line([0, 0, 4, 4])
assert [8, 4, 0, 0] == game.collapse_line([0, 4, 4, 4]), game.collapse_line([0, 4, 4, 4])
print("group columns")
original = [
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
]
expected_columns = [
[1, 5, 9, 13],
[2, 6, 10, 14],
[3, 7, 11, 15],
[4, 8, 12, 16]
]
assert expected_columns == game.group('columns', original), game.group('columns', original)
print("group rows")
expected_rows = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
assert expected_rows == game.group('rows', original), game.group('rows', original)
print("compose")
f = lambda x: x * 2
g = lambda x, y, z: [x, y, z]
z = compose(f, g)
assert [1, 2, 3, 1, 2, 3] == z(1, 2, 3), z(1, 2, 3)
f1 = lambda x: x * 2
f2 = lambda l: list(map(lambda x: x * 2, l))
f3 = lambda x, y, z: [x, y, z]
z = compose(f1, f2, f3)
assert [2, 4, 6, 2, 4, 6] == z(1, 2, 3), z(1, 2, 3)
print("partial")
f = lambda x: x * 2
g = lambda x, y, z: [x, y, z]
z = compose(f, partial(g, 1, 2))
assert [1, 2, 3, 1, 2, 3] == z(3), z(3)
print("dedupe")
assert [(1, 2), (2, 3), (3, 4)] == list(dedupe([(1, 2), (2, 3), (3, 4), (1, 2), (2, 3), (3, 4)])), dedupe([(1, 2), (2, 3), (3, 4), (1, 2), (2, 3), (3, 4)])
print('is_complete')
board = [64, 2048, 256, 128, 32, 256, 32, 8, 8, 16, 4, 0, 4, 2, 0, 0]
game.board = board
assert game.is_complete(board) != True, game.board
assert game.move('up', fake = True) == game.board, "{}, {}".format(game.move('up', fake = True), game.board)
assert game.move('down', fake = True) != game.board, "{}, {}".format(game.move('down', fake = True), game.board)
assert game.move('left', fake = True) == game.board, "{}, {}".format(game.move('left', fake = True), game.board)
assert game.move('right', fake = True) != game.board, "{}, {}".format(game.move('right', fake = True), game.board)
print('put_board_in_priority_order')
board = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
bot.game.board = board
assert bot.prioritize_board() == [0, 1, 2, 3, 7, 6, 5, 4, 8, 9, 10, 11, 15, 14, 13, 12], bot.prioritize_board()