summaryrefslogtreecommitdiff
path: root/chapter17/src/test/java/com/seaofnodes
diff options
context:
space:
mode:
Diffstat (limited to 'chapter17/src/test/java/com/seaofnodes')
-rw-r--r--chapter17/src/test/java/com/seaofnodes/simple/BrainFuckTest.java6
-rw-r--r--chapter17/src/test/java/com/seaofnodes/simple/Chapter08Test.java2
-rw-r--r--chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java2
-rw-r--r--chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java12
4 files changed, 16 insertions, 6 deletions
diff --git a/chapter17/src/test/java/com/seaofnodes/simple/BrainFuckTest.java b/chapter17/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
index 28c3477c..0c2509bf 100644
--- a/chapter17/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
+++ b/chapter17/src/test/java/com/seaofnodes/simple/BrainFuckTest.java
@@ -48,8 +48,7 @@ for( int pc = 0; pc < program#; pc++ ) {
} else if (command == 91) {
if (data[d] == 0) {
for( var d = 1; d > 0; ) {
- pc++;
- command = program[pc];
+ command = program[++pc];
if (command == 91) d++;
if (command == 93) d--;
}
@@ -57,8 +56,7 @@ for( int pc = 0; pc < program#; pc++ ) {
} else if (command == 93) {
if (data[d]) {
for( var d = 1; d > 0; ) {
- pc--;
- command = program[pc];
+ command = program[--pc];
if (command == 93) d++;
if (command == 91) d--;
}
diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 29fd09dc..bb3bd674 100644
--- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -138,7 +138,7 @@ return arg;
@Test
public void testRegress2() {
- Parser parser = new Parser("if(1) return 0; else while(arg>--arg) arg=arg+1; return 0;");
+ Parser parser = new Parser("if(1) return 0; else while(arg>- -arg) arg=arg+1; return 0;");
StopNode stop = parser.parse().iterate();
assertEquals("return 0;", stop.toString());
}
diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java
index 11424720..ddcc9e63 100644
--- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java
+++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter11Test.java
@@ -292,7 +292,7 @@ else {
}
""");
StopNode stop = parser.parse().iterate();
- assertEquals("Stop[ return 9; return 0; return 0; ]", stop.toString());
+ assertEquals("Stop[ return 9; return 0; return 0; return 0; return 0; return 0; return 0; return 0; ]", stop.toString());
}
diff --git a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java
index d39cee2d..3773f87f 100644
--- a/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java
+++ b/chapter17/src/test/java/com/seaofnodes/simple/Chapter17Test.java
@@ -3,6 +3,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.evaluator.Evaluator;
import com.seaofnodes.simple.node.StopNode;
import org.junit.Test;
+import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -88,6 +89,17 @@ return s.x;
}
@Test
+ public void testInc6() {
+ Parser parser = new Parser("""
+return --arg;
+""");
+ StopNode stop = parser.parse().iterate();
+ assertEquals("return (arg+-1);", stop.toString());
+ assertEquals(-1L, Evaluator.evaluate(stop, 0));
+ }
+
+
+ @Test
public void testVar0() {
Parser parser = new Parser("""
var d;