test_book_pair_loader.py
python · 13 lines · Exact bytes
Version & provenance · data-cm7
Recorded SHA-256 ff8d7f019d4557c25a4245f26658d6978578820971aaa5e399a736c73d2a2910Rendered SHA-256 ff8d7f019d4557c25a4245f26658d6978578820971aaa5e399a736c73d2a2910
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 numpy as np
3from book_pair_loader import BookPairs,PAIR_DTYPE,DTYPE
4class Fake:
5 def take(self,ids):
6 r=np.zeros(len(ids),dtype=DTYPE);return r
7class Tests(unittest.TestCase):
8 def test_every_alternative_changes_input_and_target(self):
9 obj=BookPairs.__new__(BookPairs);obj.records=Fake();obj.pairs=np.array([(0,i) for i in range(5)],dtype=PAIR_DTYPE);obj.targets=[np.array([[i,i+1,64] for i in range(5)])]
10 rows=obj.take(range(5));self.assertEqual(rows['y'].tolist(),obj.targets[0].tolist());self.assertEqual(rows['x'][:,-2:].tolist(),obj.targets[0][:,:2].tolist())
11 with self.assertRaises(IndexError):obj.take([-1])
12if __name__=='__main__':unittest.main()
13