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/StatementParserTest.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'calculator-java/src/test/java/StatementParserTest.java') diff --git a/calculator-java/src/test/java/StatementParserTest.java b/calculator-java/src/test/java/StatementParserTest.java index 4b2e635..8c2db59 100644 --- a/calculator-java/src/test/java/StatementParserTest.java +++ b/calculator-java/src/test/java/StatementParserTest.java @@ -1,4 +1,3 @@ -import ch.bfh.CalculatorLexer; import ch.bfh.parser.StatementParser; import org.junit.Test; @@ -86,6 +85,41 @@ public class StatementParserTest { assertEquals(6.75, sp.getValue(), 0.0); } + @Test + public void variableTest() { + sp.parseStatement("let a = 5"); + assertEquals(5.0, sp.getValue(), 0.0); + + sp.parseStatement("a"); + assertEquals(5.0, sp.getValue(), 0.0); + + sp.parseStatement("(a)"); + assertEquals(5.0, sp.getValue(), 0.0); + + sp.parseStatement("-a"); + assertEquals(-5.0, sp.getValue(), 0.0); + + sp.parseStatement("-(a)"); + assertEquals(-5.0, sp.getValue(), 0.0); + + sp.parseStatement("-(-a)"); + assertEquals(5.0, sp.getValue(), 0.0); + + sp.parseStatement("let b=5*50"); + assertEquals(250.0, sp.getValue(), 0.0); + + sp.parseStatement("b/a"); + assertEquals(50.0, sp.getValue(), 0.0); + + sp.parseStatement("b+a/2"); + assertEquals(252.5, sp.getValue(), 0.0); + + sp.parseStatement("let z = b+a/2"); + assertEquals(252.5, sp.getValue(), 0.0); + + sp.parseStatement("let a = b+a"); + assertEquals(255.0, sp.getValue(), 0.0); + } //TODO - test error detection } -- cgit v1.2.3