Files
chess/test/base.py
2025-08-22 14:28:48 -04:00

37 lines
1.0 KiB
Python

import unittest
from binding.python_c_ffi import ChessFFI
from test.chess_ffi import Board
from test.chess_ffi import KING_ATTACKS
from test.chess_ffi import KNIGHT_ATTACKS
from test.chess_ffi import PAWN_ATTACKS
from test.chess_ffi import gen_moves
from test.chess_ffi import init_attack_caches
from test.chess_ffi import load_fen
class ChessLibTestBase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.chess_ffi = ChessFFI()
init_attack_caches()
cls.KNIGHT_ATTACKS = KNIGHT_ATTACKS
cls.KING_ATTACKS = KING_ATTACKS
cls.PAWN_ATTACKS = PAWN_ATTACKS
def setUp(self):
# This should be an empty board for each test in the suite.
self.board = Board()
def load_fen(self, fen, board=None):
if board:
return self.chess_ffi.load_fen(board, fen)
return self.chess_ffi.load_fen(self.board, fen)
def gen(self, captures_only: bool = False, cap: int = 256):
return gen_moves(self.board, captures_only=captures_only, cap=cap)