-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test class for EquationEvaluator
- Loading branch information
1 parent
2b373f6
commit 76e0bad
Showing
2 changed files
with
142 additions
and
105 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
37 changes: 37 additions & 0 deletions
37
src/test/java/world/bentobox/level/calculators/EquationEvaluatorTest.java
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,37 @@ | ||
package world.bentobox.level.calculators; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.text.ParseException; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Test the equation evaluation | ||
*/ | ||
public class EquationEvaluatorTest { | ||
|
||
/** | ||
* Test method for {@link world.bentobox.level.calculators.EquationEvaluator#eval(java.lang.String)}. | ||
* @throws ParseException | ||
*/ | ||
@Test | ||
public void testEval() throws ParseException { | ||
assertEquals(4D, EquationEvaluator.eval("2+2"), 0D); | ||
assertEquals(0D, EquationEvaluator.eval("2-2"), 0D); | ||
assertEquals(1D, EquationEvaluator.eval("2/2"), 0D); | ||
assertEquals(4D, EquationEvaluator.eval("2*2"), 0D); | ||
assertEquals(8D, EquationEvaluator.eval("2+2+2+2"), 0D); | ||
assertEquals(5D, EquationEvaluator.eval("2.5+2.5"), 0D); | ||
assertEquals(1.414, EquationEvaluator.eval("sqrt(2)"), 0.001D); | ||
assertEquals(3.414, EquationEvaluator.eval("2 + sqrt(2)"), 0.001D); | ||
assertEquals(0D, EquationEvaluator.eval("sin(0)"), 0.1D); | ||
assertEquals(1D, EquationEvaluator.eval("cos(0)"), 0.1D); | ||
assertEquals(0D, EquationEvaluator.eval("tan(0)"), 0.1D); | ||
assertEquals(0D, EquationEvaluator.eval("log(1)"), 0.1D); | ||
assertEquals(27D, EquationEvaluator.eval("3^3"), 0.D); | ||
assertEquals(84.70332D, EquationEvaluator.eval("3^3 + 2 + 2.65 * (3 / 4) - sin(45) * log(10) + 55.344"), | ||
0.0001D); | ||
|
||
} | ||
} |