|
| 1 | +# SPDX-License-Identifier: MIT |
| 2 | +"""Model K's player-visible option text (host check, no GPU). |
| 3 | +
|
| 4 | +The create note of the opt-in k_approx option (clean/k/runtime/runtime_k.cpp, approx_note_), its a1 legacy-input line |
| 5 | +and the front end's K mode line (clean/runtime/interop/backend.cpp) reach the player's log. They name the option as a |
| 6 | +faster approximation and the default as the standard path (input stage); they make no claim of exactness (the project's |
| 7 | +wording rule). The note itself is checked on a device by |
| 8 | +clean/k/tests/test_k_runtime_d3d12.py test_k_approx_each_tag. |
| 9 | +
|
| 10 | +Run: python -m unittest clean.k.tests.test_k_option_text |
| 11 | +""" |
| 12 | +import os |
| 13 | +import re |
| 14 | +import unittest |
| 15 | + |
| 16 | +ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) |
| 17 | + |
| 18 | + |
| 19 | +class TestKOptionText(unittest.TestCase): |
| 20 | + def test_k_approx_note_wording(self): |
| 21 | + with open(os.path.join(ROOT, "clean", "k", "runtime", "runtime_k.cpp"), encoding="utf-8") as f: |
| 22 | + src = f.read() |
| 23 | + m = re.search(r"approx_note_ = std::string\(\"model K: close approximation k_approx=\"\)(.*?);\n", src, re.S) |
| 24 | + self.assertIsNotNone(m, "approx_note_ assignment not found") |
| 25 | + stmt = m.group(1) |
| 26 | + fixed = stmt.split("(approx_a1_ ? std::string(")[0] # the part every k_approx note carries |
| 27 | + self.assertIn('" (opt-in faster approximation; the default is the standard path)"', fixed) |
| 28 | + self.assertNotIn("exact", fixed) |
| 29 | + self.assertNotIn("default path is exact", src) |
| 30 | + a1 = stmt.split("(approx_a1_ ? std::string(")[1] # the a1 part of the note |
| 31 | + self.assertIn("run the standard input stage", a1) |
| 32 | + self.assertNotIn("exact", a1) |
| 33 | + m = re.search(r'frame_note_ = "(model K: k_approx=a1 [^"]*)";', src) |
| 34 | + self.assertIsNotNone(m, "the a1 legacy-input line not found") |
| 35 | + self.assertIn("run the standard input stage", m.group(1)) |
| 36 | + self.assertNotIn("exact", m.group(1)) |
| 37 | + |
| 38 | + def test_k_mode_line_wording(self): |
| 39 | + """The front end's K mode line (clean/runtime/interop/backend.cpp) names the default as the standard path and an |
| 40 | + opt-in mode as an approximation, with no claim of exactness.""" |
| 41 | + with open(os.path.join(ROOT, "clean", "runtime", "interop", "backend.cpp"), encoding="utf-8") as f: |
| 42 | + src = f.read() |
| 43 | + m = re.search(r'network model K mode: network=.*?\(exact \? "([^"]*)" : "([^"]*)"\)', src, re.S) |
| 44 | + self.assertIsNotNone(m, "the K mode line not found") |
| 45 | + self.assertEqual(m.groups(), (", the standard path", ", an approximation (opt-in)")) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + unittest.main() |
0 commit comments