diff options
| author | Cliff Click <cliffc@acm.org> | 2024-08-16 14:34:34 -0700 |
|---|---|---|
| committer | Thalia Archibald <thalia@archibald.dev> | 2024-09-07 10:54:48 -0700 |
| commit | bb4e3e01b5ec1e2cfbd3d6e274750e34542d72f0 (patch) | |
| tree | 15ea2d2e05a11c731cf6324d778d2ecb3bcf9e1e /chapter14/src/test/java | |
| parent | 3a0592837f40ca0ceac82a2f518949f0c9450b90 (diff) | |
| download | Simple-bb4e3e01b5ec1e2cfbd3d6e274750e34542d72f0.tar.gz Simple-bb4e3e01b5ec1e2cfbd3d6e274750e34542d72f0.zip | |
Add TypeInteger ranges
Diffstat (limited to 'chapter14/src/test/java')
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)); + } + } |
