| 1 | """Zugliste: eine Nebenvariante steht unter dem Zug, den sie ersetzt (wie im PGN, bei Lichess und |
| 2 | ChessBase), nicht unter dem Zug davor. Entschieden 24.11.2026.""" |
| 3 | |
| 4 | import unittest |
| 5 | |
| 6 | import chess |
| 7 | |
| 8 | from schach import notation |
| 9 | from tests.test_zustand_regression import FakeWindow, played |
| 10 | |
| 11 | |
| 12 | def m(uci): |
| 13 | return chess.Move.from_uci(uci) |
| 14 | |
| 15 | |
| 16 | class Window(FakeWindow): |
| 17 | def _notation(self): |
| 18 | return notation.DEFAULT |
| 19 | |
| 20 | def _wdl_for(self, board, white): |
| 21 | return None |
| 22 | |
| 23 | def _node_white(self, tree, node): |
| 24 | return None |
| 25 | |
| 26 | |
| 27 | def first_moves(branches): |
| 28 | return [branch[0][2] for branch in branches] # SAN des ersten Zugs je Zweig |
| 29 | |
| 30 | |
| 31 | class ListTest(unittest.TestCase): |
| 32 | def setUp(self): |
| 33 | self.win = Window(played("e4", "e5", "Nf3", "Nc6"), mode="maia") |
| 34 | self.win._game_tree() |
| 35 | |
| 36 | def test_alternative_steht_unter_dem_ersetzten_zug(self): |
| 37 | win = self.win |
| 38 | win._game_node(1).add_variation(m("f1c4"), starting_comment="Bester Zug") # statt 2. Sf3 |
| 39 | found, _nodes = win._list_variations() |
| 40 | self.assertEqual(list(found), [2]) # unter 2. Sf3 (Halbzug 2), nicht unter 1… e5 |
| 41 | self.assertEqual(first_moves(found[2]), ["Lc4"]) |
| 42 | |
| 43 | def test_alternative_zum_ersten_zug(self): |
| 44 | win = self.win |
| 45 | win.game_tree.game.add_variation(m("d2d4")) |
| 46 | found, _nodes = win._list_variations() |
| 47 | self.assertEqual(list(found), [0]) # unter 1. e4 |
| 48 | |
| 49 | def test_gegenwart_bleibt_unter_dem_letzten_zug(self): |
| 50 | win = self.win |
| 51 | win._game_node(3).add_variation(m("f1b5"), starting_comment="Hinweis") # nach 2… Sc6: noch nicht gespielt |
| 52 | found, _nodes = win._list_variations() |
| 53 | self.assertEqual(list(found), [3]) |
| 54 | self.assertEqual(first_moves(found[3]), ["Lb5"]) |
| 55 | |
| 56 | def test_unterzweige_stehen_unter_dem_ersetzten_zug(self): |
| 57 | win = self.win |
| 58 | side = win._game_node(1).add_variation(m("f1c4")) # 2. Lc4 Sf6 (2… Lc5) 3. d3 |
| 59 | reply = side.add_variation(m("g8f6")) |
| 60 | side.add_variation(m("f8c5")) |
| 61 | reply.add_variation(m("d2d3")) |
| 62 | found, _nodes = win._list_variations() |
| 63 | moves = found[2][0] |
| 64 | self.assertEqual([step[2] for step in moves], ["Lc4", "Sf6", "d3"]) |
| 65 | self.assertEqual(moves[0][3], ()) # unter 2. Lc4: nichts |
| 66 | self.assertEqual([first_moves(moves[1][3])], [["Lc5"]]) # 2… Lc5 unter 2… Sf6, das es ersetzt |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | unittest.main() |