Skip to content

Commit 821d13b

Browse files
author
Ryan Delaney
committed
Add tests for var_end_comment()
1 parent fbd77fa commit 821d13b

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

tests/test_functions.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,46 @@ def test_typeerror(self):
298298
self.assertRaises(TypeError, annotator.get_nags, judgment)
299299

300300

301+
class test_var_end_comment(unittest.TestCase):
302+
303+
def test_stalemate(self):
304+
board = chess.Board(fen='7k/8/6Q1/8/8/8/8/K7 b - - 0 1')
305+
judgment = {'bestcomment': "", 'depth': ""}
306+
result = annotator.var_end_comment(board, judgment)
307+
self.assertEqual(result, "Stalemate")
308+
309+
def test_insufficient_material(self):
310+
board = chess.Board(fen='7k/8/8/8/8/8/N7/K7 b - - 0 1')
311+
judgment = {'bestcomment': "", 'depth': ""}
312+
result = annotator.var_end_comment(board, judgment)
313+
self.assertEqual(result, "Insufficient material to mate")
314+
315+
def test_fifty_move_rule(self):
316+
board = chess.Board(fen='7k/8/8/8/8/1P6/N7/K7 b - - 100 150')
317+
judgment = {'bestcomment': "", 'depth': ""}
318+
result = annotator.var_end_comment(board, judgment)
319+
self.assertEqual(result, "Fifty move rule")
320+
321+
def test_threefold_repetition(self):
322+
board = chess.Board(fen='7k/8/8/8/8/1P6/N7/K7 b - - 0 1')
323+
moves = ["Kg8", "Nc1", "Kh8", "Na2", "Kg8", "Nc1", "Kh8", "Na2", "Kg8", "Nc1", "Kh8", "Na2"]
324+
for move in moves:
325+
board.push_san(move)
326+
judgment = {'bestcomment': "", 'depth': ""}
327+
result = annotator.var_end_comment(board, judgment)
328+
self.assertEqual(result, "Three-fold repetition")
329+
330+
def test_checkmate(self):
331+
board = chess.Board(fen='8/8/8/8/8/1K6/8/1k1R4 b - - 0 1')
332+
judgment = {'bestcomment': "", 'depth': ""}
333+
result = annotator.var_end_comment(board, judgment)
334+
self.assertEqual(result, "")
335+
336+
def test_other(self):
337+
board = chess.Board(fen='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1')
338+
judgment = {'bestcomment': "foo", 'depth': "bar"}
339+
result = annotator.var_end_comment(board, judgment)
340+
self.assertEqual(result, "foo/bar")
341+
342+
301343
# vim: ft=python expandtab smarttab shiftwidth=4 softtabstop=4 fileencoding=UTF-8:

0 commit comments

Comments
 (0)