From 0c62c5a642132fc8b2de4905bb4adce31069ece1 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 19 Sep 2026 10:58:24 -0700 Subject: Tighter recursive-struct test --- .../test/java/com/seaofnodes/simple/TypeTest.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'chapter25/src/test/java') diff --git a/chapter25/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter25/src/test/java/com/seaofnodes/simple/TypeTest.java index 65635afe..b83cc9e6 100644 --- a/chapter25/src/test/java/com/seaofnodes/simple/TypeTest.java +++ b/chapter25/src/test/java/com/seaofnodes/simple/TypeTest.java @@ -7,6 +7,27 @@ import static org.junit.Assert.assertSame; public class TypeTest { + // Struct hashes omit field types, so interning compares unlike leaf kinds. + @Test + public void testCyclicLeafKinds() { + TypeStruct bottom = TypeStruct.make("B14LeafKinds",false, + Field.make("x",Type.BOTTOM,2,false)); + TypeStruct one = TypeStruct.make("B14LeafKinds",false, + Field.make("x",TypeFloat.constant(1.0),2,false)); + TypeStruct two = TypeStruct.make("B14LeafKinds",false, + Field.make("x",TypeFloat.constant(2.0),2,false)); + + // Meeting creates a new struct while cyclic equality is active. Its + // float leaf must compare unequal to the previously interned BOTTOM. + TypeStruct meet = (TypeStruct)one.meet(two); + assertSame(TypeFloat.F32,meet._fields[0]._t); + assertSame(meet,two.meet(one)); + assertSame(meet,TypeStruct.make("B14LeafKinds",false, + Field.make("x",TypeFloat.F32,2,false))); + assertSame(bottom,meet.meet(bottom)); + assertSame(meet.dual(),one.dual().join(two.dual())); + } + // Test basic type properties @Test public void testTypeAdHoc() { -- cgit v1.2.3