From 21a925d6d25b009c655a7c3364dbf212c8174152 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 5 Aug 2017 16:56:50 -0700 Subject: [PATCH] Write two functions to help test the code. --- .../nwapw/abacus/tests/CalculationTests.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/test/java/org/nwapw/abacus/tests/CalculationTests.java diff --git a/src/test/java/org/nwapw/abacus/tests/CalculationTests.java b/src/test/java/org/nwapw/abacus/tests/CalculationTests.java new file mode 100644 index 0000000..bcf0305 --- /dev/null +++ b/src/test/java/org/nwapw/abacus/tests/CalculationTests.java @@ -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)); + } + +}