def test_some_chains(self): """ should return all the chains in a list ignoring squares which arent in a chain or that have been taken """ unplay_all(board) # Chains 0, 1 10 19 20, 23 30 edges = (0,17,9,10,26,27,42,48,36,49,45,46,55,56,66,7,15,16,24) edge_setter(edges, const.PLAYED, board) result = finder.find_all(board) print(result) self.assertEqual(len(result), 5) one_chains = [] for chain in result: if len(chain) == 1: one_chains.append(chain) elif len(chain) == 4: self.assertIn(1, chain) self.assertIn(10, chain) self.assertIn(19, chain) self.assertIn(20, chain) elif len(chain) == 2: self.assertIn(23, chain) self.assertIn(30, chain) else: self.assertFail("Chains were not the right length") self.assertEqual(len(one_chains), 3) self.assertIn([0], one_chains) self.assertIn([9], one_chains) self.assertIn([11], one_chains)
def test_none(self): """ should return [] when there are no free sqaures """ unplay_all(board) edges = (0, 1, 19, 12, 31, 40, 71, 66, 61, 67) edge_setter(edges, const.PLAYED, board) self.assertEqual(placer.get_free_squares(board), [])
def test_none(self): """ should return [] when there are no free sqaures """ unplay_all(board) edges = (0,1,19,12,31,40,71,66,61,67) edge_setter(edges, const.PLAYED, board) self.assertEqual(placer.get_free_squares(board), [])
def test_no_chains(self): """ should return empty list if there are no chains """ unplay_all(board) edges = (0,3,4,7,33,45,49,58,62,63,68) edge_setter(edges, const.PLAYED, board) self.assertEqual(finder.find_all(board), [])
def test_no_chains(self): """ should return empty list if there are no chains """ unplay_all(board) edges = (0, 3, 4, 7, 33, 45, 49, 58, 62, 63, 68) edge_setter(edges, const.PLAYED, board) self.assertEqual(finder.find_all(board), [])
def test_one_edge_of_board(self): """ should return the traversable square in a list """ unplay_all(board) edges = (0, 17, 1, 10) edge_setter(edges, const.PLAYED, board) result = finder._get_traversable_squares(0, board) self.assertEqual([1], result)
def test_one_edge_count(self): """ should return the traversable square in a list """ unplay_all(board) edges = (27, 28, 43, 44) edge_setter(edges, const.PLAYED, board) result = finder._get_traversable_squares(11, board) self.assertEqual([20], result)
def test_one(self): """ should return the free square in an array (for consistancey) """ unplay_all(board) edges = (0,1,19,12,31,40,71,66,61,67,56,57) edge_setter(edges, const.PLAYED, board) self.assertEqual(placer.get_free_squares(board), [31])
def test_one_edge_count(self): """ should return the traversable square in a list """ unplay_all(board) edges = (27,28,43,44) edge_setter(edges, const.PLAYED, board) result = finder._get_traversable_squares(11, board) self.assertEqual([20], result)
def test_one_edge_of_board(self): """ should return the traversable square in a list """ unplay_all(board) edges = (0,17,1,10) edge_setter(edges, const.PLAYED, board) result = finder._get_traversable_squares(0, board) self.assertEqual([1], result)
def test_none(self): """ should return the reachable squares of a square """ unplay_all(board) # Square zero, edge 8 unplayed edges = (0,9,17) edge_setter(edges, const.PLAYED, board) self.assertEqual(finder._get_traversable_squares(0, board), [])
def test_none(self): """ should return the reachable squares of a square """ unplay_all(board) # Square zero, edge 8 unplayed edges = (0, 9, 17) edge_setter(edges, const.PLAYED, board) self.assertEqual(finder._get_traversable_squares(0, board), [])
def test_one(self): """ should return the free square in an array (for consistancey) """ unplay_all(board) edges = (0, 1, 19, 12, 31, 40, 71, 66, 61, 67, 56, 57) edge_setter(edges, const.PLAYED, board) self.assertEqual(placer.get_free_squares(board), [31])
def test_complex_chain_end(self): """ should return all the squares in the chain, including the one given """ unplay_all(board) # Set some random edges to played random_edges = (14, 33, 59, 60, 70, 71) edge_setter(random_edges, const.PLAYED, board) # Test a very complex chain, traversing squares 19, 20, 11, 12, 13, 14, 23, 24, 15 square_ids = (19, 20, 11, 12, 13, 14, 23, 24, 15) chain_edges = (35, 48, 49, 44, 27, 19, 37, 20, 21, 38, 22, 31, 45, 50, 51, 47, 31, 23) edge_setter(chain_edges, const.PLAYED, board) traversal = finder.traverse(15, board) self.assertEqual(len(traversal), len(square_ids)) for square in square_ids: self.assertIn(square, traversal) edge_setter(chain_edges, const.UNPLAYED, board) # Unset the random edges edge_setter(random_edges, const.UNPLAYED, board)
def test_X_junction(self): """ should stop at a X junction """ unplay_all(board) edges = (21, 38, 22, 39, 14, 15, 24, 41, 46, 47) squares = (13, 14) edge_setter(edges, const.PLAYED, board) traversal = finder.traverse(13, board) self.assertEqual(len(traversal), len(squares)) for square in squares: self.assertIn(square, traversal) edge_setter(edges, const.UNPLAYED, board)
def test_loop_chain_square(self): """ should be able to return squares from a loop of a square chain """ unplay_all(board) edges = (3, 4, 13, 30, 38, 37, 28, 11) squares = (3, 4, 12, 13) edge_setter(edges, const.PLAYED, board) traversal = finder.traverse(3, board) self.assertEqual(len(traversal), len(squares)) for square in squares: self.assertIn(square, traversal) edge_setter(edges, const.UNPLAYED, board)
def test_needs_better_name(self): """ should return only squares which have 2 or more edges played """ unplay_all(board) edges = (0, 1, 10, 2, 11) edge_setter(edges, const.PLAYED, board) squares = (0,1,2,3) filtered = finder._filter_edge_count(squares, board) self.assertNotIn(0, filtered) self.assertIn(1, filtered) self.assertIn(2, filtered) self.assertNotIn(3, filtered)
def test_many(self): """ should return all the free squares """ unplay_all(board) edges = (0,1,19,12,31,40,71,66,61,67,56,57,62,58,63,52,53) edge_setter(edges, const.PLAYED, board) free_squares = placer.get_free_squares(board) self.assertIn(27, free_squares) self.assertIn(33, free_squares) self.assertIn(31, free_squares) self.assertNotIn(37, free_squares)
def test_X_junction(self): """ should stop at a X junction """ unplay_all(board) edges = (21,38,22,39,14,15,24,41,46,47) squares = (13,14) edge_setter(edges, const.PLAYED, board) traversal = finder.traverse(13, board) self.assertEqual(len(traversal), len(squares)) for square in squares: self.assertIn(square, traversal) edge_setter(edges, const.UNPLAYED, board)
def test_needs_better_name(self): """ should return only squares which have 2 or more edges played """ unplay_all(board) edges = (0, 1, 10, 2, 11) edge_setter(edges, const.PLAYED, board) squares = (0, 1, 2, 3) filtered = finder._filter_edge_count(squares, board) self.assertNotIn(0, filtered) self.assertIn(1, filtered) self.assertIn(2, filtered) self.assertNotIn(3, filtered)
def test_loop_chain_rect(self): """ should be able to return squares from a loop of a rectangular chain """ unplay_all(board) # 3 x 2 rectangle, make sure edge count is always satisfied edges = (3, 4, 5, 14, 31, 39, 38, 37, 28, 11, 21) squares = (3, 4, 5, 14, 13, 12) edge_setter(edges, const.PLAYED, board) traversal = finder.traverse(3, board) self.assertEqual(len(traversal), len(squares)) for square in squares: self.assertIn(square, traversal) edge_setter(edges, const.UNPLAYED, board)
def test_many(self): """ should return all the free squares """ unplay_all(board) edges = (0, 1, 19, 12, 31, 40, 71, 66, 61, 67, 56, 57, 62, 58, 63, 52, 53) edge_setter(edges, const.PLAYED, board) free_squares = placer.get_free_squares(board) self.assertIn(27, free_squares) self.assertIn(33, free_squares) self.assertIn(31, free_squares) self.assertNotIn(37, free_squares)
def test_some_chains(self): """ should return all the chains in a list ignoring squares which arent in a chain or that have been taken """ unplay_all(board) # Chains 0, 1 10 19 20, 23 30 edges = (0, 17, 9, 10, 26, 27, 42, 48, 36, 49, 45, 46, 55, 56, 66, 7, 15, 16, 24) edge_setter(edges, const.PLAYED, board) result = finder.find_all(board) print(result) self.assertEqual(len(result), 5) one_chains = [] for chain in result: if len(chain) == 1: one_chains.append(chain) elif len(chain) == 4: self.assertIn(1, chain) self.assertIn(10, chain) self.assertIn(19, chain) self.assertIn(20, chain) elif len(chain) == 2: self.assertIn(23, chain) self.assertIn(30, chain) else: self.assertFail("Chains were not the right length") self.assertEqual(len(one_chains), 3) self.assertIn([0], one_chains) self.assertIn([9], one_chains) self.assertIn([11], one_chains)