From 77dcdbc0fe22ce6147218e3615daef572e558054 Mon Sep 17 00:00:00 2001 From: mgreminger Date: Sat, 11 Jan 2025 21:20:33 -0600 Subject: [PATCH] fix: regression recognition of very small unit exponent as unitless --- public/dimensional_analysis.py | 6 +++--- tests/test_basic.spec.mjs | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/public/dimensional_analysis.py b/public/dimensional_analysis.py index f8ffb9c2..5b0c5662 100644 --- a/public/dimensional_analysis.py +++ b/public/dimensional_analysis.py @@ -966,8 +966,8 @@ def ensure_dims_all_compatible(*args): if len(args) == 1: return first_arg - first_arg_dims = normalize_dims_dict(custom_get_dimensional_dependencies(first_arg)) - if all(normalize_dims_dict(custom_get_dimensional_dependencies(arg)) == first_arg_dims for arg in args[1:]): + first_arg_dims = custom_get_dimensional_dependencies(first_arg) + if all(custom_get_dimensional_dependencies(arg) == first_arg_dims for arg in args[1:]): return first_arg raise TypeError('All input arguments to function need to have compatible units') @@ -1726,7 +1726,7 @@ def get_dimensional_analysis_expression(parameter_subs: dict[Symbol, Expr], def custom_get_dimensional_dependencies(expression: Expr | None): if expression is not None: expression = subs_wrapper(expression, {cast(Symbol, symbol): S.One for symbol in (expression.free_symbols - dimension_symbols)}) - return dimsys_SI.get_dimensional_dependencies(expression) + return normalize_dims_dict(dimsys_SI.get_dimensional_dependencies(expression)) def dimensional_analysis(dimensional_analysis_expression: Expr | None, dim_sub_error: Exception | None, custom_base_units: CustomBaseUnits | None = None): diff --git a/tests/test_basic.spec.mjs b/tests/test_basic.spec.mjs index 10731b8f..c107c2a4 100644 --- a/tests/test_basic.spec.mjs +++ b/tests/test_basic.spec.mjs @@ -796,6 +796,12 @@ test('Test floating point exponent rounding', async () => { await page.click('#add-math-cell'); await page.setLatex(5, String.raw`\mathrm{sum}\left(1\left\lbrack K\cdot s^{.000000000001}\right\rbrack,4\left\lbrack K\right\rbrack\right)=`); + // check small exponent rounding for dimensionless exponent check + await page.click('#add-math-cell'); + await page.setLatex(6, String.raw`6^{1\left\lbrack s^{.0000000000001}\right\rbrack}=`); + await page.click('#add-math-cell'); + await page.setLatex(7, String.raw`6^{1\left\lbrack s^{.000000000001}\right\rbrack}=`); + await page.waitForSelector('text=Updating...', {state: 'detached'}); let content = await page.textContent('#result-value-0'); @@ -808,7 +814,7 @@ test('Test floating point exponent rounding', async () => { content = await page.textContent('#result-units-1'); expect(content).toBe('kg'); - await expect(page.locator('#cell-2 >> text=Dimension Error')).toBeVisible(); + await expect(page.locator('#cell-2 >> text=Dimension Error: Only equivalent dimensions can be added or subtracted')).toBeVisible(); content = await page.textContent('#result-value-3'); expect(parseLatexFloat(content)).toBeCloseTo(4, precision); @@ -820,7 +826,14 @@ test('Test floating point exponent rounding', async () => { content = await page.textContent('#result-units-4'); expect(content).toBe('K'); - await expect(page.locator('#cell-5 >> text=Dimension Error')).toBeVisible(); + await expect(page.locator('#cell-5 >> text=Dimension Error: All input arguments to function need to have compatible units')).toBeVisible(); + + content = await page.textContent('#result-value-6'); + expect(parseLatexFloat(content)).toBeCloseTo(6, precision); + content = await page.textContent('#result-units-6'); + expect(content).toBe(''); + + await expect(page.locator('#cell-7 >> text=Dimension Error: Exponent Not Dimensionless')).toBeVisible(); }); test('Test function notation with integrals', async () => {