Files
chess/test/base.py
Josh 5b4dc74681
All checks were successful
Python tests (make) / test (push) Successful in 10s
Update test suite
Put all ffi code into its own module for clarity.
2025-08-17 17:23:42 -04:00

33 lines
967 B
Python

import unittest
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):
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(self, fen: str):
rc = load_fen(self.board, fen)
self.assertEqual(rc, 0, f"load_fen failed rc={rc} for FEN: {fen}")
return self.board
def gen(self, captures_only: bool = False, cap: int = 256):
return gen_moves(self.board, captures_only=captures_only, cap=cap)