Files

14 lines
790 B
Python

import importlib.util,pathlib,unittest
p=pathlib.Path(__file__).with_name('benchmark.py');spec=importlib.util.spec_from_file_location('bench',p);b=importlib.util.module_from_spec(spec);spec.loader.exec_module(b)
class PreparationTests(unittest.TestCase):
def test_exact_count_and_middle_needle(self):
case=b.choose_prompt(20000,lambda s:len(s))
self.assertLessEqual(case['counted_tokens'],20000)
self.assertGreater(case['counted_tokens'],19800)
self.assertEqual(case['text'].count(b.NEEDLE),1)
self.assertTrue(.45<case['needle_position_fraction']<.55)
def test_corpus_deterministic(self):self.assertEqual(b.corpus(30),b.corpus(50)[:30])
def test_output_has_space(self):
for ctx in b.CONTEXTS:self.assertLess(ctx-b.MARGIN+b.OUTPUT,ctx)
if __name__=='__main__':unittest.main()