test_curriculum_policy.py
python · 84 lines · Exact bytes
Version & provenance · data-cm7
Recorded SHA-256 fda1133cf0f020fbc31cd4c493f96b79eed2eb34dc589389c59927dde5aa5116Rendered SHA-256 fda1133cf0f020fbc31cd4c493f96b79eed2eb34dc589389c59927dde5aa5116
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
2from curriculum_policy import preflight, select, FREE_RESERVE, TABLE_CAP
3
4
5class PolicyTests(unittest.TestCase):
6 def flight(self, files=None, **kw):
7 args = dict(host_free=100_000_000_000, native_free=100_000_000_000,
8 task_bytes=10)
9 args.update(kw)
10 return preflight(files or [dict(name='KQvK.rtbw', bytes=100)], **args)
11
12 def test_budget_before_download(self):
13 self.assertEqual(self.flight()['projected_task_bytes'], 110)
14 with self.assertRaises(ValueError):
15 self.flight([dict(name='KQvK.rtbw', bytes=TABLE_CAP + 1)])
16
17 def test_requires_both_disks(self):
18 for kw in (dict(native_free=None), dict(host_free=None),
19 dict(native_free=FREE_RESERVE), dict(host_free=FREE_RESERVE)):
20 with self.assertRaises(ValueError): self.flight(**kw)
21
22 def test_total_cap(self):
23 with self.assertRaises(ValueError): self.flight(task_bytes=2_000_000_000)
24
25 def test_reuse_and_mismatch(self):
26 self.assertEqual(self.flight(reusable={'KQvK.rtbw':100})['new_bytes'], 0)
27 with self.assertRaises(ValueError): self.flight(reusable={'KQvK.rtbw':99})
28
29 def test_reject_unsafe_or_large_tables(self):
30 for name in ('../KQvK.rtbw', 'KQQvKQQ.rtbw', 'KvK.rtbw', 'KQvK.exe'):
31 with self.assertRaises(ValueError): self.flight([dict(name=name, bytes=100)])
32
33 def test_unknown_size_and_duplicates(self):
34 for size in (None, 0, -1, True):
35 with self.assertRaises(ValueError): self.flight([dict(name='KQvK.rtbw', bytes=size)])
36 with self.assertRaises(ValueError):
37 self.flight([dict(name='KQvK.rtbw', bytes=1)]*2)
38
39 def candidate(self, key='key', **kw):
40 c=dict(position_key=key, game_aliases=['id:synthetic'], source_kind='tablebase_exact',
41 legal_verified=True, terminal=False, pieces=3, castling=False,
42 clock_verified=True, all_children_probed=True, wdl=2, dtz=4,
43 repetition_status='unknown', preserving_moves=['a1a2','a1b1'],
44 material_family='KQvK', from_real_game=True)
45 c.update(kw)
46 return c
47
48 def choose(self, cs, **kw):
49 args=dict(protected_keys=set(), protected_games=set(), limit=10,
50 family_cap=5, source_kind='tablebase_exact', protection_verified=True)
51 args.update(kw)
52 return select(cs, **args)
53
54 def test_protection_fail_closed(self):
55 with self.assertRaises(ValueError): self.choose([], protection_verified=False)
56 self.assertEqual(self.choose([self.candidate()],protected_keys={'key'})[0], [])
57 self.assertEqual(self.choose([self.candidate()],protected_games={'id:synthetic'})[0], [])
58
59 def test_preserve_ties_and_unknown_repetition(self):
60 c=self.choose([self.candidate()])[0][0]
61 self.assertEqual(c['preserving_moves'], ['a1a2','a1b1'])
62 self.assertEqual(c['repetition_status'], 'unknown')
63
64 def test_reject_unverified_semantics(self):
65 for kw in (dict(clock_verified=False), dict(all_children_probed=False),
66 dict(terminal=True), dict(castling=True), dict(pieces=6),
67 dict(preserving_moves=[]), dict(dtz=None), dict(wdl=3)):
68 self.assertEqual(self.choose([self.candidate(**kw)])[0], [])
69
70 def test_dedup_cap_and_determinism(self):
71 cs=[self.candidate(str(i)) for i in range(8)]
72 a=self.choose(cs+cs)[0]
73 b=self.choose(list(reversed(cs)))[0]
74 self.assertEqual(a,b)
75 self.assertEqual(len(a),5)
76
77 def test_separate_provenance(self):
78 self.assertEqual(self.choose([self.candidate(source_kind='human_main')])[0], [])
79 c=self.candidate(source_kind='opening_supported', distinct_game_support=2)
80 self.assertEqual(self.choose([c],source_kind='opening_supported')[0], [])
81
82
83if __name__ == '__main__': unittest.main(verbosity=2)
84