-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from rjcohn/master
Allow legal variable characters to be modified
- Loading branch information
Showing
3 changed files
with
101 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.udojava.evalex; | ||
|
||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TestVariableCharacters { | ||
|
||
@Test | ||
public void testBadVarChar() { | ||
String err = ""; | ||
try { | ||
Expression expression = new Expression("a.b/2*PI+MIN(e,b)"); | ||
expression.eval(); | ||
} catch (Expression.ExpressionException e) { | ||
err = e.getMessage(); | ||
} | ||
assertEquals("Unknown operator '.' at position 2", err); | ||
} | ||
|
||
@Test | ||
public void testAddedVarChar() { | ||
String err = ""; | ||
Expression expression; | ||
|
||
try { | ||
expression = new Expression("a.b/2*PI+MIN(e,b)").setVariableCharacters("_"); | ||
expression.eval(); | ||
} catch (Expression.ExpressionException e) { | ||
err = e.getMessage(); | ||
} | ||
assertEquals("Unknown operator '.' at position 2", err); | ||
|
||
try { | ||
expression = new Expression("a.b/2*PI+MIN(e,b)").setVariableCharacters("_."); | ||
expression.eval(); | ||
} catch (Expression.ExpressionException e) { | ||
err = e.getMessage(); | ||
} | ||
assertEquals("Unknown operator or function: a.b", err); | ||
|
||
expression = new Expression("a.b/2*PI+MIN(e,b)").setVariableCharacters("_."); | ||
assertEquals("5.859875", expression.with("a.b", "2").and("b", "3").eval().toPlainString()); | ||
|
||
try { | ||
expression = new Expression(".a.b/2*PI+MIN(e,b)").setVariableCharacters("_."); | ||
expression.eval(); | ||
} catch (Expression.ExpressionException e) { | ||
err = e.getMessage(); | ||
} | ||
assertEquals("Unknown operator '.' at position 1", err); | ||
|
||
expression = new Expression("a.b/2*PI+MIN(e,b)").setVariableCharacters("_.").setFirstVariableCharacters("."); | ||
assertEquals("5.859875", expression.with("a.b", "2").and("b", "3").eval().toPlainString()); | ||
} | ||
} |