def test_can_make_moves(self): b = Board(seed=False) # Make sure it's fully empty first self.assertEqual(len(b.empty_tiles()), 16) # Put a square in the top left corner val = 1 pos = 0 b._tiles.put(pos, val) # Move in the negative direction along the rows (up) # Then move in the negative direction along the columns (left) # Should do nothing, we are at the edge for d in (1, 3): b.move(d, suppress_invalid=True) self.assertEqual(b._tiles.take(pos), val) # Move in the positive direction along the rows (down) # This should move three rows b.move(0) pos += b.length * 3 self.assertEqual(b._tiles.take(pos), val) # At the bottom - movement should do nothing b.move(0, suppress_invalid=True) self.assertEqual(b._tiles.take(pos), val) # Move in the positive direction along the columns (right) # This should move three columns b.move(2) pos += 3 self.assertEqual(b._tiles.take(pos), val) # At the right - movement should do nothing b.move(2, suppress_invalid=True) self.assertEqual(b._tiles.take(pos), val)
def test_new_board_starts_with_two_squares(self): b = Board() self.assertFalse(b.is_board_full()) self.assertEqual(len(b.empty_tiles()), len(b._tiles.flatten()) - 2)