Skip to content

Commit 8cd2bf8

Browse files
committed
Add gaviota tests to standard test suite
1 parent 54cf977 commit 8cd2bf8

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

chess/gaviota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ def a8toa1_init():
17781778

17791779
a8toa1 = a8toa1_init()
17801780

1781-
class PythonTableBase(object):
1781+
class PythonTablebases(object):
17821782
""" Provide access to Gaviota tablebases via full python code."""
17831783

17841784
def __init__(self,directory):

test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,39 @@ def test_native_probe_wdl(self):
22582258
self.assertEqual(self.tablebases.probe_wdl(board), 1)
22592259

22602260

2261+
class GaviotaTestCase(unittest.TestCase):
2262+
2263+
def setUp(self):
2264+
self.tablebases = chess.gaviota.open_tablebases("data/gaviota", LibraryLoader=None)
2265+
2266+
def tearDown(self):
2267+
self.tablebases.close()
2268+
2269+
def test_dm(self):
2270+
with open("data/endgame-dm.epd") as epds:
2271+
for line, epd in enumerate(epds):
2272+
# Skip empty lines and comments.
2273+
epd = epd.strip()
2274+
if not epd or epd.startswith("#"):
2275+
continue
2276+
2277+
# Parse EPD.
2278+
board, extra = chess.Board.from_epd(epd)
2279+
2280+
# Skip 5 and 6 piece endgames.
2281+
if chess.pop_count(board.occupied) > 4:
2282+
continue
2283+
2284+
# Check DTM.
2285+
if extra["dm"] > 0:
2286+
expected = extra["dm"] * 2 - 1
2287+
else:
2288+
expected = extra["dm"] * 2
2289+
dtm = self.tablebases.probe_dtm(board).dtm
2290+
self.assertEqual(dtm, expected,
2291+
"Expecting dtm {0} for {1}, got {2} (at line {3})".format(expected, board.fen(), dtm, line + 1))
2292+
2293+
22612294
if __name__ == "__main__":
22622295
if "-v" in sys.argv or "--verbose" in sys.argv:
22632296
logging.basicConfig(level=logging.DEBUG)

test_gaviota.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import chess
66
import chess.gaviota
77

8-
#tables = chess.gaviota.open_tablebases("data/gaviota")
9-
tables = chess.gaviota.PythonTableBase("data/gaviota")
8+
tables = chess.gaviota.open_tablebases("data/gaviota", LibraryLoader=None)
109

11-
with open("data/long-endgames.epd") as epds:
10+
with open("data/endgame-dm.epd") as epds:
1211
for line, epd in enumerate(epds):
1312
# Skip empty lines and comments.
1413
epd = epd.strip()

0 commit comments

Comments
 (0)