-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: string expression to latex expression conversion (#4181)
- Loading branch information
Showing
5 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/client/hmi-client/tests/unit/services/string-to-latex-expression.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { stringToLatexExpression } from '@/services/model'; | ||
|
||
describe('stringToLatexExpression', () => { | ||
it('should wrap variables after underscores in {} and escape subsequent underscores', () => { | ||
const expression = 'x_variable'; | ||
const expected = 'x_{variable}'; | ||
const result = stringToLatexExpression(expression); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should convert ^ to LaTeX superscript notation', () => { | ||
const expression = 'x^2'; | ||
const expected = 'x^{2}'; | ||
const result = stringToLatexExpression(expression); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should detect and convert fractions a/b to \\frac{a}{b}', () => { | ||
const expression = '1/2'; | ||
const expected = '\\frac{1}{2}'; | ||
const result = stringToLatexExpression(expression); | ||
expect(result).toEqual(expected); | ||
}); | ||
|
||
it('should handle the expression I_unvaccinated^2*NPI_mult*S_unvaccinated*beta/N', () => { | ||
const expression = 'I_unvaccinated^2*NPI_mult*S_unvaccinated*beta/N'; | ||
const expected = 'I_{unvaccinated}^{2}*NPI_{mult}*S_{unvaccinated}*\\frac{beta}{N}'; | ||
const result = stringToLatexExpression(expression); | ||
expect(result).toEqual(expected); | ||
}); | ||
}); |