Skip to content

Commit

Permalink
fix: use standard SI symbol for base units
Browse files Browse the repository at this point in the history
sec now defaults to s, ampere now defaults to A, kelvin now defaults to K, candelar now defaults to cd, and mole now defaults to mol
  • Loading branch information
mgreminger committed Nov 18, 2023
1 parent 270eced commit 67891d1
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions public/dimensional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,11 @@ class CombinedExpressionScatter(TypedDict):
(0, 0, 0, 0, 0, 0, 0, 0, 0): "",
(1, 0, 0, 0, 0, 0, 0, 0, 0): "kg",
(0, 1, 0, 0, 0, 0, 0, 0, 0): "m",
(0, 0, 1, 0, 0, 0, 0, 0, 0): "sec",
(0, 0, 0, 1, 0, 0, 0, 0, 0): "ampere",
(0, 0, 0, 0, 1, 0, 0, 0, 0): "kelvin",
(0, 0, 0, 0, 0, 1, 0, 0, 0): "candela",
(0, 0, 0, 0, 0, 0, 1, 0, 0): "mole",
(0, 0, 1, 0, 0, 0, 0, 0, 0): "s",
(0, 0, 0, 1, 0, 0, 0, 0, 0): "A",
(0, 0, 0, 0, 1, 0, 0, 0, 0): "K",
(0, 0, 0, 0, 0, 1, 0, 0, 0): "cd",
(0, 0, 0, 0, 0, 0, 1, 0, 0): "mol",
(1, 1, -2, 0, 0, 0, 0, 0, 0): "N",
(0, 2, 0, 0, 0, 0, 0, 0, 0): "m^2",
(0, 3, 0, 0, 0, 0, 0, 0, 0): "m^3",
Expand Down
18 changes: 9 additions & 9 deletions tests/test_basic.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ test('Test basic functionality', async () => {
content = await page.textContent('#result-value-1');
expect(parseLatexFloat(content)).toBeCloseTo(6e-6, precision);
content = await page.textContent('#result-units-1');
expect(content).toBe('m^2*sec^-1');
expect(content).toBe('m^2*s^-1');

await page.type(':nth-match(math-field.editable, 2)', '[/mm^2');
await page.press(':nth-match(math-field.editable, 2)', 'ArrowRight');
Expand Down Expand Up @@ -438,7 +438,7 @@ test('Test basic functionality', async () => {
await page.type(':nth-match(math-field.editable, 1)', ']=')
await page.waitForSelector('text=Updating...', {state: 'detached'});
content = await page.textContent('#result-units-0');
expect(content).toBe('sec^-1')
expect(content).toBe('s^-1')

await page.click('#add-math-cell');
await page.type(':nth-match(math-field.editable, 2)', '1[1/sec');
Expand Down Expand Up @@ -1234,12 +1234,12 @@ test('Test temperature conversions', async () => {
content = await page.textContent('#result-value-2');
expect(parseLatexFloat(content)).toBeCloseTo(5/9, precision);
content = await page.textContent('#result-units-2');
expect(content).toBe('kelvin');
expect(content).toBe('K');

content = await page.textContent('#result-value-3');
expect(parseLatexFloat(content)).toBeCloseTo(283.15, precision);
content = await page.textContent('#result-units-3');
expect(content).toBe('kelvin');
expect(content).toBe('K');

content = await page.textContent('#result-value-4');
expect(parseLatexFloat(content)).toBeCloseTo(460.67, precision-1);
Expand All @@ -1259,12 +1259,12 @@ test('Test temperature conversions', async () => {
content = await page.textContent('#result-value-7');
expect(parseLatexFloat(content)).toBeCloseTo(2, precision);
content = await page.textContent('#result-units-7');
expect(content).toBe('kelvin^-1');
expect(content).toBe('K^-1');

content = await page.textContent('#result-value-8');
expect(parseLatexFloat(content)).toBeCloseTo(5/9, precision);
content = await page.textContent('#result-units-8');
expect(content).toBe('sec^1*kelvin^1');
expect(content).toBe('s^1*K^1');

});

Expand Down Expand Up @@ -1506,7 +1506,7 @@ test('Test angular frequency conversions', async () => {
let content = await page.textContent('#result-value-1');
expect(parseLatexFloat(content)).toBeCloseTo(6, precision);
content = await page.textContent('#result-units-1');
expect(content).toBe('sec^-1*rad^1');
expect(content).toBe('s^-1*rad^1');

content = await page.textContent('#result-value-2');
expect(parseLatexFloat(content)).toBeCloseTo(3/pi, precision);
Expand All @@ -1516,10 +1516,10 @@ test('Test angular frequency conversions', async () => {
content = await page.textContent('#result-value-3');
expect(parseLatexFloat(content)).toBeCloseTo(3/pi, precision);
content = await page.textContent('#result-units-3');
expect(content).toBe('sec^-1');
expect(content).toBe('s^-1');

content = await page.textContent('#result-value-4');
expect(parseLatexFloat(content)).toBeCloseTo(3/pi, precision);
content = await page.textContent('#result-units-4');
expect(content).toBe('sec^-1');
expect(content).toBe('s^-1');
});
2 changes: 1 addition & 1 deletion tests/test_calc.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('test basic calculus', async () => {
content = await page.textContent('#result-value-10');
expect(parseLatexFloat(content)).toBeCloseTo(20, precision);
content = await page.textContent('#result-units-10');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');
content = await page.textContent('#result-value-11');
expect(content).toBe('x');
content = await page.textContent('#result-value-12');
Expand Down
2 changes: 1 addition & 1 deletion tests/test_functions.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test('Test min/max functions', async ({ browserName }) => {
let content = await page.locator('#result-value-1').textContent();
expect(parseLatexFloat(content)).toBeCloseTo(-.002, precision);
content = await page.locator('#result-units-1').textContent();
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

await page.setLatex(2, 'y=-10\\left[mm\\right]');

Expand Down
2 changes: 1 addition & 1 deletion tests/test_generated_code.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ test('Funciton with two inputs', async () => {
Returns
-------
float
Return value has units of [m sec].
Return value has units of [m s].
"""
result = x*z
Expand Down
10 changes: 5 additions & 5 deletions tests/test_matrix_addition.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test('Matrix addition with units', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack sec\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack s\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
});

test('Matrix addition with incompatible units', async () => {
Expand Down Expand Up @@ -98,7 +98,7 @@ test('Test subtraction with units', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} -4\left\lbrack m\right\rbrack & -4\left\lbrack sec\right\rbrack \\ -4\left\lbrack kg\right\rbrack & -4\left\lbrack rad\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} -4\left\lbrack m\right\rbrack & -4\left\lbrack s\right\rbrack \\ -4\left\lbrack kg\right\rbrack & -4\left\lbrack rad\right\rbrack \end{bmatrix}`);
});

test('Incompatible size addition', async () => {
Expand All @@ -124,7 +124,7 @@ test('nonsquare addition', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 7\left\lbrack m\right\rbrack & 7\left\lbrack sec\right\rbrack \\ 7\left\lbrack kg\right\rbrack & 7\left\lbrack rad\right\rbrack \\ 7\left\lbrack kelvin\right\rbrack & 7\left\lbrack ampere\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 7\left\lbrack m\right\rbrack & 7\left\lbrack s\right\rbrack \\ 7\left\lbrack kg\right\rbrack & 7\left\lbrack rad\right\rbrack \\ 7\left\lbrack K\right\rbrack & 7\left\lbrack A\right\rbrack \end{bmatrix}`);
});

test('Addition with literal and variable matrices', async () => {
Expand All @@ -144,7 +144,7 @@ test('Addition with literal and variable matrices', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack sec\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack s\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
});

test('Addition with two variable matrices', async () => {
Expand All @@ -168,7 +168,7 @@ test('Addition with two variable matrices', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack sec\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 6\left\lbrack m\right\rbrack & 8\left\lbrack s\right\rbrack \\ 10\left\lbrack kg\right\rbrack & 12\left\lbrack rad\right\rbrack \end{bmatrix}`);
});

test('Addition scalar and variable matrix', async () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_matrix_inverse.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ test('Matrix inverse with mixed units', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

let content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 2\left\lbrack \frac{1}{m}\right\rbrack & -3\left\lbrack \frac{1}{m}\right\rbrack \\ -1\left\lbrack \frac{1}{sec}\right\rbrack & 2\left\lbrack \frac{1}{sec}\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 2\left\lbrack \frac{1}{m}\right\rbrack & -3\left\lbrack \frac{1}{m}\right\rbrack \\ -1\left\lbrack \frac{1}{s}\right\rbrack & 2\left\lbrack \frac{1}{s}\right\rbrack \end{bmatrix}`);
});

test('Matrix inverse exponent with mixed units', async () => {
Expand All @@ -76,7 +76,7 @@ test('Matrix inverse exponent with mixed units', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

let content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 2\left\lbrack \frac{1}{m}\right\rbrack & -3\left\lbrack \frac{1}{m}\right\rbrack \\ -1\left\lbrack \frac{1}{sec}\right\rbrack & 2\left\lbrack \frac{1}{sec}\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 2\left\lbrack \frac{1}{m}\right\rbrack & -3\left\lbrack \frac{1}{m}\right\rbrack \\ -1\left\lbrack \frac{1}{s}\right\rbrack & 2\left\lbrack \frac{1}{s}\right\rbrack \end{bmatrix}`);
});

test('Matrix inverse with inconsistent units', async () => {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_matrix_multiplication.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ test('Units with scalar literal times matrix literal', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

let content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot sec\right\rbrack & 10\left\lbrack kg\cdot sec\right\rbrack \\ 15\left\lbrack sec\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot sec\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot s\right\rbrack & 10\left\lbrack kg\cdot s\right\rbrack \\ 15\left\lbrack s\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot s\right\rbrack \end{bmatrix}`);

// change order of scalar-matrix multiplication, should commute
await page.setLatex(0, String.raw`\begin{bmatrix}1\left\lbrack m\right\rbrack & 2\left\lbrack kg\right\rbrack\\ 3\left\lbrack radian\right\rbrack & 4\left\lbrack m^2\right\rbrack\end{bmatrix}\cdot 5\left\lbrack s\right\rbrack=`);

await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot sec\right\rbrack & 10\left\lbrack kg\cdot sec\right\rbrack \\ 15\left\lbrack sec\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot sec\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot s\right\rbrack & 10\left\lbrack kg\cdot s\right\rbrack \\ 15\left\lbrack s\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot s\right\rbrack \end{bmatrix}`);
});

test('Variable scalar times variable matrix', async () => {
Expand All @@ -294,15 +294,15 @@ test('Variable scalar times variable matrix', async () => {
await page.waitForSelector('text=Updating...', {state: 'detached'});

let content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot sec\right\rbrack & 10\left\lbrack kg\cdot sec\right\rbrack \\ 15\left\lbrack sec\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot sec\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot s\right\rbrack & 10\left\lbrack kg\cdot s\right\rbrack \\ 15\left\lbrack s\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot s\right\rbrack \end{bmatrix}`);

// change order of scalar-matrix multiplication, should commute
await page.setLatex(0, String.raw`A\cdot a=`);

await page.waitForSelector('text=Updating...', {state: 'detached'});

content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot sec\right\rbrack & 10\left\lbrack kg\cdot sec\right\rbrack \\ 15\left\lbrack sec\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot sec\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} 5\left\lbrack m\cdot s\right\rbrack & 10\left\lbrack kg\cdot s\right\rbrack \\ 15\left\lbrack s\cdot rad\right\rbrack & 20\left\lbrack m^{2}\cdot s\right\rbrack \end{bmatrix}`);
});

test('Cross product with column vectors and variable entries', async () => {
Expand All @@ -329,7 +329,7 @@ test('Cross product with column vectors and numeric entries and units', async ()
await page.waitForSelector('text=Updating...', {state: 'detached'});

let content = await page.textContent(`#result-value-0`);
expect(content).toBe(String.raw`\begin{bmatrix} -3\left\lbrack kg\cdot sec\right\rbrack \\ 6\left\lbrack m\cdot sec\right\rbrack \\ -3\left\lbrack kg\cdot m\right\rbrack \end{bmatrix}`);
expect(content).toBe(String.raw`\begin{bmatrix} -3\left\lbrack kg\cdot s\right\rbrack \\ 6\left\lbrack m\cdot s\right\rbrack \\ -3\left\lbrack kg\cdot m\right\rbrack \end{bmatrix}`);
});

test('Cross product with column vectors and numeric entries and incompatible units', async () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/test_system_solve.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ test('Test equation solving', async () => {
content = await page.textContent('#result-value-4');
expect(parseLatexFloat(content)).toBeCloseTo(-0.01, precision);
content = await page.textContent('#result-units-4');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

content = await page.textContent('#result-value-5');
expect(parseLatexFloat(content)).toBeCloseTo(-0.022369362920544027, precision);
Expand All @@ -130,7 +130,7 @@ test('Test equation solving', async () => {
content = await page.textContent('#result-value-4');
expect(parseLatexFloat(content)).toBeCloseTo(0.01, precision);
content = await page.textContent('#result-units-4');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

content = await page.textContent('#result-value-5');
expect(parseLatexFloat(content)).toBeCloseTo(0.022369362920544027, precision);
Expand Down Expand Up @@ -161,7 +161,7 @@ test('test underdetermined system that has exact numerical solution', async () =
let content = await page.textContent('#result-value-1');
expect(parseLatexFloat(content)).toBeCloseTo(-sqrt(2*9.81*10*12*25.4/1000), precision);
content = await page.textContent('#result-units-1');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

// update previous example to use assignment instead of equality
await page.setLatex(0, String.raw`h=\frac{1}{2\cdot g}\cdot v^{2}`, 2);
Expand All @@ -174,7 +174,7 @@ test('test underdetermined system that has exact numerical solution', async () =
content = await page.textContent('#result-value-1');
expect(parseLatexFloat(content)).toBeCloseTo(sqrt(2*9.81*10*12*25.4/1000), precision);
content = await page.textContent('#result-units-1');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

// update previous example to use assignment with m on both sides
// leave on second solution
Expand All @@ -185,7 +185,7 @@ test('test underdetermined system that has exact numerical solution', async () =
content = await page.textContent('#result-value-1');
expect(parseLatexFloat(content)).toBeCloseTo(sqrt(2*9.81*10*12*25.4/1000), precision);
content = await page.textContent('#result-units-1');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

});

Expand Down Expand Up @@ -316,7 +316,7 @@ test('Test function notation with equation solving and combined function/assignm
content = await page.textContent('#result-value-6');
expect(parseLatexFloat(content)).toBeCloseTo(sqrt(2*9.81*.003), precision);
content = await page.textContent('#result-units-6');
expect(content).toBe('m^1*sec^-1');
expect(content).toBe('m^1*s^-1');

});

Expand Down

0 comments on commit 67891d1

Please sign in to comment.