Something went wrong. Try again.
[PRE-ALPHA] an open source web-based 2D/3D graphing calculator cartesium.org
Something went wrong. Try again.
TypeScript
at mathquill
123456789101112131415161718192021222324252627282930313233343536import { describe, expect, it } from 'vitest';import { polishMathNotation } from './polish-math-notation.js';
describe('completed function notation', () => { it('formats reductions with editable bounds without inventing a unit step', () => { expect(polishMathNotation(String.raw`\text{sum}\left(\left[k^{2}\text{ for }k\text{ in }1:n\right]\right)`)) .toBe(String.raw`\sum_{k=1}^{n}\left(k^{2}\right)`); expect(polishMathNotation(String.raw`\operatorname{product}\left(\left[k\text{ for }k\text{ in }1:2:n\right]\right)`)) .toBe(String.raw`\prod\left(\left[k\text{ for }k\text{ in }1:2:n\right]\right)`); expect(polishMathNotation(String.raw`\text{sum}\left(\left[1,2\right]\right)^{2}`)) .toBe(String.raw`\left(\sum\left(\left[1,2\right]\right)\right)^{2}`); }); it('preserves authored constants and unrelated formatting', () => { expect(polishMathNotation(String.raw`y=\operatorname{floor}\left(\pi\right)+\frac{1}{2}`)) .toBe(String.raw`y=\lfloor \pi\rfloor +\frac{1}{2}`); expect(polishMathNotation(String.raw`\text{floor_1}\left(x\right)+A^{T}`)) .toBe(String.raw`\text{floor_1}\left(x\right)+A^{T}`); }); it('formats nested shorthands and scopes outer powers', () => { expect(polishMathNotation(String.raw`\text{conj}\left(\text{norm}\left(\left[1,2\right]\right)\right)`)) .toBe(String.raw`\overline{\left\lVert \left[1,2\right]\right\rVert }`); expect(polishMathNotation(String.raw`\log\left(x,2\right)^{3}`)) .toBe(String.raw`\left(\log_{2} x\right)^{3}`); expect(polishMathNotation(String.raw`\text{transpose}\left(A+B\right)`)) .toBe(String.raw`\left(A+B\right)^{\top}`); }); it('keeps incomplete calls intact', () => { expect(polishMathNotation(String.raw`\operatorname{floor}\left(x`)) .toBe(String.raw`\operatorname{floor}\left(x`); }); it('keeps matrix and nested function commas inside their arguments', () => { expect(polishMathNotation(String.raw`\mathrm{integral}\left(\max\left(t,2\right),t,0,1\right)`)) .toBe(String.raw`\int_{0}^{1} \max\left(t,2\right) dt`); });});