From 4b9eda962ee0f3d75c21f3322ebe43340b023668 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 14 Apr 2016 14:22:41 +0200 Subject: [PATCH] =?UTF-8?q?Tests=20anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/unify/UnifyTest.java | 74 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/test/unify/UnifyTest.java b/test/unify/UnifyTest.java index ebae5e0a..af6e044f 100644 --- a/test/unify/UnifyTest.java +++ b/test/unify/UnifyTest.java @@ -618,6 +618,15 @@ public class UnifyTest extends TypeUnify { public void unifyTestVoid() { /* * Constraints Set mit "void" Typen + * T1 < Integer + * Integer < Integer + * T1 < T2 + * T3 < Bool + * void < T4 + * OL < Object + * void < void + * ol < T5 + * T5 < ol */ TypeFactory tf = new TypeFactory(); FiniteClosureBuilder fcb = new FiniteClosureBuilder(); @@ -626,7 +635,7 @@ public class UnifyTest extends TypeUnify { UnifyType tphT2 = tf.getPlaceholderType("T2"); UnifyType tphT3 = tf.getPlaceholderType("T3"); UnifyType tphT4 = tf.getPlaceholderType("T4"); - UnifyType tphT5 = tf.getPlaceholderType("T4"); + UnifyType tphT5 = tf.getPlaceholderType("T5"); UnifyType integer = tf.getSimpleType("java.lang.Integer"); UnifyType voidType = tf.getSimpleType("void"); @@ -638,7 +647,7 @@ public class UnifyTest extends TypeUnify { fcb.add(integer, object); fcb.add(main, object); fcb.add(bool, object); - fcb.add(voidType, object); + fcb.add(voidType, voidType); fcb.add(ol, object); IFiniteClosure fc = fcb.getFiniteClosure(); @@ -657,10 +666,71 @@ public class UnifyTest extends TypeUnify { eq.add(new UnifyPair(tphT5, ol, PairOperator.SMALLERDOT)); Set> expected = new HashSet<>(); + Set solution = new HashSet(); + solution.add(new UnifyPair(tphT3, bool, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT5, ol, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT2, integer, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT1, integer, PairOperator.EQUALSDOT)); + solution.add(new UnifyPair(tphT4, voidType, PairOperator.EQUALSDOT)); + expected.add(solution); + + Set> actual = unify(eq, fc); System.out.println("Test Void:"); System.out.println(actual); + + Assert.assertEquals(expected, actual); + } + + @Test + public void unifyTestOverloading(){ + /* + * Constraints Set mit "void" Typen + * OL < T1 + * T1 < T1 + * T1 < T2 + * T1 < OL + */ + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + + UnifyType tphT1 = tf.getPlaceholderType("T1"); + UnifyType tphT2 = tf.getPlaceholderType("T2"); + + UnifyType integer = tf.getSimpleType("java.lang.Integer"); + UnifyType voidType = tf.getSimpleType("void"); + UnifyType bool = tf.getSimpleType("java.lang.Boolean"); + UnifyType object = tf.getSimpleType("Object"); + UnifyType main = tf.getSimpleType("Main"); + UnifyType ol = tf.getSimpleType("OL"); + + fcb.add(integer, object); + fcb.add(main, object); + fcb.add(bool, object); + fcb.add(voidType, voidType); + fcb.add(ol, object); + + IFiniteClosure fc = fcb.getFiniteClosure(); + + Set eq = new HashSet(); + eq.add(new UnifyPair(ol, tphT1, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, tphT1, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, tphT2, PairOperator.SMALLERDOT)); + eq.add(new UnifyPair(tphT1, ol, PairOperator.SMALLERDOT)); + + Set expectedSolution = new HashSet(); + expectedSolution.add(new UnifyPair(tphT1, ol, PairOperator.EQUALSDOT)); + + + Set> actual = unify(eq, fc); + + System.out.println("Test Overloading:"); + System.out.println(actual); + + for(Set actualSolution : actual){ + Assert.assertTrue(actualSolution.containsAll(expectedSolution)); + } } @Test