def test_neighbors(): grid = make_grid('test2', size=(5, 5), live_cells=[0, 3, 12, 18, 21]) get_neighbours = neighbours(grid) p1 = id_to_pos(0, grid) assert get_neighbours(p1) == [(0, 1), (1, 0), (1, 1)] p2 = id_to_pos(18, grid) assert get_neighbours(p2) == [(2, 2), (2, 3), (2, 4), (3, 2), (3, 4), (4, 2), (4, 3), (4, 4)] p3 = id_to_pos(24, grid) assert get_neighbours(p3) == [(3, 3), (3, 4), (4, 3)]
def test_neighbours_at_origin(self): cells_expected = set([(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]) result = neighbours((0, 0)) self.assertEqual(cells_expected, result)
def test_neighbours(self): cells_expected = set([(0, 0), (1, 0), (2, 0), (0, 1), (2, 1), (0, 2), (1, 2), (2, 2)]) result = neighbours((1, 1)) self.assertEqual(cells_expected, result)