summaryrefslogtreecommitdiff
path: root/chapter32/src/test
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-11-16 15:45:47 -0800
committerCliff Click <cliffc@acm.org>2026-11-16 15:45:47 -0800
commit650f541f976c03e22a4bc93bb9b09d81a7f810ba (patch)
tree082ceafa0e11a9688b5db69c94b1f2d9fb6785dc /chapter32/src/test
parent0dcd3513a633479ce228f24826db4f09e4c0fc8b (diff)
downloadSimple-650f541f976c03e22a4bc93bb9b09d81a7f810ba.tar.gz
Simple-650f541f976c03e22a4bc93bb9b09d81a7f810ba.zip
Another round of test speedup
More TestType lattice test speedups. Collapse together some expensive tests. Trim some tests from `sanity` target
Diffstat (limited to 'chapter32/src/test')
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java28
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/ModTest.java27
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java113
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java2
-rw-r--r--chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java81
5 files changed, 164 insertions, 87 deletions
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
index 0e4c230a..5399aecf 100644
--- a/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
+++ b/chapter32/src/test/java/com/seaofnodes/simple/AssemblyDumpTest.java
@@ -13,25 +13,39 @@ public class AssemblyDumpTest {
@Test public void libraryUnitsAndGlyphs() throws Exception {
Path root=Path.of("build/objs/assembly-dump");
Files.createDirectories(root);
- Path build=Files.createTempDirectory(root,"sys-");
- CodeGen code=new CodeGen("src/main/smp",build.toString(),null,"sys",null,123,true,TypeInteger.BOT)
+ Path fixture=Files.createTempDirectory(root,"font-");
+ Path source=Files.createDirectories(fixture.resolve("src"));
+ Path build=Files.createDirectories(fixture.resolve("obj"));
+ Files.createDirectories(source.resolve("Atlas"));
+ // Use the real font, but only two tiny modules: drawing integration is
+ // covered by DrawTest. This test needs multiple units and constant data.
+ String canvasSource=Files.readString(Path.of("src/main/smp/sys/draw/Canvas.smp"));
+ int fontStart=canvasSource.indexOf("val _glyphs =");
+ assertTrue("Font declaration",fontStart>=0);
+ int fontEnd=canvasSource.indexOf("};",fontStart);
+ assertTrue("Font initializer",fontEnd>=0);
+ Files.writeString(source.resolve("Atlas/Font.smp"),canvasSource.substring(fontStart,fontEnd+2)+
+ "\nval glyph={int i -> _glyphs[i];};\n");
+ Files.writeString(source.resolve("Atlas.smp"),"val glyph={int i -> Font.glyph(i);};\n");
+ CodeGen code=new CodeGen(source.toString(),build.toString(),null,"Atlas",null,123,true,TypeInteger.BOT)
.driver(CodeGen.Phase.Serialize,TestC.CPU_PORT,TestC.CALL_CONVENTION)
.driver(CodeGen.Phase.Encoding,TestC.CPU_PORT,TestC.CALL_CONVENTION);
var entry=code._encoding;
String before=code.asm();
assertSame("Dumping another unit must not change the active encoding",entry,code._encoding);
+ assertEquals(2,code._compunits.size());
for( var unit : code._compunits.values() )
if( unit._src!=null ) {
String heading="=== Compilation unit: "+unit._cname+" ===";
assertEquals("Exactly one heading for "+unit._cname,2,before.split(heading,-1).length);
}
- int start=before.indexOf("=== Compilation unit: sys.draw.Canvas ===");
+ int start=before.indexOf("=== Compilation unit: Atlas.Font ===");
assertTrue(start>=0);
int end=before.indexOf("=== Compilation unit:",start+1);
String canvas=before.substring(start,end<0 ? before.length() : end);
assertTrue(canvas.contains("Constant Pool"));
- assertTrue(canvas.contains("sys.draw.Canvas._glyphs: []u16"));
- TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("sys/draw/Canvas")._clz.field("_glyphs")._t;
+ assertTrue(canvas.contains("Atlas.Font._glyphs: []u16"));
+ TypeMemPtr ptr=(TypeMemPtr)code._compunits.get("Atlas/Font")._clz.field("_glyphs")._t;
TypeConAry glyphs=(TypeConAry)ptr._obj.field("[]")._t;
assertEquals(96,glyphs.len());
BAOS bytes=new BAOS();
@@ -40,10 +54,10 @@ public class AssemblyDumpTest {
canvas.contains("60000000"+HexFormat.of().formatHex(bytes.toByteArray())));
code.exportELF(false,false);
com.seaofnodes.simple.codegen.PrintRegTestSupport.checkDataAliases(
- build.resolve("sys/draw/Canvas.o"),196,"sys.draw.Canvas._glyphs");
+ build.resolve("Atlas/Font.o"),196,"Atlas.Font._glyphs");
assertSame(entry,code._encoding);
assertEquals("Export must not truncate the dump to its entry unit",before,code.asm());
- Files.writeString(build.resolve("sys.asm"),before);
+ Files.writeString(build.resolve("Atlas.asm"),before);
}
@Test public void combinedEncodingAndEarlierPhase() {
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java b/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java
index 7f79599d..c06e99f1 100644
--- a/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java
+++ b/chapter32/src/test/java/com/seaofnodes/simple/ModTest.java
@@ -166,20 +166,31 @@ public class ModTest {
return integerEdges(new long[]{Long.MIN_VALUE,Long.MIN_VALUE+1,-17,-5,-1,0,1,5,17,Long.MAX_VALUE});
}
private static String integerEdges(long[] values) {
+ // Keep the full value matrix in data, rather than compiling a long
+ // chain of constant calls and conditional returns for every pair.
StringBuilder source=new StringBuilder("""
val rem_noInline={ i64 x,i64 y -> x%y; };
val div_noInline={ i64 x,i64 y -> x/y; };
val main={ ->
+ val values=new i64[~]{
""");
- int failure=1;
- for( long x : values )
- for( long y : values ) {
- source.append("if(rem_noInline(").append(literal(x)).append(',').append(literal(y))
- .append(")!=").append(literal(y==0 ? 0 : x%y)).append(") return ").append(failure++).append(';');
- source.append("if(div_noInline(").append(literal(x)).append(',').append(literal(y))
- .append(")!=").append(literal(y==0 ? 0 : x/y)).append(") return ").append(failure++).append(';');
+ for(int i=0;i<values.length;i++) source.append(i==0 ? "" : ",").append(literal(values[i]));
+ source.append("}; val expectedRem=new i64[~]{");
+ int n=0;
+ for(long x:values) for(long y:values) source.append(n++==0 ? "" : ",").append(literal(y==0 ? 0 : x%y));
+ source.append("}; val expectedDiv=new i64[~]{");
+ n=0;
+ for(long x:values) for(long y:values) source.append(n++==0 ? "" : ",").append(literal(y==0 ? 0 : x/y));
+ return source.append("""
+ };
+ int index=0;
+ for(int i=0;i<values#;i++) for(int j=0;j<values#;j++) {
+ if(rem_noInline(values[i],values[j])!=expectedRem[index]) return index*2+1;
+ if(div_noInline(values[i],values[j])!=expectedDiv[index]) return index*2+2;
+ index++;
}
- return source.append("return 0; };").toString();
+ return 0; };
+ """).toString();
}
@Test public void nativeFloatingEdges() throws Exception {
double[][] cases={{Double.MAX_VALUE,0.1},{-Double.MAX_VALUE,0.1},
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java b/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java
index 59b62709..d6783380 100644
--- a/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java
+++ b/chapter32/src/test/java/com/seaofnodes/simple/StringFormatTest.java
@@ -11,28 +11,88 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class StringFormatTest extends TestC {
- private static void prints(String body, String expected) throws Exception {
- runSYS("val main={ -> "+body+" return 0; };", "stringFormat",expected,-1);
+ // Share a few native programs, retaining a separately reported assertion
+ // for each case. Blocks isolate locals; the delimiter preserves embedded
+ // NULs and newlines in the expected output.
+ private enum Format {
+ DefaultsAndNestedStrings("sys.io.p(\"CPU plays %(2+3). %(\"nested %(7)\") %(true) %(1.5)\\n\");",
+ "CPU plays 5. nested 7 1 1.5\n"),
+ Formats("sys.io.p(\"%+06d(17)|%#08x(42)|%-5.3s(\"abcdef\")|%.2f(1.25)|%c(65)|%b(false)\\n\");",
+ "+00017|0x00002a|abc |1.25|A|false\n"),
+ RemainderInInterpolation("int mod=17; sys.io.p(\"%(mod%5)|%02d(mod%5)|%%|\\%|%(mod %= 5)|%(mod)\");",
+ "2|02|%|%|2|2"),
+ IntegerLimits("i64 lo=-9223372036854775807-1; sys.io.p(\"%(lo)|%(9223372036854775807)|%u(-1)|%X(-1)\");",
+ "-9223372036854775808|9223372036854775807|18446744073709551615|FFFFFFFFFFFFFFFF"),
+ IntegerPaddingRules("sys.io.p(\"%#.0o(0)|%#.3o(1)|%#x(0)|%-08d(17)|%08.4d(-17)|%+d(0)|% d(0)\");",
+ "0|001|0|17 | -0017|+0| 0"),
+ BuilderNumberUsesFormatter("val b=new sys.aryu8(); b.num(-9223372036854775807-1).add('|').num(9223372036854775807); sys.io.p(sys.text.end(b));",
+ "-9223372036854775808|9223372036854775807"),
+ EvaluationOrder("int x=0; val s=\"%(x++)%(x++)%(x++)\"; sys.io.p(\"%(s):%(s#):%(x)|%%|\\%\");",
+ "012:3:3|%|%"),
+ EvaluationMutatesBytes("val a=new u8[1]; a[0]='A'; sys.io.p(\"%(a)%(a[0]='B')%(a)\");", "A66B"),
+ Converters("sys.io.p(sys.text.int(17)); sys.io.p(sys.text.char(65)); sys.io.p(sys.text.bool(true)); sys.io.p(sys.text.flt(1.5));",
+ "17Atrue1.5"),
+ FieldNamedInt("struct S { int int=7; }; sys.io.p(\"%((new S).int)\");", "7"),
+ FloatAndAlternateFormats("f32 x=1.25f; sys.io.p(\"%(x)|%f(x)|%.2e(x)|%.2G(x)|%#o(9)|% d(7)|%.0d(0)|%a(1.5)\");",
+ "1.25|1.250000|1.25e+00|1.2|011| 7||0x1.8p+0"),
+ BufferGrowth("sys.io.p(\"%0100d(17)|%.100f(1.0)\");", "0".repeat(98)+"17|1."+"0".repeat(100)),
+ BytesAndEmptyStrings("val empty=\"%(\"\")\"; val bytes=\"a\\0b\"; sys.io.p(\"%(empty#):%s(bytes):%.2s(bytes):%c(0)\");",
+ "0:a\0b:a\0:\0"),
+ Utf8String("val s=\"π\"; sys.io.p(\"%(s):%(s#):%(s[0]):π\");", "π:2:207:π"),
+ DeferredParsing("""
+ struct S { u8[~] s; new S={ -> s="%("}) %(3)")"; }; };
+ val s=new S;
+ sys.io.p(s.s);
+ for(int i=0; i<2; sys.io.p("%(i++) %("(")")) { }
+ """, "}) 30 (1 (");
+
+ final String body, expected;
+ Format(String body, String expected) { this.body=body; this.expected=expected; }
+ }
+ private static final String END="\n--end-format-case--\n";
+ private static final int BATCH_SIZE=5;
+ private static final String[] OUTPUTS=new String[Format.values().length];
+
+ @org.junit.BeforeClass public static void resetNativeBatches() {
+ java.util.Arrays.fill(OUTPUTS,null);
+ }
+
+ private static void prints(Format test) throws Exception {
+ int index=test.ordinal();
+ if( OUTPUTS[index]==null ) {
+ Format[] cases=Format.values();
+ int first=index/BATCH_SIZE*BATCH_SIZE, limit=Math.min(first+BATCH_SIZE,cases.length);
+ StringBuilder source=new StringBuilder("val main={ -> ");
+ for( int i=first; i<limit; i++ ) {
+ assertFalse("Reserved batch delimiter",cases[i].expected.contains(END));
+ source.append('{').append(cases[i].body).append('}');
+ source.append("sys.io.p(\"\\n--end-format-case--\\n\");");
+ }
+ source.append("return 0; };");
+ String exe=compile(source.toString(),"stringFormat"+first,
+ new Ary<>(new String[]{RELEASE_SYS_DIR}),CALL_CONVENTION,null,null,-1);
+ String[] outputs=exec(TEST_TIMEOUT_SECONDS,exe).split(java.util.regex.Pattern.quote(END),-1);
+ assertEquals("Each format case must complete",limit-first+1,outputs.length);
+ assertEquals("No output after final case", "",outputs[outputs.length-1]);
+ for( int i=first; i<limit; i++ ) OUTPUTS[i]=outputs[i-first];
+ }
+ assertEquals(test.name(),test.expected,OUTPUTS[index]);
}
@Test public void testDefaultsAndNestedStrings() throws Exception {
- prints("sys.io.p(\"CPU plays %(2+3). %(\"nested %(7)\") %(true) %(1.5)\\n\");",
- "CPU plays 5. nested 7 1 1.5\n");
+ prints(Format.DefaultsAndNestedStrings);
}
@Test public void testFormats() throws Exception {
- prints("sys.io.p(\"%+06d(17)|%#08x(42)|%-5.3s(\"abcdef\")|%.2f(1.25)|%c(65)|%b(false)\\n\");",
- "+00017|0x00002a|abc |1.25|A|false\n");
+ prints(Format.Formats);
}
@Test public void testRemainderInInterpolation() throws Exception {
- prints("int mod=17; sys.io.p(\"%(mod%5)|%02d(mod%5)|%%|\\%|%(mod %= 5)|%(mod)\");",
- "2|02|%|%|2|2");
+ prints(Format.RemainderInInterpolation);
}
@Test public void testIntegerLimits() throws Exception {
- prints("i64 lo=-9223372036854775807-1; sys.io.p(\"%(lo)|%(9223372036854775807)|%u(-1)|%X(-1)\");",
- "-9223372036854775808|9223372036854775807|18446744073709551615|FFFFFFFFFFFFFFFF");
+ prints(Format.IntegerLimits);
}
@Test public void testSignedAndUnsignedRadices() throws Exception {
@@ -49,13 +109,11 @@ public class StringFormatTest extends TestC {
}
@Test public void testIntegerPaddingRules() throws Exception {
- prints("sys.io.p(\"%#.0o(0)|%#.3o(1)|%#x(0)|%-08d(17)|%08.4d(-17)|%+d(0)|% d(0)\");",
- "0|001|0|17 | -0017|+0| 0");
+ prints(Format.IntegerPaddingRules);
}
@Test public void testBuilderNumberUsesFormatter() throws Exception {
- prints("val b=new sys.aryu8(); b.num(-9223372036854775807-1).add('|').num(9223372036854775807); sys.io.p(sys.text.end(b));",
- "-9223372036854775808|9223372036854775807");
+ prints(Format.BuilderNumberUsesFormatter);
}
@Test public void testFormattingInEvaluatorFromSource() {
@@ -74,15 +132,13 @@ public class StringFormatTest extends TestC {
}
@Test public void testEvaluationOrderAndLength() throws Exception {
- prints("int x=0; val s=\"%(x++)%(x++)%(x++)\"; sys.io.p(\"%(s):%(s#):%(x)|%%|\\%\");",
- "012:3:3|%|%");
- prints("val a=new u8[1]; a[0]='A'; sys.io.p(\"%(a)%(a[0]='B')%(a)\");", "A66B");
+ prints(Format.EvaluationOrder);
+ prints(Format.EvaluationMutatesBytes);
}
@Test public void testConverters() throws Exception {
- prints("sys.io.p(sys.text.int(17)); sys.io.p(sys.text.char(65)); sys.io.p(sys.text.bool(true)); sys.io.p(sys.text.flt(1.5));",
- "17Atrue1.5");
- prints("struct S { int int=7; }; sys.io.p(\"%((new S).int)\");", "7");
+ prints(Format.Converters);
+ prints(Format.FieldNamedInt);
}
@Test public void testForwardReturnTypes() throws Exception {
@@ -91,14 +147,13 @@ public class StringFormatTest extends TestC {
}
@Test public void testFloatAndAlternateFormats() throws Exception {
- prints("f32 x=1.25f; sys.io.p(\"%(x)|%f(x)|%.2e(x)|%.2G(x)|%#o(9)|% d(7)|%.0d(0)|%a(1.5)\");",
- "1.25|1.250000|1.25e+00|1.2|011| 7||0x1.8p+0");
+ prints(Format.FloatAndAlternateFormats);
runSYS("val format_noInline={ f32 x -> \"%(x)|%f(x)\"; }; val main={ -> sys.io.p(format_noInline(1.25f)); return 0; };",
"stringFormatFloat","1.25|1.250000",-1);
}
@Test public void testBufferGrowth() throws Exception {
- prints("sys.io.p(\"%0100d(17)|%.100f(1.0)\");", "0".repeat(98)+"17|1."+"0".repeat(100));
+ prints(Format.BufferGrowth);
}
@Test public void testLiteralRemainsConstant() {
@@ -107,18 +162,12 @@ public class StringFormatTest extends TestC {
}
@Test public void testBytesAndEmptyStrings() throws Exception {
- prints("val empty=\"%(\"\")\"; val bytes=\"a\\0b\"; sys.io.p(\"%(empty#):%s(bytes):%.2s(bytes):%c(0)\");",
- "0:a\0b:a\0:\0");
- prints("val s=\"π\"; sys.io.p(\"%(s):%(s#):%(s[0]):π\");", "π:2:207:π");
+ prints(Format.BytesAndEmptyStrings);
+ prints(Format.Utf8String);
}
@Test public void testDeferredParsing() throws Exception {
- prints("""
- struct S { u8[~] s; new S={ -> s="%("}) %(3)")"; }; };
- val s=new S;
- sys.io.p(s.s);
- for(int i=0; i<2; sys.io.p("%(i++) %("(")")) { }
- """, "}) 30 (1 (");
+ prints(Format.DeferredParsing);
}
@Test public void testImportedFormatter() throws Exception {
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java b/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java
index 30cff89f..d875c47a 100644
--- a/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java
+++ b/chapter32/src/test/java/com/seaofnodes/simple/TestWorkspace.java
@@ -7,7 +7,7 @@ import java.nio.file.attribute.BasicFileAttributes;
/** Prepare a Make test group's working directory without sharing native outputs. */
public class TestWorkspace {
public static void main(String[] args) throws IOException {
- if( args.length!=2 || !args[0].matches("tests_group[0-7]") || !args[1].matches("[A-Za-z0-9_]+") )
+ if( args.length!=2 || !args[0].matches("tests_group[0-7]|sanity_group[0-2]") || !args[1].matches("[A-Za-z0-9_]+") )
throw new IllegalArgumentException("Expected test group and CPU_ABI");
Path root = Path.of("").toAbsolutePath().normalize();
Path work = root.resolve("build/tests").resolve(args[0]).normalize();
diff --git a/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java
index 8f212bda..adcc1b3a 100644
--- a/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java
+++ b/chapter32/src/test/java/com/seaofnodes/simple/TypeTest.java
@@ -276,74 +276,77 @@ public class TypeTest {
public void testLatticeTheory() {
Type[] ts = Type.gather();
// Make partitions the outer loop between independent JVMs. A direct
- // JUnit/IDE invocation retains the full Cartesian-product coverage.
+ // JUnit/IDE invocation retains the full coverage.
int parts = Integer.parseInt(System.getProperty("simple.lattice.parts","1"));
int part = Integer.parseInt(System.getProperty("simple.lattice.part" ,"0"));
Assert.assertTrue("Invalid lattice partition",parts > 0 && parts <= ts.length && part >= 0 && part < parts);
- // Confirm commutative & complete
- for( int i=part; i<ts.length; i+=parts ) {
- Type t0 = ts[i];
- for( Type t1 : ts ) {
- check_commute (t0,t1);
- check_symmetric(t0,t1);
+ // Every triple reuses these pairs. Compute both operand orders rather
+ // than assuming commutativity in the table we are about to check.
+ Type[][] meets = new Type[ts.length][ts.length];
+ Type[][] joins = new Type[ts.length][ts.length];
+ for( int i=0; i<ts.length; i++ )
+ for( int j=0; j<ts.length; j++ ) {
+ meets[i][j] = ts[i].meet(ts[j]);
+ joins[i][j] = ts[i].join(ts[j]);
}
- }
- // Confirm associative
+ // Confirm commutative & complete, once per unordered pair.
for( int i=part; i<ts.length; i+=parts ) {
- Type t0 = ts[i];
- for( Type t1 : ts )
- for( Type t2 : ts )
- assoc(t0,t1,t2);
+ assertSame(ts[i],meets[i][i]);
+ for( int j=i; j<ts.length; j++ ) {
+ assertSame(meets[i][j],meets[j][i]);
+ check_symmetric(ts[i],ts[j],meets[i][j]);
+ }
}
+ // Each unordered triple represents all six permutations. Check every
+ // intermediate result in both operand orders; a pair's meet need not
+ // itself be in ts, so its commutativity must not be assumed.
+ for( int i=part; i<ts.length; i+=parts )
+ for( int j=i; j<ts.length; j++ )
+ for( int k=j; k<ts.length; k++ )
+ assoc(ts[i],ts[j],ts[k],meets[i][j],meets[i][k],meets[j][k]);
+
// Confirm symmetry. If A isa B, then A.join(C) isa B.join(C)
for( int i=part; i<ts.length; i+=parts ) {
Type t0 = ts[i];
- for( Type t1 : ts )
- if( t0.isa(t1) )
- for( Type t2 : ts ) {
- Type t02 = t0.join(t2);
- Type t12 = t1.join(t2);
+ for( int j=0; j<ts.length; j++ )
+ if( meets[i][j]==ts[j] )
+ for( int k=0; k<ts.length; k++ ) {
+ Type t02 = joins[i][k];
+ Type t12 = joins[j][k];
Type mt = t02.meet(t12);
- assertSame(t0+" isa "+t1+" joined "+t2, mt,t12);
+ if( mt!=t12 ) assertSame(t0+" isa "+ts[j]+" joined "+ts[k], mt,t12);
}
}
}
- // By design in meet, args are already flipped to order _type, which forces
- // symmetry for things with badly ordered _type fields. The question is
- // still interesting for other orders.
- private static void check_commute( Type t0, Type t1 ) {
- if( t0==t1 ) return;
- if( t0.is_simple() && !t1.is_simple() ) return; // By design, flipped the only allowed order
- Type mta = t0.meet(t1);
- Type mtb = t1.meet(t0); // Reverse args and try again
- assertSame(mta,mtb);
- }
-
// A & B = MT
// Expect: ~A & ~MT == ~A
// Expect: ~B & ~MT == ~B
private static void check_symmetric( Type t0, Type t1 ) {
+ check_symmetric(t0,t1,t0.meet(t1));
+ }
+
+ private static void check_symmetric( Type t0, Type t1, Type mt ) {
if( t1==t0 ) return;
- Type mt = t0.meet(t1);
Type dm = mt.dual();
Type d0 = t0.dual();
Type d1 = t1.dual();
Type ta = dm.meet(d1);
Type tb = dm.meet(d0);
- assertSame(t0+" & "+t1+" mt="+mt, ta,d1);
- assertSame(t0+" & "+t1+" mt="+mt, tb,d0);
+ if( ta!=d1 ) assertSame(t0+" & "+t1+" mt="+mt, ta,d1);
+ if( tb!=d0 ) assertSame(t0+" & "+t1+" mt="+mt, tb,d0);
}
- private static void assoc( Type t0, Type t1, Type t2 ) {
- Type t01 = t0 .meet(t1 );
- Type t12 = t1 .meet(t2 );
- Type t01_2 = t01.meet(t2 );
- Type t0_12 = t0 .meet(t12);
- assertSame(t0+" & "+t1+" & "+t2, t01_2,t0_12);
+ private static void assoc( Type a, Type b, Type c, Type ab, Type ac, Type bc ) {
+ // The six original associativity equalities connect these six values
+ // in a cycle. Equality to one common result checks the same property.
+ Type result = ab.meet(c);
+ if( result!=c.meet(ab) || result!=ac.meet(b) || result!=b.meet(ac) ||
+ result!=bc.meet(a) || result!=a.meet(bc) )
+ Assert.fail("Associativity: "+a+" & "+b+" & "+c);
}
// Test cyclic types and meets