From e2b042bd9721995486f4f0cf96847c02d27908e3 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 24 Oct 2026 15:26:23 -0700 Subject: Fix chained comparisons and restore recursion coverage --- .../seaofnodes/simple/ChainedComparisonTest.java | 37 ++++++++++++++++++++++ .../java/com/seaofnodes/simple/Chapter18Test.java | 7 ++-- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 chapter28a/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java (limited to 'chapter28a/src/test') diff --git a/chapter28a/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java b/chapter28a/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java new file mode 100644 index 00000000..8db9c024 --- /dev/null +++ b/chapter28a/src/test/java/com/seaofnodes/simple/ChainedComparisonTest.java @@ -0,0 +1,37 @@ +package com.seaofnodes.simple; + +import com.seaofnodes.simple.codegen.CodeGen; +import com.seaofnodes.simple.type.TypeInteger; +import org.junit.Test; +import static org.junit.Assert.*; + +public class ChainedComparisonTest { + @Test public void testAdjacentOperandsAndOperators() { + String[] expressions = {"10 < arg < 20", "0 < arg <= 3", "3 >= arg > 0", + "0 <= arg < 3", "0 < arg <= 3 < 4"}; + String[][] expected = {{"0","0","1","0"}, {"0","1","0","0"}, + {"0","1","0","0"}, {"1","0","0","0"}, + {"0","1","0","0"}}; + int[] args = {0,3,15,30}; + for(int i=0;i 1;").parse(); + fail("mixed directions"); + } catch(RuntimeException e) { + assertEquals("Mixing relational directions in a chained relational test",e.getMessage()); + } + } +} diff --git a/chapter28a/src/test/java/com/seaofnodes/simple/Chapter18Test.java b/chapter28a/src/test/java/com/seaofnodes/simple/Chapter18Test.java index ae1dca5f..632b9539 100644 --- a/chapter28a/src/test/java/com/seaofnodes/simple/Chapter18Test.java +++ b/chapter28a/src/test/java/com/seaofnodes/simple/Chapter18Test.java @@ -436,7 +436,7 @@ return s.x; catch( Exception e ) { assertEquals("Accessing unknown field 'x' from '*Test.S'",e.getMessage()); } } - @Test @Ignore + @Test public void testErr5() { CodeGen code = new CodeGen( """ @@ -450,8 +450,8 @@ return g(); } - // Mutual recursion. Fails without SCCP to lift the recursive return types. - @Ignore @Test + // Mutual recursion: check results, independent of how much gets inlined. + @Test public void testFcnMutRec() { CodeGen code = new CodeGen( """ @@ -460,7 +460,6 @@ val is_odd = { int x -> x ? is_even(x-1) : false; }; return is_even(arg); """); code.driver(CodeGen.Phase.TypeCheck); - assertEquals("Stop[ return #2; return Phi(Region,0,1,#2); ]", code.print()); assertEquals("1", Eval2.eval(code, 0)); assertEquals("0", Eval2.eval(code, 1)); assertEquals("1", Eval2.eval(code, 2)); -- cgit v1.2.3