Download annotations/annotation_19/test.py from mcy98/RECODE-H: direct link, hf CLI and curl.
- Browser
- Download file 3.41 kB
-
https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_19/test.py
- Command line
-
hf download hf://datasets/mcy98/RECODE-H/annotations/annotation_19/test.py
-
curl -L -o test.py https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_19/test.py
3.41 kB
| import unittest | |
| import copy | |
| from canonical import simult_search as canonical_simult_search | |
| ## Revise simult to canonical for testing | |
| from simult import simult_search as generated_simult_search | |
| class TestSimultSearchAllSamples(unittest.TestCase): | |
| def setUp(self): | |
| # Define at least three different representative samples | |
| # 1. Linear chain | |
| sample_chain = { | |
| "claims": [ | |
| {"subclaim": "Step 1", "frequency-score": 4.0}, | |
| {"subclaim": "Step 2", "frequency-score": 3.0}, | |
| {"subclaim": "Step 3", "frequency-score": 5.0} | |
| ], | |
| "dep_graph": [ | |
| [0, 0, 0], | |
| [1, 0, 0], | |
| [0, 1, 0] | |
| ] | |
| } | |
| # 2. Star structure | |
| sample_star = { | |
| "claims": [ | |
| {"subclaim": "root", "frequency-score": 4.5}, | |
| {"subclaim": "leaf1", "frequency-score": 3.5}, | |
| {"subclaim": "leaf2", "frequency-score": 2.5} | |
| ], | |
| "dep_graph": [ | |
| [0, 0, 0], | |
| [1, 0, 0], | |
| [1, 0, 0] | |
| ] | |
| } | |
| # 3. Diamond (fork and join) | |
| sample_diamond = { | |
| "claims": [ | |
| {"subclaim": "Let n be an integer.", "frequency-score": 5.0}, | |
| {"subclaim": "n is even if n mod 2 = 0.", "frequency-score": 3.0}, | |
| {"subclaim": "n is odd if n mod 2 = 1.", "frequency-score": 2.0}, | |
| {"subclaim": "n is either even or odd.", "frequency-score": 4.0} | |
| ], | |
| "dep_graph": [ | |
| [0, 0, 0, 0], | |
| [1, 0, 0, 0], | |
| [1, 0, 0, 0], | |
| [0, 1, 1, 0] | |
| ] | |
| } | |
| # You may add more samples here | |
| self.samples = [ | |
| ("Linear chain", sample_chain), | |
| ("Star", sample_star), | |
| ("Diamond", sample_diamond), | |
| ] | |
| self.noise = 0.001 | |
| self.risk = "freq" | |
| self.beta = 0.2 | |
| def test_simult_search_equivalence_over_samples(self): | |
| for name, question in self.samples: | |
| with self.subTest(sample=name): | |
| # Use deepcopy to avoid side effects | |
| q1 = copy.deepcopy(question) | |
| q2 = copy.deepcopy(question) | |
| out_canon = canonical_simult_search(q1, self.noise, ind=False, risk=self.risk, beta=self.beta) | |
| out_gen = generated_simult_search(q2, self.noise, ind=False, risk=self.risk, beta=self.beta) | |
| self.assertIsInstance(out_gen, dict, f"[{name}] Output type mismatch") | |
| self.assertEqual( | |
| set(out_canon.keys()), set(out_gen.keys()), | |
| f"[{name}] Key set mismatch: {set(out_canon.keys())} vs {set(out_gen.keys())}" | |
| ) | |
| for k in out_canon: | |
| self.assertEqual( | |
| out_canon[k][0], out_gen[k][0], | |
| f"[{name}] Included indices mismatch at subgraph {k}: {out_canon[k][0]} vs {out_gen[k][0]}" | |
| ) | |
| self.assertAlmostEqual( | |
| out_canon[k][1], out_gen[k][1], places=6, | |
| msg=f"[{name}] Risk threshold mismatch at subgraph {k}: {out_canon[k][1]} vs {out_gen[k][1]}" | |
| ) | |
| if __name__ == "__main__": | |
| unittest.main() | |