diff options
| author | Cliff Click <cliffc@acm.org> | 2024-10-04 14:18:47 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-10-06 08:56:22 -0700 |
| commit | 162558e68e0f8c83ad42a2c1bc676ae0eef2464c (patch) | |
| tree | e42b629f6725d753993450c69b046e0bb70ea92a /chapter15/src/test/java/com/seaofnodes | |
| parent | a417a50f8f7fefbd40bb39866b8d7db2cbd691c2 (diff) | |
| download | Simple-162558e68e0f8c83ad42a2c1bc676ae0eef2464c.tar.gz Simple-162558e68e0f8c83ad42a2c1bc676ae0eef2464c.zip | |
Force arrays to have a safety check
Improves BrainFuck
Diffstat (limited to 'chapter15/src/test/java/com/seaofnodes')
| -rw-r--r-- | chapter15/src/test/java/com/seaofnodes/simple/BrainFuckTest.java | 4 | ||||
| -rw-r--r-- | chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/chapter15/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter15/src/test/java/com/seaofnodes/simple/BrainFuckTest.java index 894abbf6..03a22c55 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/BrainFuckTest.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/BrainFuckTest.java @@ -26,7 +26,7 @@ public class BrainFuckTest { encoded + """ int pc = 0; int d = 0; -u8[] data = new u8[10000]; +u8[] data = new u8[100]; int i=0; while(i < data#) { data[i] = 0; @@ -92,6 +92,6 @@ return result; for (byte b : "Hello Wo".getBytes(StandardCharsets.UTF_8)) { expected = (expected << 8) | b; } - assertEquals(expected, Evaluator.evaluate(stop, 0, 100000)); + assertEquals(expected, Evaluator.evaluate(stop, 0, 10000)); } } diff --git a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java index 1aee2f0d..266d8a47 100644 --- a/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java +++ b/chapter15/src/test/java/com/seaofnodes/simple/Chapter15Test.java @@ -24,6 +24,25 @@ return 3.14; } @Test + public void testSafetyCheck() { + Parser parser = new Parser( +""" +u8[] old = new u8[0]; +u8[] output = new u8[1]; +int i = 0; +while (i < old#) { + output[i] = old[i]; + i = i + 1; +} +output[i] = 1; +return output; +"""); + StopNode stop = parser.parse(false).iterate(true); + assertEquals("return u8[];", stop.toString()); + assertEquals("Obj<u8[]> {\n #=1\n []=1\n}", Evaluator.evaluate(stop, 0).toString()); + } + + @Test public void testBasic1() { Parser parser = new Parser( """ |
