From 3baa44f1c8459713a96f4db994ee9905cc4e8df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gassmann?= Date: Fri, 11 Jun 2021 18:22:23 +0200 Subject: [~] Updated the unit tests to take in account the variables --- .../src/test/java/ExpressionParserTest.java | 115 --------------------- 1 file changed, 115 deletions(-) delete mode 100644 calculator-java/src/test/java/ExpressionParserTest.java (limited to 'calculator-java/src/test/java/ExpressionParserTest.java') diff --git a/calculator-java/src/test/java/ExpressionParserTest.java b/calculator-java/src/test/java/ExpressionParserTest.java deleted file mode 100644 index b15e844..0000000 --- a/calculator-java/src/test/java/ExpressionParserTest.java +++ /dev/null @@ -1,115 +0,0 @@ -import ch.bfh.CalculatorLexer; -import ch.bfh.parser.ExpressionParser; -import org.junit.Test; -import static org.junit.Assert.assertEquals; - -public class ExpressionParserTest { - - // Only testing correct expressions first - @Test - public void emptyExpression() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer(""); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(0.0, ep.getValue(), 0.0); - } - - @Test - public void oneFactor() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("10"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(10.0, ep.getValue(), 0.0); - } - - @Test - public void oneParenthesisedFactor() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("(10)"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(10.0, ep.getValue(), 0.0); - } - - @Test - public void oneNegativeFactor() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("-10"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(-10.0, ep.getValue(), 0.0); - } - - @Test - public void oneNegativeParenthesisedFactor() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("-(10)"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(-10.0, ep.getValue(), 0.0); - } - - @Test - public void oneNegativeParenthesisedNegativeFactor() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("-(-10)"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(10.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorSum() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("2+3"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(5.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorSub() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("2-3"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(-1.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorSumWithSub() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("2--3"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(5.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorSumWithSubParenthesised() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("2-(-3)"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(5.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorMul() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("2*3"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(6.0, ep.getValue(), 0.0); - } - - @Test - public void twoFactorDiv() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("11/4"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(2.75, ep.getValue(), 0.0); - } - - @Test - public void completeArithmeticOperationWithPriorities() { - CalculatorLexer cl = new CalculatorLexer(); - cl.initLexer("(4+5)*3/4"); - ExpressionParser ep = new ExpressionParser(cl); - assertEquals(6.75, ep.getValue(), 0.0); - } - - //TODO - test error detection - -} -- cgit v1.2.3