Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

schach / tests / test_notation.py · 1.9 KB · at 3c63b1d52560 · raw

Outline: 7 definitions
1
import unittest
2
3
import chess
4
5
from schach import notation
6
7
8
class NotationTest(unittest.TestCase):
9
    def test_san(self):
10
        self.assertEqual(notation.san("Nf3", "de"), "Sf3")
11
        self.assertEqual(notation.san("Bxc6", "de"), "Lxc6")
12
        self.assertEqual(notation.san("e8=Q+", "de"), "e8=D+")
13
        self.assertEqual(notation.san("Rfe1", "de"), "Tfe1")
14
        self.assertEqual(notation.san("O-O", "de"), "O-O")
15
        self.assertEqual(notation.san("Nf3", "en"), "Nf3")
16
17
    def test_label(self):
18
        board = chess.Board()
19
        self.assertEqual(notation.label(board, chess.Move.from_uci("g1f3"), "de"), "1. Sf3")
20
        board.push_san("e4")
21
        self.assertEqual(notation.label(board, chess.Move.from_uci("b8c6"), "en"), "1… Nc6")
22
23
    def test_text(self):
24
        german = "Sg5 wäre wilder. Nach Sxe4 holt Te1 den Bauern zurück, dann Lxc6 und De2. Plan Sbd2–f1–g3, e8=D."
25
        self.assertEqual(notation.text(german, "de"), german)
26
        self.assertEqual(
27
            notation.text(german, "en"),
28
            "Ng5 wäre wilder. Nach Nxe4 holt Re1 den Bauern zurück, dann Bxc6 und Qe2. Plan Nbd2–f1–g3, e8=Q.",
29
        )
30
31
    def test_text_leaves_words_alone(self):
32
        sentence = "Schwarz deckt e5. Der Läufer zielt auf f7 – Lehrerin, Dame, Turm, König."
33
        self.assertEqual(notation.text(sentence, "en"), sentence)
34
35
36
class ClockPartsTest(unittest.TestCase):
37
    def test_parts(self):
38
        from schach.board import clock_parts
39
40
        self.assertEqual(clock_parts(300000), ("05", "00"))
41
        self.assertEqual(clock_parts(61000), ("01", "01"))
42
        self.assertEqual(clock_parts(19450), ("00", "19"))
43
        self.assertEqual(clock_parts(1800000), ("30", "00"))
44
        self.assertEqual(clock_parts(3723000), ("1:02", "03"))
45
        self.assertEqual(clock_parts(-5), ("00", "00"))
46
47
48
if __name__ == "__main__":
49
    unittest.main()