Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit multiplication bug #92

Open
anunnakian opened this issue Apr 6, 2018 · 3 comments
Open

Implicit multiplication bug #92

anunnakian opened this issue Apr 6, 2018 · 3 comments

Comments

@anunnakian
Copy link

If you have the following formula "3x+1" and you disable the implicitMultiplication, I'll have, not an exception, but an error telling you that you have too much operators !!

@bvedrenne
Copy link

Current version of source throw exception.
@Test
public void testImplicitMultiplicationOffVariable() {
Expression e = new ExpressionBuilder("3x+1").variable("x").implicitMultiplication(false).build();
e.evaluate();
}
this is the exception thrown:

java.lang.IllegalArgumentException: No value has been set for the setVariable 'x'.

@shuvamc019
Copy link
Contributor

Thanks for the update @bvedrenne . It seems like that exception is only being thrown because the variable x has not been assigned any value. Your test could be rewritten as:

@Test
public void testImplicitMultiplicationOffVariable() {
Expression e = new ExpressionBuilder("3x+1").variable("x").implicitMultiplication(false).build().setVariable("x", 2);
e.evaluate();
}

This would assign x the arbitrary value of 2. However, since implicit multiplication is off, an IllegalArgumentException is still thrown, but this time it says that there is an invalid number of arguments passed to the function, which is a more accurate description of the exception thrown.

Correct me if I'm wrong, but it seems to me like that was the only issue with the code. Now, the correct exception is being thrown.

@anunnakian
Copy link
Author

Thanks for the update @bvedrenne and @shuvamc019 for your answer.
To my mind, I don't think throwing an exception that says there is an invalid number of arguments passed to the function, because we don't use a function (exp4j function) in our formula 3x+1.

The more accurate to me is to throw an UnknownFunctionOrVariableException. What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants