|
15 | 15 | import static org.junit.jupiter.api.Assertions.*; |
16 | 16 |
|
17 | 17 | class ParserTest { |
| 18 | + public static final int MUL_PREC = 2; |
| 19 | + public static final int ADD_PREC = 3; |
| 20 | + |
18 | 21 | boolean nocache = false; |
19 | 22 |
|
20 | 23 | void assertInfixParsesTo(String src, int level, MathSymbol expected) { |
@@ -60,27 +63,27 @@ void assertInfixParsesToInner(String src, int level, MathSymbol expected) { |
60 | 63 |
|
61 | 64 | @Test |
62 | 65 | void parseInfixPrecedenceLevel() { |
63 | | - assertInfixParsesTo("1.0/2.0", 1, |
| 66 | + assertInfixParsesTo("1.0/2.0", MUL_PREC, |
64 | 67 | new DivOperation(new BasicDoubleSymbol(1.0), new BasicDoubleSymbol(2.0))); |
65 | | - assertInfixParsesTo(".3*6.", 1, |
| 68 | + assertInfixParsesTo(".3*6.", MUL_PREC, |
66 | 69 | new MulOperation(new BasicDoubleSymbol(.3), new BasicDoubleSymbol(6.))); |
67 | | - assertInfixParsesTo("2.1*5.3+1.1", 2, |
| 70 | + assertInfixParsesTo("2.1*5.3+1.1", ADD_PREC, |
68 | 71 | new AddOperation(new MulOperation(new BasicDoubleSymbol(2.1), new BasicDoubleSymbol(5.3)), new BasicDoubleSymbol(1.1))); |
69 | | - assertInfixParsesTo("0.9-2.1/.3", 2, |
| 72 | + assertInfixParsesTo("0.9-2.1/.3", ADD_PREC, |
70 | 73 | new SubOperation(new BasicDoubleSymbol(0.9), new DivOperation(new BasicDoubleSymbol(2.1), new BasicDoubleSymbol(.3)))); |
71 | | - assertInfixParsesTo("(2.2+1.1)+3.7", 2, |
| 74 | + assertInfixParsesTo("(2.2+1.1)+3.7", ADD_PREC, |
72 | 75 | new AddOperation(new AddOperation(new BasicDoubleSymbol(2.2), new BasicDoubleSymbol(1.1)), new BasicDoubleSymbol(3.7))); |
73 | | - assertInfixParsesTo(CommonData.getBigData1_groupingParens(), 2); |
74 | | - assertInfixParsesTo(CommonData.getBigData2_groupingParens(), 2); |
75 | | - assertInfixParsesTo("2.2+1.1+3.7", 2, |
| 76 | + assertInfixParsesTo(CommonData.getBigData1_groupingParens(), ADD_PREC); |
| 77 | + assertInfixParsesTo(CommonData.getBigData2_groupingParens(), ADD_PREC); |
| 78 | + assertInfixParsesTo("2.2+1.1+3.7", ADD_PREC, |
76 | 79 | new AddOperation(new AddOperation(new BasicDoubleSymbol(2.2), new BasicDoubleSymbol(1.1)), new BasicDoubleSymbol(3.7))); |
77 | | - assertInfixParsesTo("2.2+1.1+3.7+0.2", 2, |
| 80 | + assertInfixParsesTo("2.2+1.1+3.7+0.2", ADD_PREC, |
78 | 81 | new AddOperation(new AddOperation(new AddOperation(new BasicDoubleSymbol(2.2), new BasicDoubleSymbol(1.1)), new BasicDoubleSymbol(3.7)), new BasicDoubleSymbol(0.2))); |
79 | | - assertInfixParsesTo(CommonData.getBigData1_minimumParens(), 2); |
80 | | - assertInfixParsesTo(CommonData.getBigData2_minimumParens(), 2); |
81 | | - assertInfixParsesTo(".9/2./3.3", 1, |
| 82 | + assertInfixParsesTo(CommonData.getBigData1_minimumParens(), ADD_PREC); |
| 83 | + assertInfixParsesTo(CommonData.getBigData2_minimumParens(), ADD_PREC); |
| 84 | + assertInfixParsesTo(".9/2./3.3", MUL_PREC, |
82 | 85 | new DivOperation(new DivOperation(new BasicDoubleSymbol(.9), new BasicDoubleSymbol(2.)), new BasicDoubleSymbol(3.3))); |
83 | | - assertInfixParsesTo(".9/2./3.3", 2, |
| 86 | + assertInfixParsesTo(".9/2./3.3", ADD_PREC, |
84 | 87 | new DivOperation(new DivOperation(new BasicDoubleSymbol(.9), new BasicDoubleSymbol(2.)), new BasicDoubleSymbol(3.3))); |
85 | 88 | } |
86 | 89 |
|
|
0 commit comments