Download test_study.py from aaaded/spark-capacity-boundary-study: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/datasets/aaaded/spark-capacity-boundary-study/resolve/main/test_study.py
- Command line
-
hf download hf://datasets/aaaded/spark-capacity-boundary-study/test_study.py
-
curl -L -o test_study.py https://huggingface.co/datasets/aaaded/spark-capacity-boundary-study/resolve/main/test_study.py
1.89 kB
| import json | |
| import unittest | |
| from study import make_corpus, score, enumerate_optimum, dp_optimum | |
| class StudyTests(unittest.TestCase): | |
| def setUp(self): | |
| self.case = make_corpus()['cases'][0] | |
| self.valid = 'FINAL_JSON: '+json.dumps(dict(value=self.case['optimum'], items=self.case['optimal_sets'][0])) | |
| def test_oracles_agree_for_every_capacity(self): | |
| for case in make_corpus()['cases']: | |
| for capacity in range(sum(x['weight'] for x in case['items'])+1): | |
| self.assertEqual(enumerate_optimum(case['items'], capacity)[0], dp_optimum(case['items'], capacity)) | |
| def test_valid_answer_and_thinking_channel(self): | |
| self.assertTrue(score(self.case, self.valid, False, False)['strict_correct']) | |
| self.assertTrue(score(self.case, '<think>provisional wrong answer</think>\n'+self.valid, True, False)['strict_correct']) | |
| def test_truncation_and_missing_thinking_end_fail(self): | |
| self.assertFalse(score(self.case, self.valid, False, True)['strict_correct']) | |
| self.assertFalse(score(self.case, self.valid, True, False)['strict_correct']) | |
| def test_wrong_claimed_value_fails(self): | |
| text='FINAL_JSON: '+json.dumps(dict(value=self.case['optimum']+1,items=self.case['optimal_sets'][0])) | |
| self.assertFalse(score(self.case,text,False,False)['strict_correct']) | |
| def test_ambiguous_invalid_and_infeasible_fail(self): | |
| bad=[self.valid+'\n'+self.valid,'FINAL_JSON: {"value":true,"items":[]}', | |
| 'FINAL_JSON: {"value":1,"items":["A","A"]}', 'FINAL_JSON: {"value":0,"items":["Z"]}', | |
| 'FINAL_JSON: '+json.dumps(dict(value=sum(x['value'] for x in self.case['items']),items=[x['id'] for x in self.case['items']]))] | |
| for text in bad: | |
| self.assertFalse(score(self.case,text,False,False)['strict_correct']) | |
| if __name__=='__main__': | |
| unittest.main() | |