summaryrefslogtreecommitdiff
path: root/chapter12/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter12/src/test/java')
-rw-r--r--chapter12/src/test/java/com/seaofnodes/simple/Chapter04Test.java28
-rw-r--r--chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java7
2 files changed, 35 insertions, 0 deletions
diff --git a/chapter12/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter12/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index 80cdb3f2..a3109ff7 100644
--- a/chapter12/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/chapter12/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -51,6 +51,34 @@ public class Chapter04Test {
}
@Test
+ public void testSub0() {
+ Parser parser = new Parser("return arg-0;");
+ StopNode ret = parser.parse();
+ assertEquals("return arg;", ret.print());
+ }
+
+ @Test
+ public void test0Sub() {
+ Parser parser = new Parser("return 0-arg;");
+ StopNode ret = parser.parse();
+ assertEquals("return (-arg);", ret.print());
+ }
+
+ @Test
+ public void testSubNeg() {
+ Parser parser = new Parser("return 3--arg;");
+ StopNode ret = parser.parse();
+ assertEquals("return (arg+3);", ret.print());
+ }
+
+ @Test
+ public void testNegSub() {
+ Parser parser = new Parser("return -arg-3;");
+ StopNode ret = parser.parse();
+ assertEquals("return (-(arg+3));", ret.print());
+ }
+
+ @Test
public void testVarArg() {
Parser parser = new Parser("return arg; ");
StopNode stop = parser.parse();
diff --git a/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java b/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
index d862df95..9da4a4b8 100644
--- a/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
+++ b/chapter12/src/test/java/com/seaofnodes/simple/Chapter12Test.java
@@ -9,6 +9,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter12Test {
+ @Test public void testSubZeroFloat() {
+ var stop = new Parser("flt x = arg; return 0-x;").parse().iterate();
+ // Compare strings so +0.0 and -0.0 remain distinct.
+ assertEquals("0.0", Evaluator.evaluate(stop,0).toString());
+ assertEquals("-1.0", Evaluator.evaluate(stop,1).toString());
+ }
+
@Test public void testDeadNumericReturns() {
for( String[] test : new String[][] {
{"if(1) return 7; else return 2.5;", "7"},