summaryrefslogtreecommitdiff
path: root/chapter11/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'chapter11/src/test/java')
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter01Test.java58
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter02Test.java35
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter03Test.java8
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter04Test.java12
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter05Test.java14
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter06Test.java2
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter07Test.java5
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/Chapter08Test.java1
-rw-r--r--chapter11/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java8
9 files changed, 69 insertions, 74 deletions
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter01Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter01Test.java
index 81b0d173..c10dc510 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter01Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter01Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -16,7 +14,7 @@ public class Chapter01Test {
StopNode stop = parser.parse();
StartNode start = Parser.START;
ReturnNode ret = (ReturnNode)stop.in(0);
-
+
assertTrue(ret.ctrl() instanceof CProjNode);
Node expr = ret.expr();
if( expr instanceof ConstantNode con ) {
@@ -37,14 +35,66 @@ public class Chapter01Test {
assertEquals(TypeInteger.constant(0),con._type);
}
+ @Test
+ public void testBad1() {
+ try {
+ new Parser("ret").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Undefined name 'ret'",e.getMessage());
+ }
+ }
@Test
public void testBad2() {
- try {
+ try {
new Parser("return 0123;").parse();
fail();
} catch( RuntimeException e ) {
assertEquals("Syntax error: integer values cannot start with '0'",e.getMessage());
}
}
+
+ @Test
+ public void testNotBad3() {
+ // this test used to fail in chapter 1
+ assertEquals("return 12;", new Parser("return --12;").parse().print());
+ }
+
+ @Test
+ public void testBad4() {
+ try {
+ new Parser("return 100").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Syntax error, expected ;: ",e.getMessage());
+ }
+ }
+
+ @Test
+ public void testNotBad5() {
+ // this test used to fail in chapter 1
+ assertEquals("return -100;", new Parser("return -100;").parse().print());
+ }
+
+ @Test
+ public void testBad6() {
+ try {
+ new Parser("return100").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Undefined name 'return100'",e.getMessage());
+ }
+ }
+
+ @Test
+ public void testBad7() {
+ try {
+ new Parser("return 1;}").parse();
+ fail();
+ } catch( RuntimeException e ) {
+ assertEquals("Syntax error, unexpected }",e.getMessage());
+ }
+ }
+
}
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter02Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter02Test.java
index 351cdb16..2deba460 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter02Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter02Test.java
@@ -2,14 +2,12 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
public class Chapter02Test {
-
+
@Test
public void testParseGrammar() {
Parser parser = new Parser("return 1+2*3+-5;");
@@ -64,36 +62,5 @@ public class Chapter02Test {
GraphVisualizer gv = new GraphVisualizer();
System.out.println(gv.generateDotOutput(parser));
}
-
- @Test
- public void testBad1() {
- try {
- new Parser("ret").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Undefined name 'ret'",e.getMessage());
- }
- }
- @Test
- public void testNotBad3() {
- // this test used to fail in chapter 1
- assertEquals("return 12;", new Parser("return --12;").parse().print());
- }
-
- @Test
- public void testBad4() {
- try {
- new Parser("return 100").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Syntax error, expected ;: ",e.getMessage());
- }
- }
-
- @Test
- public void testNotBad5() {
- // this test used to fail in chapter 1
- assertEquals("return -100;", new Parser("return -100;").parse().print());
- }
}
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter03Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter03Test.java
index 8a11107d..407fbe48 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter03Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter03Test.java
@@ -2,14 +2,12 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
public class Chapter03Test {
-
+
@Test
public void testVarDecl() {
Parser parser = new Parser("int a=1; return a;");
@@ -49,7 +47,7 @@ public class Chapter03Test {
@Test
public void testSelfAssign() {
- try {
+ try {
new Parser("int a=a; return a;").parse();
fail();
} catch( RuntimeException e ) {
@@ -58,7 +56,7 @@ public class Chapter03Test {
}
@Test
- public void testBad6() {
+ public void testBad1() {
try {
new Parser("int a=1; int b=2; int c=0; { int b=3; c=a+b;").parse();
fail();
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter04Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter04Test.java
index 57d464ef..317fe677 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter04Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter04Test.java
@@ -2,14 +2,12 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
public class Chapter04Test {
-
+
@Test
public void testPeephole() {
Parser parser = new Parser("return 1+arg+2; #showGraph;");
@@ -37,7 +35,7 @@ public class Chapter04Test {
StopNode ret = parser.parse();
assertEquals("return (arg*2);", ret.print());
}
-
+
@Test
public void testPeephole3() {
Parser parser = new Parser("return 1+arg+2+arg+3; #showGraph;");
@@ -51,7 +49,7 @@ public class Chapter04Test {
StopNode ret = parser.parse();
assertEquals("return arg;", ret.print());
}
-
+
@Test
public void testVarArg() {
Parser parser = new Parser("return arg; #showGraph;");
@@ -112,7 +110,7 @@ public class Chapter04Test {
@Test
public void testBug3() {
- try {
+ try {
new Parser("inta=1; return a;").parse();
fail();
} catch( RuntimeException e ) {
@@ -126,5 +124,5 @@ public class Chapter04Test {
StopNode ret = parser.parse();
assertEquals("return (-arg);", ret.print());
}
-
+
}
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter05Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter05Test.java
index 2c17113e..64f3a1d9 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter05Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter05Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
@@ -203,7 +201,7 @@ return a;""");
}
@Test
- public void testKeyword3() {
+ public void testKeyword3() {
try {
new Parser("int a=1; ififif(arg)inta=2;return a;").parse();
fail();
@@ -212,14 +210,4 @@ return a;""");
}
}
- @Test
- public void testBad7() {
- try {
- new Parser("return 1;}").parse();
- fail();
- } catch( RuntimeException e ) {
- assertEquals("Syntax error, unexpected }",e.getMessage());
- }
- }
-
}
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter06Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter06Test.java
index 5e823f5d..fed34465 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter06Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter06Test.java
@@ -2,9 +2,7 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter07Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter07Test.java
index 0685f6f9..f9251be7 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter07Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter07Test.java
@@ -2,15 +2,12 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
-import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
public class Chapter07Test {
-
@Test
public void testExample() {
Parser parser = new Parser(
@@ -47,7 +44,6 @@ return a;
@Test
public void testWhileNested() {
Parser parser = new Parser(
-
"""
int sum = 0;
int i = 0;
@@ -240,4 +236,5 @@ return a;
assertEquals("return Phi(Loop10,1,(Phi_a+3));", stop.toString());
assertTrue(stop.ret().ctrl() instanceof CProjNode);
}
+
}
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/Chapter08Test.java b/chapter11/src/test/java/com/seaofnodes/simple/Chapter08Test.java
index 82b04c60..730da36a 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/Chapter08Test.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/Chapter08Test.java
@@ -5,7 +5,6 @@ import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.type.TypeInteger;
import org.junit.Assert;
import org.junit.Test;
-import org.junit.Ignore;
import static org.junit.Assert.*;
diff --git a/chapter11/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java b/chapter11/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
index 29a6853c..51e39cd0 100644
--- a/chapter11/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
+++ b/chapter11/src/test/java/com/seaofnodes/simple/fuzzer/Fuzzer.java
@@ -134,16 +134,16 @@ public class Fuzzer {
new ScriptGenerator(rand, sb, true).genProgram();
try {
var parser = new Parser(sb.toString());
-
+
var stop = parser.parse();
int parse_peeps= Node.ITER_CNT;
int parse_nops = Node.ITER_NOP_CNT;
double parse_nop_ratio = (double)parse_nops/parse_peeps;
int nids = Node.UID();
if( nids <= max_nids ) return max_nids;
-
+
double parse_peeps_per_node = (double)parse_peeps/nids;
-
+
stop.iterate();
int iter_peeps= Node.ITER_CNT;
int iter_nops = Node.ITER_NOP_CNT;
@@ -174,7 +174,7 @@ public class Fuzzer {
check(sb.toString(), valid, seed);
}
-
+
/**
* Check that no exceptions happened.
* @return true if no exception happened