summaryrefslogtreecommitdiff
path: root/chapter14/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter14/src/test/java')
-rw-r--r--chapter14/src/test/java/com/seaofnodes/simple/Chapter06Test.java4
-rw-r--r--chapter14/src/test/java/com/seaofnodes/simple/Chapter11Test.java2
-rw-r--r--chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java33
3 files changed, 34 insertions, 5 deletions
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index 472e2db3..cddf0ae2 100644
--- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -27,10 +27,10 @@ return 1;
int a = 1;
if (arg)
a = 2;
-return (arg < a) < 3;
+return (arg < a) < 3; // Because (arg < a) is a bool/uint1/[0-1], its always less than 3
""");
StopNode stop = parser.parse().iterate();
- assertEquals("return ((arg<Phi(Region16,2,1))<3);", stop.toString());
+ assertEquals("return 1;", stop.toString());
}
@Test
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index e367184c..3b9cac7d 100644
--- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -292,7 +292,7 @@ else {
}
""");
StopNode stop = parser.parse(false).iterate(false);
- assertEquals("Stop[ return 9; return 0; return 0; return 0; return 0; ]", stop.toString());
+ assertEquals("Stop[ return 9; return 0; return 0; return 0; ]", stop.toString());
}
diff --git a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java
index e668d48e..4bf04b88 100644
--- a/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java
+++ b/chapter14/src/test/java/com/seaofnodes/simple/Chapter14Test.java
@@ -8,9 +8,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class Chapter14Test {
- // This is a just a copy of a test from ch12 - remove!
+
@Test
- public void testToBeRemoved() {
+ public void testJig() {
Parser parser = new Parser(
"""
return 3.14;
@@ -20,4 +20,33 @@ return 3.14;
assertEquals(3.14, Evaluator.evaluate(stop, 0));
}
+ @Test
+ public void testRange() {
+ Parser parser = new Parser(
+"""
+int b;
+if( arg ) b=1; else b=0;
+int c = 99;
+if( b < 0 ) c = -1;
+if( b > 2 ) c = 1;
+return c;
+""");
+ StopNode stop = parser.parse(false).iterate(false);
+ assertEquals("return 99;", stop.toString());
+ assertEquals(99L, Evaluator.evaluate(stop, 0));
+ }
+
+ @Test
+ public void testU8() {
+ Parser parser = new Parser(
+"""
+u8 b = 123;
+b = b + 456;// Truncate
+return 67;
+""");
+ StopNode stop = parser.parse(false).iterate(false);
+ assertEquals("return 67;", stop.toString());
+ assertEquals(67, Evaluator.evaluate(stop, 0));
+ }
+
}