def test_piece_overlap(self): standard_piece = Piece.from_attributes() opposite_piece = Piece.from_attributes(True, True, False, True) self.assertTrue( Piece.overlap( standard_piece, opposite_piece ) )
def test_no_overlap(self): a = Piece.from_attributes(True, True, False, True) b = Piece.from_attributes(True, False, True, True) c = Piece.from_attributes(False, True, False, False) d = Piece.from_attributes(True, False, False, False) self.assertFalse( Piece.overlap( a, b, c, d ) )
def test_check_no_win_horizontal(self): game = Game() a = Piece.from_attributes(True, True, False, True) b = Piece.from_attributes(True, False, False, True) c = Piece.from_attributes(False, True, False, False) d = Piece.from_attributes(True, False, True, False) game.board.put(a, 0, 0) game.board.put(b, 1, 0) game.board.put(c, 2, 0) game.board.put(d, 3, 0) self.assertEqual(game.check_win(0, 0), False)
def test_check_win_negative_diagonal(self): game = Game() a = Piece.from_attributes(True, True, False, True) b = Piece.from_attributes(True, False, False, True) c = Piece.from_attributes(True, True, False, False) d = Piece.from_attributes(True, False, True, False) game.board.put(a, 0, 3) game.board.put(b, 1, 2) game.board.put(c, 2, 1) game.board.put(d, 3, 0) self.assertEqual(game.check_win(0, 3), True)
def test_check_win_vertical(self): game = Game() a = Piece.from_attributes(True, True, False, True) b = Piece.from_attributes(True, False, False, True) c = Piece.from_attributes(True, True, False, False) d = Piece.from_attributes(True, False, True, False) game.board.put(a, 0, 0) game.board.put(b, 0, 1) game.board.put(c, 0, 2) game.board.put(d, 0, 3) self.assertEqual(game.check_win(0, 0), True)
def test_creation_with_positive_attributes(self): standard_piece = Piece.from_attributes(True) self.assertEqual(standard_piece.value, 1) standard_piece = Piece.from_attributes(True, True) self.assertEqual(standard_piece.value, 3) standard_piece = Piece.from_attributes(True, True, True, True) self.assertEqual(standard_piece.value, 15) standard_piece = Piece.from_attributes(True, False, True, True) self.assertEqual(standard_piece.value, 13) standard_piece = Piece.from_attributes(True, False, False, True) self.assertEqual(standard_piece.value, 9)
def test_full_overlap(self): pieces = [] for black in (True, False): for tall in (True, False): for hole in (True, False): for square in (True, False): pieces.append( Piece.from_attributes(black, tall, hole, square) ) for piece in pieces: overlaps = 0 for other_piece in pieces: if piece == other_piece: continue if Piece.overlap(piece, other_piece): overlaps += 1 self.assertEqual( overlaps, 14 )
def test_creation(self): standard_piece = Piece.from_attributes() self.assertEqual(standard_piece.value, 0)
def test_put_simple(self): board = Board(2) piece = Piece.from_attributes(True, False) board.put(piece, 1, 1) with self.assertRaises(Exception): board.put(piece, 1, 1)