mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-17 16:09:32 -08:00
Write two functions to help test the code.
This commit is contained in:
parent
edba2eca2e
commit
a964f8982c
36
src/test/java/org/nwapw/abacus/tests/CalculationTests.java
Normal file
36
src/test/java/org/nwapw/abacus/tests/CalculationTests.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package org.nwapw.abacus.tests;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.nwapw.abacus.Abacus;
|
||||
import org.nwapw.abacus.number.NumberInterface;
|
||||
import org.nwapw.abacus.plugin.StandardPlugin;
|
||||
import org.nwapw.abacus.tree.TreeNode;
|
||||
|
||||
public class CalculationTests {
|
||||
|
||||
private static Abacus abacus = new Abacus();
|
||||
|
||||
@BeforeClass
|
||||
public static void prepareTests(){
|
||||
abacus.getPluginManager().addInstantiated(new StandardPlugin(abacus.getPluginManager()));
|
||||
abacus.getPluginManager().load();
|
||||
}
|
||||
|
||||
private void testOutput(String input, String parseOutput, String output){
|
||||
TreeNode parsedTree = abacus.parseString(input);
|
||||
Assert.assertNotNull(parsedTree);
|
||||
Assert.assertEquals(parsedTree.toString(), parseOutput);
|
||||
NumberInterface result = abacus.evaluateTree(parsedTree);
|
||||
Assert.assertNotNull(result);
|
||||
Assert.assertTrue(result.toString().startsWith(output));
|
||||
}
|
||||
|
||||
private void testEvalError(String input, String parseOutput){
|
||||
TreeNode parsedTree = abacus.parseString(input);
|
||||
Assert.assertNotNull(parsedTree);
|
||||
Assert.assertEquals(parsedTree.toString(), parseOutput);
|
||||
Assert.assertNull(abacus.evaluateTree(parsedTree));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user