Spaces:
Configuration error
Configuration error
File size: 4,596 Bytes
69373e6 c903325 | 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 | from pycatan.core.game import Game
from pycatan.core.default_board import DefaultBoard
class TestDefaultBoard:
def test_get_connected_tiles(self):
board = Game().board
test_cases = {
(0, 0): [[0, 0]],
(0, 1): [[0, 0]],
(0, 2): [[0, 0], [0, 1]],
(3, 4): [[2, 1], [2, 2], [3, 1]],
(5, 0): [[4, 0]],
(5, 1): [[4, 0]],
(5, 2): [[4, 0], [4, 1]]
}
# Test that it returns the points connected properly
for case, answers in test_cases.items():
points = DefaultBoard.get_tile_indexes_for_point(case[0], case[1])
for ans in answers:
# Check it returned the correct point
assert ans in points
def test_points_have_reference_to_tiles(self):
# Get board
b = Game().board
# Test cases
# Keys are the coordinates of the points, whereas values
# are the coordinates of the tiles surronding that point
#
cases = {
(0, 0): [(0, 0)],
(1, 2): [(0, 0), (1, 0), (1, 1)],
(2, 0): [(2, 0)],
(5, 2): [(4, 0), (4, 1)]
}
# Check each point has references to the tiles around it
for key in cases:
point = b.points[key[0]][key[1]]
answers = cases[key]
for ans in answers:
tile = b.tiles[ans[0]][ans[1]]
assert tile in point.tiles
def test_tiles_have_references_to_points(self):
# Get board
b = Game().board
# Test cases
cases = {
(0, 0): [
(0, 0),
(0, 1),
(0, 2),
(1, 1),
(1, 2),
(1, 3)
],
(2, 3): [
(2, 6),
(2, 7),
(2, 8),
(3, 6),
(3, 7),
(3, 8)
],
(4, 2): [
(4, 5),
(4, 6),
(4, 7),
(5, 4),
(5, 5),
(5, 6)
]
}
for key in cases:
tile = b.tiles[key[0]][key[1]]
answers = cases[key]
for ans in answers:
point = b.points[ans[0]][ans[1]]
assert point in tile.points
def test_points_have_references_to_connected_points(self):
board = Game().board
cases = {
(0, 0): (0, 1),
(0, 0): (1, 1),
(1, 8): (2, 9),
(2, 3): (2, 2),
(4, 1): (5, 0),
(4, 2): (3, 3)
}
for case in cases:
ans = cases[case]
assert board.points[ans[0]][ans[1]] in board.points[case[0]][case[1]].connected_points
def test_get_outside_points(self):
# Get outside points
outside_points = DefaultBoard.get_outside_points()
# Check the points exist
cases = {
(0, 0): True,
(1, 2): False,
(4, 0): True,
(5, 3): True,
(3, 2): False
}
for case in cases:
ans = cases[case]
assert (list(case) in outside_points) == ans
# Check the points are in the right order
# Each value in this dict is the point that should be directly after the key
order_cases = {
(0, 0): (0, 1),
(0, 6): (1, 7),
(2, 10): (3, 10),
(5, 3): (5, 2),
(2, 1): (1, 0),
(1, 0): (1, 1)
}
for case in order_cases:
ans = order_cases[case]
assert outside_points.index(list(case)) + 1 == outside_points.index(list(ans))
def test_harbors_are_placed_correctly(self):
# Create board
board = Game().board
# Test that the harbors are on these spots
cases = [
(0, 2),
(2, 9),
(3, 0),
(5, 2)
]
# Flatten all harbor positions
harbor_positions = list(sum(map(lambda x: [x.point_one, x.point_two], board.harbors), []))
for case in cases:
assert board.points[case[0]][case[1]] in harbor_positions
def test_harbors_always_have_connected_points(self):
# Create board
board = Game().board
# For every harbor, check that the two points are connected
for harbor in board.harbors:
print(harbor.point_one)
assert harbor.point_two in harbor.point_one.connected_points
|