Skip to content

Commit

Permalink
Implied Multiplication and checkNumberNameManyImpliedMultiplication /…
Browse files Browse the repository at this point in the history
… neverParseForImpliedMultiplication fixed #269
  • Loading branch information
mariuszgromada committed Aug 20, 2022
1 parent e09d0a3 commit b9cf669
Show file tree
Hide file tree
Showing 6 changed files with 425 additions and 20 deletions.
17 changes: 11 additions & 6 deletions CURRENT/c-sharp/src/org/mariuszgromada/math/mxparser/Expression.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.cs 5.0.7 2022-08-16
* @(#)Expression.cs 5.0.7 2022-08-20
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -7757,12 +7757,12 @@ private bool checkNumberNameManyImpliedMultiplication(Token token) {
else if (neverParseForImpliedMultiplication.Contains(substr)) {
keywordFound = true;
parserKeyword = new KeyWord();
}
break;
}
}
}

if (decimalFound || fractionFound || otherNumberBaseFound || keywordFound)
{
if (decimalFound || fractionFound || otherNumberBaseFound || keywordFound) {
// Checking if not recognized token was present
if (lPos - lastConsumedPos > 1) {
tokenPart = new TokenPart();
Expand All @@ -7787,8 +7787,13 @@ private bool checkNumberNameManyImpliedMultiplication(Token token) {

tokenParts.Add(tokenPart);

lastConsumedPos = rPos - 1;
lPos = rPos;
if (rPos > lPos) {
lastConsumedPos = rPos - 1;
lPos = rPos;
} else {
lastConsumedPos = tokenStrLength - 1;
lPos = tokenStrLength;
}
}
else {
lPos++;
Expand Down
93 changes: 89 additions & 4 deletions CURRENT/c-sharp/tests-and-release/4-Unit-Tests/ApiTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)ApiTest.cs 5.0.4 2022-05-22
* @(#)ApiTest.cs 5.0.7 2022-08-20
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace org.mariuszgromada.math.mxparser.test {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.0.3
* @version 5.0.7
*
*/
[TestClass]
Expand Down Expand Up @@ -3915,13 +3915,98 @@ public void testApi0151() {
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0152() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(152, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, 2*xi)", "sum(i,1,10,2*x*i)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0153() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(153, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, xi*2)", "sum(i,1,10,x*i*2)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0154() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(154, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, 2*ix)", "sum(i,1,10,2*i*x)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0155() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(155, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, ix*2)", "sum(i,1,10,i*x*2)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0156() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(156, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, 2*xpi)", "sum(i,1,10,2*x*pi)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0157() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(157, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, xpi*2)", "sum(i,1,10,x*pi*2)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0158() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(158, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, 2*pix)", "sum(i,1,10,2*pi*x)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testApi0159() {
TestCommonTools.testApiSettingsInit();
bool testResult = false;
String testDescr = "Implied Multiplication & canonical expression string test";
TestCommonTools.consolePrintTestApiStart(159, testDescr);
testResult = testCanonicalString("sum(i, 1, 10, pix*2)", "sum(i,1,10,pi*x*2)");
TestCommonTools.consolePrintTestApiEnd(testResult);
Assert.IsTrue(testResult);
}
public static bool testCanonicalString(String expStr, String expResStr, params String[] elements) {
Expression e = new Expression(expStr);
mXparser.consolePrintln();
mXparser.consolePrintln("------ expStr = " + expStr);
mXparser.consolePrintln("------ expResStr = " + expResStr);
Expression e = new Expression(expStr);
if (elements != null)
if (elements.Length > 0)
foreach (String str in elements)
e.addArguments(new Argument(str, "0"));
return expResStr.Equals(e.getCanonicalExpressionString());
String canExprStr = e.getCanonicalExpressionString();
mXparser.consolePrintln("------ canExprStr = " + canExprStr);
return expResStr.Equals(canExprStr);
}
}
}
116 changes: 114 additions & 2 deletions CURRENT/c-sharp/tests-and-release/4-Unit-Tests/SyntaxTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)SyntaxTest.cs 5.0.4 2022-05-22
* @(#)SyntaxTest.cs 5.0.7 2022-08-20
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace org.mariuszgromada.math.mxparser.test {
* <a href="https://play.google.com/store/apps/details?id=org.mathparser.scalar.pro" target="_blank">Scalar Pro</a><br>
* <a href="https://mathspace.pl" target="_blank">MathSpace.pl</a><br>
*
* @version 5.0.3
* @version 5.0.7
*
*/
[TestClass]
Expand Down Expand Up @@ -4751,5 +4751,117 @@ public void testSyn0308() {
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0309() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, 2*xi)";
TestCommonTools.consolePrintTestSynStart(309, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0310() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, xi*2)";
TestCommonTools.consolePrintTestSynStart(310, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0311() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, 2*ix)";
TestCommonTools.consolePrintTestSynStart(311, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0312() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, ix*2)";
TestCommonTools.consolePrintTestSynStart(310, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0313() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, 2*xpi)";
TestCommonTools.consolePrintTestSynStart(313, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0314() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, xpi*2)";
TestCommonTools.consolePrintTestSynStart(313, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0315() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, 2*pix)";
TestCommonTools.consolePrintTestSynStart(313, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
[TestMethod]
public void testSyn0316() {
TestCommonTools.testSynSettingsInit();
bool testResult = false;
String expStr = "sum(i, 1, 10, pix*2)";
TestCommonTools.consolePrintTestSynStart(313, expStr);
Expression e = new Expression(expStr);
bool syn = e.checkSyntax();
bool reg = false;
if (syn == reg)
testResult = true;
TestCommonTools.consolePrintTestSynEnd(syn, reg, testResult, e);
Assert.IsTrue(testResult);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* @(#)Expression.java 5.0.7 2022-08-16
* @(#)Expression.java 5.0.7 2022-08-20
*
* MathParser.org-mXparser DUAL LICENSE AGREEMENT as of date 2022-05-22
* The most up-to-date license is available at the below link:
Expand Down Expand Up @@ -7769,6 +7769,7 @@ private boolean checkNumberNameManyImpliedMultiplication(Token token) {
} else if (neverParseForImpliedMultiplication.contains(substr)) {
keywordFound = true;
parserKeyword = new KeyWord();
break;
}
}
}
Expand Down Expand Up @@ -7798,8 +7799,13 @@ private boolean checkNumberNameManyImpliedMultiplication(Token token) {

tokenParts.add(tokenPart);

lastConsumedPos = rPos - 1;
lPos = rPos;
if (rPos > lPos) {
lastConsumedPos = rPos - 1;
lPos = rPos;
} else {
lastConsumedPos = tokenStrLength - 1;
lPos = tokenStrLength;
}
} else {
lPos++;
}
Expand Down
Loading

0 comments on commit b9cf669

Please sign in to comment.