LittlePlyResearch notebook

test_inference.py

python · 28 lines · Exact bytes

Line 1 ↗
Version & provenance · state-v2-cm7

Recorded SHA-256 9e82ebac1d2a1e683663da8074a5e090aee279a6031413af8ae9918f0d1c5d0dRendered SHA-256 9e82ebac1d2a1e683663da8074a5e090aee279a6031413af8ae9918f0d1c5d0d

Apache-2.0 original project code; dependencies retain their own licenses. License notes. Line links are stable within this snapshot. CM-7 completed implementation source; original and public rendered hashes recorded. Host-specific paths use /work placeholders; inspect reproduction instructions before running. Separate Rust helper retains its GPL license.

1import unittest
2import codec as c
3from inference import State
4
5class Tests(unittest.TestCase):
6    def test_incremental_parity_and_bad_phase(self):
7        s=State();b=c.chess.Board()
8        for u in ('e2e4','e7e5','g1f3'):
9            m=c.chess.Move.from_uci(u);e=c.example(b,m)
10            for phase,t in enumerate(c.triple(m)):
11                self.assertEqual(s.inputs()['input_ids'],e['input_ids'][:120+phase])
12                with self.assertRaises(ValueError):s.feed(377)
13                s.feed(t)
14            b.push(m);self.assertEqual(s.finish().fen(),b.fen())
15        s.feed(57)
16        with self.assertRaises(ValueError):s.finish()
17    def test_fen_only_and_terminal(self):
18        s=State.from_fen('4k3/P7/8/8/8/8/8/4K3 w - - 0 37')
19        self.assertEqual(s.inputs()['input_ids'][1],c.HIST_NONE)
20        self.assertFalse(s.inputs()['metadata']['repetition_history_complete'])
21        for t in (48,56,65):s.feed(t)
22        self.assertEqual(s.board.piece_at(56).piece_type,c.chess.KNIGHT)
23        terminal=State.from_fen('7k/6Q1/6K1/8/8/8/8/8 b - - 0 1')
24        self.assertFalse(any(terminal.mask(True)))
25        with self.assertRaises(ValueError):terminal.inputs()
26
27if __name__=='__main__':unittest.main()
28