From 3953c903ca08137e2fba5d7d7330a5e9056f624a Mon Sep 17 00:00:00 2001 From: Márton Golej Date: Mon, 25 Oct 2021 20:54:03 +0200 Subject: Test for the case study added. --- .../language/mapping/PartialModelMapper.java | 211 ++++++++++----------- .../mapping/tests/PartialModelMapperTest.xtend | 201 ++++++++++++++------ 2 files changed, 249 insertions(+), 163 deletions(-) (limited to 'language-to-store') diff --git a/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java b/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java index ba32921a..1593a237 100644 --- a/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java +++ b/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java @@ -27,117 +27,111 @@ import tools.refinery.store.model.Tuple; import tools.refinery.store.model.representation.Relation; import tools.refinery.store.model.representation.TruthValue; - public class PartialModelMapper { public PartialModelMapperDTO transformProblem(Problem problem) throws PartialModelMapperException { - //Defining an integer in order to assign different values to all the nodes - int[] nodeIter = new int[] {0}; - - //Getting the relations and the nodes from the given problem + // Defining an integer in order to assign different values to all the nodes + int[] nodeIter = new int[] { 0 }; + + // Getting the relations and the nodes from the given problem PartialModelMapperDTO pmmDTO = initTransform(problem, nodeIter); - - //Getting the relations and the nodes from the built in problem + + // Getting the relations and the nodes from the built in problem Optional builtinProblem = ProblemUtil.getBuiltInLibrary(problem); - if (builtinProblem.isEmpty()) throw new PartialModelMapperException("builtin.problem not found"); + if (builtinProblem.isEmpty()) + throw new PartialModelMapperException("builtin.problem not found"); PartialModelMapperDTO builtinProblemDTO = initTransform(builtinProblem.get(), nodeIter); - - //Merging the relation and the nodes from the given problem and from the built in problem + + // Merging the relation and the nodes from the given problem and from the built + // in problem pmmDTO.getRelationMap().putAll(builtinProblemDTO.getRelationMap()); pmmDTO.getNodeMap().putAll(builtinProblemDTO.getNodeMap()); pmmDTO.getEnumNodeMap().putAll(builtinProblemDTO.getEnumNodeMap()); pmmDTO.getNewNodeMap().putAll(builtinProblemDTO.getNewNodeMap()); pmmDTO.getUniqueNodeMap().putAll(builtinProblemDTO.getUniqueNodeMap()); - - //Definition of store and model + + // Definition of store and model ModelStore store = new ModelStoreImpl(new HashSet<>(pmmDTO.getRelationMap().values())); Model model = store.createModel(); pmmDTO.setModel(model); - - //Collecting all the nodes in one map - Map allNodesMap = mergeNodeMaps(pmmDTO.getEnumNodeMap(), - pmmDTO.getUniqueNodeMap(), - pmmDTO.getNewNodeMap(), - pmmDTO.getNodeMap()); - - //Filling up the relations with unknown truth values + + // Collecting all the nodes in one map + Map allNodesMap = mergeNodeMaps(pmmDTO.getEnumNodeMap(), pmmDTO.getUniqueNodeMap(), + pmmDTO.getNewNodeMap(), pmmDTO.getNodeMap()); + + // Filling up the relations with unknown truth values for (tools.refinery.language.model.problem.Relation relation : pmmDTO.getRelationMap().keySet()) { - if(!(relation instanceof PredicateDefinition pd && pd.isError())) { + if (!(relation instanceof PredicateDefinition pd && pd.isError())) { Relation r = pmmDTO.getRelationMap().get(relation); - if(r.getArity() == 1) - for(Integer i : allNodesMap.values()) { - pmmDTO.getModel().put(r, Tuple.of(i), TruthValue.UNKNOWN); - } - else if(r.getArity() == 2) - for(Integer i : allNodesMap.values()) { - for (Integer j : allNodesMap.values()) { - pmmDTO.getModel().put(r, Tuple.of(i,j), TruthValue.UNKNOWN); + if (r.getArity() == 1) + for (Integer i : allNodesMap.values()) { + pmmDTO.getModel().put(r, Tuple.of(i), TruthValue.UNKNOWN); } - } - else throw new PartialModelMapperException("Relation with arity above 2 is not supported"); + else if (r.getArity() == 2) + for (Integer i : allNodesMap.values()) { + for (Integer j : allNodesMap.values()) { + pmmDTO.getModel().put(r, Tuple.of(i, j), TruthValue.UNKNOWN); + } + } + else + throw new PartialModelMapperException("Relation with arity above 2 is not supported"); } } - - //Filling up the exists - tools.refinery.language.model.problem.Relation existsRelation = findingRelationInDTO(builtinProblemDTO, "exists", - "The exists not found in built in problem"); + + // Filling up the exists + tools.refinery.language.model.problem.Relation existsRelation = findingRelationInDTO(builtinProblemDTO, + "exists", "The exists not found in built in problem"); for (Node n : allNodesMap.keySet()) { - if(pmmDTO.getNewNodeMap().containsKey(n)) { + if (pmmDTO.getNewNodeMap().containsKey(n)) { pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), - Tuple.of(allNodesMap.get(n)), - TruthValue.UNKNOWN); - } - else { + Tuple.of(allNodesMap.get(n)), TruthValue.UNKNOWN); + } else { pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), - Tuple.of(allNodesMap.get(n)), - TruthValue.TRUE); + Tuple.of(allNodesMap.get(n)), TruthValue.TRUE); } } - - //Filling up the equals - tools.refinery.language.model.problem.Relation equalsRelation = findingRelationInDTO(builtinProblemDTO, "equals", - "The equals not found in built in problem"); + + // Filling up the equals + tools.refinery.language.model.problem.Relation equalsRelation = findingRelationInDTO(builtinProblemDTO, + "equals", "The equals not found in built in problem"); for (Node n1 : allNodesMap.keySet()) { - for(Node n2 : allNodesMap.keySet()) { - if(n1.equals(n2)) { - if(pmmDTO.getNewNodeMap().containsKey(n1)) { + for (Node n2 : allNodesMap.keySet()) { + if (n1.equals(n2)) { + if (pmmDTO.getNewNodeMap().containsKey(n1)) { pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), - Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), - TruthValue.UNKNOWN); - } - else { + Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.UNKNOWN); + } else { pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), - Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), - TruthValue.TRUE); + Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.TRUE); } - } - else { + } else { pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), - Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), - TruthValue.FALSE); + Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.FALSE); } } } - - //Transforming the assertions + + // Transforming the assertions processAssertions(problem, pmmDTO, allNodesMap); processAssertions(builtinProblem.get(), pmmDTO, allNodesMap); - + return pmmDTO; } - //Searches for and gives back a relation in a PartialModelMapperDTO - private tools.refinery.language.model.problem.Relation findingRelationInDTO(PartialModelMapperDTO partialModelMapperDTO, String searchedRelation, String errorText) + // Searches for and gives back a relation in a PartialModelMapperDTO + private tools.refinery.language.model.problem.Relation findingRelationInDTO( + PartialModelMapperDTO partialModelMapperDTO, String searchedRelation, String errorText) throws PartialModelMapperException { for (tools.refinery.language.model.problem.Relation r : partialModelMapperDTO.getRelationMap().keySet()) { - if (searchedRelation.equals(r.getName())) return r; + if (searchedRelation.equals(r.getName())) + return r; } throw new PartialModelMapperException(errorText); } - //Processing assertions and placing them in the model + // Processing assertions and placing them in the model private void processAssertions(Problem problem, PartialModelMapperDTO pmmDTO, Map allNodesMap) { - for(Statement s : problem.getStatements()) { - if(s instanceof Assertion assertion) { + for (Statement s : problem.getStatements()) { + if (s instanceof Assertion assertion) { Relation r1 = pmmDTO.getRelationMap().get(assertion.getRelation()); int i = 0; int[] integers = new int[assertion.getArguments().size()]; @@ -148,76 +142,69 @@ public class PartialModelMapper { } } pmmDTO.getModel().put(r1, Tuple.of(integers), logicValueToTruthValue(assertion.getValue())); - } - else if (s instanceof ClassDeclaration cd) { - if(!cd.isAbstract()) - pmmDTO.getModel().put(pmmDTO.getRelationMap().get(cd), - Tuple.of(pmmDTO.getNewNodeMap().get(cd.getNewNode())), - TruthValue.TRUE); - } - else if (s instanceof EnumDeclaration ed) { + } else if (s instanceof ClassDeclaration cd) { + if (!cd.isAbstract()) + pmmDTO.getModel().put(pmmDTO.getRelationMap().get(cd), + Tuple.of(pmmDTO.getNewNodeMap().get(cd.getNewNode())), TruthValue.TRUE); + } else if (s instanceof EnumDeclaration ed) { for (Node n : ed.getLiterals()) { - pmmDTO.getModel().put(pmmDTO.getRelationMap().get(ed), - Tuple.of(pmmDTO.getEnumNodeMap().get(n)), - TruthValue.TRUE); + pmmDTO.getModel().put(pmmDTO.getRelationMap().get(ed), Tuple.of(pmmDTO.getEnumNodeMap().get(n)), + TruthValue.TRUE); } } } } - - //Getting the relations and nodes from the problem + + // Getting the relations and nodes from the problem private PartialModelMapperDTO initTransform(Problem problem, int[] nodeIter) { - //Defining needed Maps + // Defining needed Maps Map> relationMap = new HashMap<>(); Map enumNodeMap = new HashMap<>(); Map uniqueNodeMap = new HashMap<>(); Map newNodeMap = new HashMap<>(); - - //Definition of Relations, filling up the enumNodeMap, uniqueNodeMap, newNodeMap + + // Definition of Relations, filling up the enumNodeMap, uniqueNodeMap, + // newNodeMap EList statements = problem.getStatements(); for (Statement s : statements) { if (s instanceof ClassDeclaration cd) { Relation r1 = new Relation<>(cd.getName(), 1, TruthValue.FALSE); relationMap.put(cd, r1); - if(!cd.isAbstract()) newNodeMap.put(cd.getNewNode(), nodeIter[0]++); + if (!cd.isAbstract()) + newNodeMap.put(cd.getNewNode(), nodeIter[0]++); EList refDeclList = cd.getReferenceDeclarations(); for (ReferenceDeclaration refDec : refDeclList) { Relation r2 = new Relation<>(refDec.getName(), 2, TruthValue.FALSE); relationMap.put(refDec, r2); } - } - else if (s instanceof EnumDeclaration ed) { + } else if (s instanceof EnumDeclaration ed) { Relation r = new Relation<>(ed.getName(), 1, TruthValue.FALSE); relationMap.put(ed, r); for (Node n : ed.getLiterals()) { enumNodeMap.put(n, nodeIter[0]++); } - } - else if (s instanceof UniqueDeclaration ud) { + } else if (s instanceof UniqueDeclaration ud) { for (Node n : ud.getNodes()) { uniqueNodeMap.put(n, nodeIter[0]++); } - } - else if (s instanceof PredicateDefinition pd) { + } else if (s instanceof PredicateDefinition pd) { Relation r = new Relation<>(pd.getName(), 1, TruthValue.FALSE); relationMap.put(pd, r); } } - - //Filling the nodeMap up + + // Filling the nodeMap up Map nodeMap = new HashMap<>(); - for(Node n : problem.getNodes()) { + for (Node n : problem.getNodes()) { nodeMap.put(n, nodeIter[0]++); } - - return new PartialModelMapperDTO(null,relationMap,nodeMap,enumNodeMap,uniqueNodeMap,newNodeMap); + + return new PartialModelMapperDTO(null, relationMap, nodeMap, enumNodeMap, uniqueNodeMap, newNodeMap); } - - //Merging the maps of nodes into one map - private Map mergeNodeMaps(Map enumNodeMap, - Map uniqueNodeMap, - Map newNodeMap, - Map nodeMap) { + + // Merging the maps of nodes into one map + private Map mergeNodeMaps(Map enumNodeMap, Map uniqueNodeMap, + Map newNodeMap, Map nodeMap) { Map out = new HashMap<>(); out.putAll(enumNodeMap); out.putAll(uniqueNodeMap); @@ -226,19 +213,25 @@ public class PartialModelMapper { return out; } - //Exchange method from LogicValue to TruthValue + // Exchange method from LogicValue to TruthValue private TruthValue logicValueToTruthValue(LogicValue value) { - if(value.equals(LogicValue.TRUE)) return TruthValue.TRUE; - else if(value.equals(LogicValue.FALSE)) return TruthValue.FALSE; - else if(value.equals(LogicValue.UNKNOWN)) return TruthValue.UNKNOWN; - else return TruthValue.ERROR; + if (value.equals(LogicValue.TRUE)) + return TruthValue.TRUE; + else if (value.equals(LogicValue.FALSE)) + return TruthValue.FALSE; + else if (value.equals(LogicValue.UNKNOWN)) + return TruthValue.UNKNOWN; + else + return TruthValue.ERROR; } - - public class PartialModelMapperException extends Exception{ + + public class PartialModelMapperException extends Exception { private static final long serialVersionUID = 1L; + public PartialModelMapperException(String errorText) { super(errorText); } + public PartialModelMapperException() { super(); } diff --git a/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend b/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend index dcdea332..52b89bae 100644 --- a/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend +++ b/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend @@ -59,9 +59,9 @@ class PartialModelMapperTest { val a = problem.node("a") val b = problem.node("b") - assertTrue(model.getDataRepresentations().contains(relationMap.get(person))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))); - assertTrue(model.get(relationMap.get(friend), Tuple.of(nodeMap.get(a),nodeMap.get(b))).equals(TruthValue.TRUE)); + assertTrue(model.getDataRepresentations().contains(relationMap.get(person))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))) + assertTrue(model.get(relationMap.get(friend), Tuple.of(nodeMap.get(a),nodeMap.get(b))).equals(TruthValue.TRUE)) } //Testing the class @@ -87,10 +87,10 @@ class PartialModelMapperTest { val friend = problem.findClass("Person").reference("friend") val a = problem.node("a") - assertTrue(model.getDataRepresentations().contains(relationMap.get(person))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))); + assertTrue(model.getDataRepresentations().contains(relationMap.get(person))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))) - assertTrue(model.get(relationMap.get(person), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)); + assertTrue(model.get(relationMap.get(person), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)) } //Testing the equals and exists from the built in problem @@ -103,7 +103,7 @@ class PartialModelMapperTest { class Person. ''') EcoreUtil.resolveAll(problem) - val builtin = problem.builtin; + val builtin = problem.builtin val modelAndMaps = mapper.transformProblem(problem) assertThat(modelAndMaps, notNullValue()) @@ -148,7 +148,7 @@ class PartialModelMapperTest { Person(a). Person(b). ''') - val builtin = problem.builtin; + val builtin = problem.builtin EcoreUtil.resolveAll(problem) val modelAndMaps = mapper.transformProblem(problem) @@ -166,23 +166,23 @@ class PartialModelMapperTest { val exists = builtin.pred("exists") val equals = builtin.findClass("node").reference("equals") - assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(exists))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(equals))); - - assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(b))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(a))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(b))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(b))).equals(TruthValue.FALSE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(a))).equals(TruthValue.FALSE)); - - assertTrue(model.get(relationMap.get(exists), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(a))).equals(TruthValue.FALSE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(b))).equals(TruthValue.FALSE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)); - assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)); + assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(exists))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(equals))) + + assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(b))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(a))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(b))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(b))).equals(TruthValue.FALSE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(a))).equals(TruthValue.FALSE)) + + assertTrue(model.get(relationMap.get(exists), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(a))).equals(TruthValue.FALSE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(b))).equals(TruthValue.FALSE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)) + assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)) } //Testing the behavior of the newNodes @@ -194,7 +194,7 @@ class PartialModelMapperTest { ''') EcoreUtil.resolveAll(problem) - val modelAndMaps = mapper.transformProblem(problem); + val modelAndMaps = mapper.transformProblem(problem) assertThat(modelAndMaps, notNullValue()) val model = modelAndMaps.model @@ -206,11 +206,11 @@ class PartialModelMapperTest { val PersonNew = problem.findClass("Person").newNode - assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))); + assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))) assertTrue(newNodeMap.size.equals(4)) //3 from builtin.problem, 1 from Person - assertTrue(model.get(relationMap.get(Person), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.TRUE)); + assertTrue(model.get(relationMap.get(Person), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.TRUE)) } //Testing the behavior of enumerations @@ -236,11 +236,11 @@ class PartialModelMapperTest { val adult = problem.findEnum("TaxStatus").literal("adult") val retired = problem.findEnum("TaxStatus").literal("retired") - assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))); - assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(child))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(student))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(adult))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(retired))).equals(TruthValue.TRUE)); + assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))) + assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(child))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(student))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(adult))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(retired))).equals(TruthValue.TRUE)) } //Testing the bool from the built in problem @@ -250,7 +250,7 @@ class PartialModelMapperTest { class Person. ''') EcoreUtil.resolveAll(problem) - val builtin = problem.builtin; + val builtin = problem.builtin val modelAndMaps = mapper.transformProblem(problem) assertThat(modelAndMaps, notNullValue()) @@ -263,9 +263,9 @@ class PartialModelMapperTest { val trueEnum = builtin.findEnum("bool").literal("true") //Emiatt nem sikerül a teszt val falseEnum = builtin.findEnum("bool").literal("false") - assertTrue(model.getDataRepresentations().contains(relationMap.get(bool))); - assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(trueEnum))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(falseEnum))).equals(TruthValue.TRUE)); + assertTrue(model.getDataRepresentations().contains(relationMap.get(bool))) + assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(trueEnum))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(falseEnum))).equals(TruthValue.TRUE)) } //Testing different aspects of the behavior @@ -325,21 +325,114 @@ class PartialModelMapperTest { val family = problem.uniqueNode("family") val adult = problem.findEnum("TaxStatus").literal("adult") - assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(members))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(children))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(parent))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(taxStatus))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))); - assertTrue(model.getDataRepresentations().contains(relationMap.get(invalidTaxStatus))); - - assertTrue(model.get(relationMap.get(Family), Tuple.of(uniqueNodeMap.get(family))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(anne))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(bob))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(ciri))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(anne),nodeMap.get(ciri))).equals(TruthValue.TRUE)); - assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(bob),nodeMap.get(ciri))).equals(TruthValue.UNKNOWN)); - assertTrue(model.get(relationMap.get(taxStatus), Tuple.of(nodeMap.get(anne),enumNodeMap.get(adult))).equals(TruthValue.TRUE)); + assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(members))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(children))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(parent))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(taxStatus))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(invalidTaxStatus))) + + assertTrue(model.get(relationMap.get(Family), Tuple.of(uniqueNodeMap.get(family))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(anne))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(bob))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(ciri))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(anne),nodeMap.get(ciri))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(bob),nodeMap.get(ciri))).equals(TruthValue.UNKNOWN)) + assertTrue(model.get(relationMap.get(taxStatus), Tuple.of(nodeMap.get(anne),enumNodeMap.get(adult))).equals(TruthValue.TRUE)) + } + + @Test + def void carCaseStudyTest(){ + val problem = parseHelper.parse(''' + abstract class DynamicComponent { + contains StaticComponent[1..1] placedOn + } + abstract class StaticComponent. + class Car extends DynamicComponent. + class Pedestrian extends DynamicComponent. + class Road extends StaticComponent { + contains LaneSegment[0..*] lanes + } + class LaneSegment extends StaticComponent { + Lane[0..*] adjacentLanes + Lane[0..*] sameDirLanes + } + + Car(c1). + Car(c2). + Pedestrian(p1). + Road(r1). + LaneSegment(l1). + LaneSegment(l2). + LaneSegment(l3). + placedOn(c1,l1). + placedOn(c2,l2). + placedOn(p1,l3). + lanes(r1,l1). + lanes(r1,l2). + lanes(r1,l3). + adjacentLanes(l1,l2). + adjacentLanes(l2,l1). + sameDirLanes(l1,l3). + sameDirLanes(l3,l1). + ''') + EcoreUtil.resolveAll(problem) + + val modelAndMaps = mapper.transformProblem(problem) + assertThat(modelAndMaps, notNullValue()) + + val model = modelAndMaps.model + val relationMap = modelAndMaps.relationMap + val nodeMap = modelAndMaps.nodeMap + + val DynamicComponent = problem.findClass("DynamicComponent") + val placedOn = problem.findClass("DynamicComponent").reference("placedOn") + val StaticComponent = problem.findClass("StaticComponent") + val Car = problem.findClass("Car") + val Pedestrian = problem.findClass("Pedestrian") + val Road = problem.findClass("Road") + val lanes = problem.findClass("Road").reference("lanes") + val LaneSegment = problem.findClass("LaneSegment") + val adjacentLanes = problem.findClass("LaneSegment").reference("adjacentLanes") + val sameDirLanes = problem.findClass("LaneSegment").reference("sameDirLanes") + + val c1 = problem.node("c1") + val c2 = problem.node("c2") + val p1 = problem.node("p1") + val r1 = problem.node("r1") + val l1 = problem.node("l1") + val l2 = problem.node("l2") + val l3 = problem.node("l3") + + assertTrue(model.getDataRepresentations().contains(relationMap.get(DynamicComponent))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(placedOn))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(StaticComponent))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(Car))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(Pedestrian))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(Road))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(lanes))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(LaneSegment))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(adjacentLanes))) + assertTrue(model.getDataRepresentations().contains(relationMap.get(sameDirLanes))) + + assertTrue(model.get(relationMap.get(Car), Tuple.of(nodeMap.get(c1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(Car), Tuple.of(nodeMap.get(c2))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(Pedestrian), Tuple.of(nodeMap.get(p1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(Road), Tuple.of(nodeMap.get(r1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l2))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l3))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(c1),nodeMap.get(l1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(c2),nodeMap.get(l2))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(p1),nodeMap.get(l3))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l2))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l3))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(adjacentLanes), Tuple.of(nodeMap.get(l1),nodeMap.get(l2))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(adjacentLanes), Tuple.of(nodeMap.get(l2),nodeMap.get(l1))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(sameDirLanes), Tuple.of(nodeMap.get(l1),nodeMap.get(l3))).equals(TruthValue.TRUE)) + assertTrue(model.get(relationMap.get(sameDirLanes), Tuple.of(nodeMap.get(l3),nodeMap.get(l1))).equals(TruthValue.TRUE)) } } -- cgit v1.2.3-54-g00ecf