Ensure calculator factors are explicit

This commit is contained in:
Codex Agent
2026-03-09 19:22:48 +00:00
parent 56873816bb
commit c20f2ebc60
2 changed files with 66 additions and 41 deletions

View File

@@ -9,6 +9,9 @@ CONVERSION_RATE_UTIL = ROOT / "hdyc-svelte" / "src" / "lib" / "utils" / "convers
CATEGORY_PAGE = ROOT / "hdyc-svelte" / "src" / "routes" / "category" / "[category]" / "+page.svelte"
CALCULATOR_COMPONENT = ROOT / "hdyc-svelte" / "src" / "lib" / "components" / "Calculator.svelte"
TARGET_SLUG = "gauss-to-oersted"
NON_APPLICABLE_TWO_INPUT_STANDARD_SLUGS = {
"grams-per-liter-to-molarity",
}
def _extract_calculator_block(slug: str) -> str:
@@ -38,6 +41,28 @@ class GaussToOerstedConversionRateRegressionTests(unittest.TestCase):
self.assertIn("conversionRateText = getConversionRateText(config)", calculator_component_text)
self.assertIn('<span class="formula-hint">', calculator_component_text)
def test_all_applicable_two_input_standard_calculators_have_factors(self) -> None:
missing_factors: list[str] = []
for line in CALCULATORS_TS.read_text(encoding="utf-8").splitlines():
if '"type": "standard"' not in line:
continue
if '"labels": {"in1":' not in line or '"in2":' not in line or '"in3":' in line:
continue
slug_match = re.search(r'"slug": "([^"]+)"', line)
if not slug_match:
continue
slug = slug_match.group(1)
if slug in NON_APPLICABLE_TWO_INPUT_STANDARD_SLUGS:
continue
if '"factor":' not in line:
missing_factors.append(slug)
self.assertEqual(
missing_factors,
[],
f"Two-input standard calculators missing factors (and therefore conversion-rate text): {missing_factors}",
)
if __name__ == "__main__":
unittest.main()