Skip to content

Commit 52b517e

Browse files
authored
Merge pull request #72 from pie-framework/fix/PD-5052
fix(symbolic-validation): allow matching numbers with leading spaces and trailing zeros PD-5052
2 parents 404b11a + 5029887 commit 52b517e

3 files changed

Lines changed: 52 additions & 2 deletions

File tree

docs/js/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40801,7 +40801,7 @@ const differenceIsTooGreat = (a, b) => {
4080140801
const lta = new LatexToAst();
4080240802
const atm = new AstToMathJs();
4080340803
const latexEqual$1 = (a, b, opts) => {
40804-
const isNumeric = (str) => /^-?\d+(\.\d+)?$/.test(str);
40804+
const isNumeric = (str) => /^\s*-?\d+(\.\d+)?\s*$/.test(str);
4080540805
if (!a || !b) {
4080640806
return false;
4080740807
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export default {
2+
mode: "symbolic",
3+
tests: [
4+
// Core validation (leading space + trailing zeros)
5+
{ target: "1.3", eq: [" 1.30", "1.30", " 1.3", " 1.3000"] },
6+
{ target: "4.5", eq: [" 4.50", "4.500", " 4.5000"] },
7+
{ target: "43.0", eq: [" 43.0", "43.00", " 43.0000"] },
8+
{ target: "8.5", eq: ["8.5", "8.50", " 8.500"] },
9+
{ target: "0.0", eq: [" 0.0", "0.000", " 0.0000"] },
10+
{ target: "5.0", eq: [" 5.0", "5.00", " 5.000"] },
11+
12+
// Digits 1 through 9 as last decimal digit
13+
{ target: "4.1", eq: [" 4.10", "4.100", " 4.1000"] },
14+
{ target: "4.2", eq: [" 4.20", "4.200", " 4.2000"] },
15+
{ target: "4.3", eq: [" 4.30", "4.300", " 4.3000"] },
16+
{ target: "4.4", eq: [" 4.40", "4.400", " 4.4000"] },
17+
{ target: "4.6", eq: [" 4.60", "4.600", " 4.6000"] },
18+
{ target: "4.7", eq: [" 4.70", "4.700", " 4.7000"] },
19+
{ target: "4.8", eq: [" 4.80", "4.800", " 4.8000"] },
20+
{ target: "4.9", eq: [" 4.90", "4.900", " 4.9000"] },
21+
22+
// Leading spaces, trailing zeros, and mixed combinations
23+
{ target: "8.2", eq: [" 8.2", "8.20", " 8.200", " 8.2000"] },
24+
{ target: "5.9", eq: [" 5.90", "5.900", " 5.9000"] },
25+
{ target: "0.004", eq: [" 0.0040", "0.00400", " 0.004000"] },
26+
{ target: "0.00278", eq: [" 0.002780", "0.0027800"] },
27+
28+
// Negative values with same rules
29+
{ target: "-1.3", eq: [" -1.30", "-1.300", " -1.3000"] },
30+
{ target: "-0.65", eq: [" -0.650", "-0.6500"] },
31+
{ target: "-43.7", eq: [" -43.70", "-43.700", " -43.7000"] },
32+
{ target: "-5.4", eq: [" -5.40000", "-5.4000", " -5.40"] },
33+
34+
// Integer values with decimals + spaces
35+
{ target: "12", eq: [" 12.0", "12.000", " 12.0000"] },
36+
{ target: "-8", eq: [" -8.0", "-8.000", " -8.0000"] },
37+
38+
// Leading zero values
39+
{ target: "0.05", eq: [" 0.050", "0.0500", " 0.05000"] },
40+
{ target: "-0.03", eq: [" -0.030", "-0.0300", " -0.03000"] },
41+
42+
// Mixed padding
43+
{ target: "100.25", eq: [" 100.250", "100.2500", " 100.25000"] },
44+
{ target: "-100.25", eq: [" -100.250", "-100.2500", " -100.25000"] },
45+
46+
// Control cases
47+
{ target: "3", eq: [" 3.0", "3.00", " 3.000"] },
48+
{ target: "-3", eq: [" -3.0", "-3.00", " -3.000"] }
49+
]
50+
};

src/latex-equal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const lta = new LatexToAst();
1717
const atm = new AstToMathJs();
1818

1919
export const latexEqual = (a: Latex, b: Latex, opts: Opts) => {
20-
const isNumeric = (str: string): boolean => /^-?\d+(\.\d+)?$/.test(str);
20+
const isNumeric = (str: string): boolean => /^\s*-?\d+(\.\d+)?\s*$/.test(str);
2121

2222
if (!a || !b) {
2323
return false;

0 commit comments

Comments
 (0)