From 257edfc0b3c19bf43f71952d5066abf572445101 Mon Sep 17 00:00:00 2001 From: Florian Steurer Date: Sat, 26 Mar 2016 14:09:45 +0100 Subject: [PATCH] fc smaller test --- test/unify/FiniteClosureBuilder.java | 18 +++++ test/unify/FiniteClosureTest.java | 107 +++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) diff --git a/test/unify/FiniteClosureBuilder.java b/test/unify/FiniteClosureBuilder.java index d5b3b32b..5a639b38 100644 --- a/test/unify/FiniteClosureBuilder.java +++ b/test/unify/FiniteClosureBuilder.java @@ -29,6 +29,8 @@ public class FiniteClosureBuilder { public IFiniteClosure getCollectionExample() { TypeFactory tf = new TypeFactory(); + /* Collection */ + Type collection = tf.getSimpleType("Collection"); Type set = tf.getSimpleType("Set", "T"); Type sortedSet = tf.getSimpleType("Set", "T"); @@ -58,6 +60,22 @@ public class FiniteClosureBuilder { add(arrayList, list); add(stack, vector); + /* Map */ + Type map = tf.getSimpleType("Map", "K", "V"); + Type sortedMap = tf.getSimpleType("SortedMap", "K", "V"); + Type navigableMap = tf.getSimpleType("NavigableMap", "K", "V"); + Type treeMap = tf.getSimpleType("TreeMap", "K", "V"); + Type hashMap = tf.getSimpleType("HashMap", "K", "V"); + Type hashtable = tf.getSimpleType("Hashtable", "K", "V"); + Type linkedHashMap = tf.getSimpleType("LinkedHashSet", "K", "V"); + + add(sortedMap, map); + add(hashMap, map); + add(hashtable, map); + add(navigableMap, sortedMap); + add(treeMap, navigableMap); + add(linkedHashMap, hashMap); + IFiniteClosure fc = getFiniteClosure(); clear(); return fc; diff --git a/test/unify/FiniteClosureTest.java b/test/unify/FiniteClosureTest.java index c35bfe66..d3766e74 100644 --- a/test/unify/FiniteClosureTest.java +++ b/test/unify/FiniteClosureTest.java @@ -168,6 +168,7 @@ public class FiniteClosureTest { /* * Test Case 7: + * * smaller(Set) = * { HashSet, Set, TreeSet, LinkedHashSet, * HashSet, Set, TreeSet, LinkedHashSet } @@ -193,6 +194,112 @@ public class FiniteClosureTest { /* * Test Case 8: * + * smaller(Set) = + * { Set, HashSet, LinkedHashSet, TreeSet, + * Set, HashSet, LinkedHashSet, TreeSet } + */ + + Type superNotInFc = tf.getSuperType(notInFc); + Type setSuperNotInFc = tf.getSimpleType("Set", superNotInFc); + Type hashSetSuperNotInFc = tf.getSimpleType("HashSet", superNotInFc); + Type treeSetSuperNotInFc = tf.getSimpleType("TreeSet", superNotInFc); + Type linkedHashSetSuperNotInFc = tf.getSimpleType("LinkedHashSet", superNotInFc); + + expectedResult = new HashSet<>(Arrays.stream(new Type[] { + setNotInFc, hashSetNotInFc, treeSetNotInFc, linkedHashSetNotInFc, + setSuperNotInFc, hashSetSuperNotInFc, treeSetSuperNotInFc, linkedHashSetSuperNotInFc + }).collect(Collectors.toSet())); + + Assert.assertEquals(expectedResult, fc.smaller(setSuperNotInFc)); + + /* + * Test Case 8: + * + * smaller(NotInFc) = + * { NotInFc, NotInFc, NotInFc, NotInFc } + */ + + Type notInFcExtNumber = tf.getSimpleType("NotInFc", extNum); + Type notInFcInteger = tf.getSimpleType("NotInFc", integer); + Type notInFcNumber = tf.getSimpleType("NotInFc", number); + Type notInFcExtInt = tf.getSimpleType("NotInFc", extInt); + + expectedResult = new HashSet<>(Arrays.stream(new Type[] { + notInFcExtNumber, notInFcInteger, notInFcNumber, notInFcExtInt + }).collect(Collectors.toSet())); + + Assert.assertEquals(expectedResult, fc.smaller(notInFcExtNumber)); + + /* + * Test Case 9: + * + * smaller(NotInFc = + * { NotInFc, NotInFc } + */ + + Type alsoNotInFc = tf.getSimpleType("AlsoNotInFc"); + Type notInFcAlsoNotInFc = tf.getSimpleType("NotInFc", alsoNotInFc); + Type notInFcSupAlsoNotInFc = tf.getSimpleType("NotInFc", tf.getSuperType(alsoNotInFc)); + + expectedResult = new HashSet<>(Arrays.stream(new Type[] { + notInFcAlsoNotInFc, notInFcSupAlsoNotInFc + }).collect(Collectors.toSet())); + + Set actual = fc.smaller(notInFcSupAlsoNotInFc); + Assert.assertEquals(expectedResult, actual); + + /* + * Test Case 10: + * + * smaller(HashMap) = + * { HashMap, HashMap, HashMap, HashMap + * HashMap, HashMap, HashMap, HashMap, + * HashMap, HashMap, HashMap + * HashMap, HashMap, HashMap, HashMap } + */ + + /* + * Test Case 11: + * + * smaller(SortedMap) = { SortedMap, NavigableMap, TreeMap } + */ + + /* + * Test Case 12: + * + * MyMap> <* HashMap + * + * smaller(HashMap) = { HashMap>, MyMap> } + */ + + /* + * Test Case 13: + * + * MyMap> <* HashMap + * + * smaller(HashMap) = + * { HashMap, List>, + * HashMap>, + * MyMap> } + */ + + /* + * Test Case 14 + * + * MyMap> <* HashMap + * + * smaller(HashMap) = + */ + + /* + * Test Case 13: + * + * MyMap> <* HashMap +// * TODO sinnvoll ausformulieren + * smaller(HashMap) = + * { HashMap, List>, + * HashMap>, + * MyMap> } */ }