X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Futils%2FModelledSTSSuite.java;h=7ccb3ccd358f52b7b443476ff8ade20b8c05883b;hb=1ec0193a5a5b8f368b03adb24acd762838ddf8ea;hp=b856787cfc560c4c634e471909cdc86e48d49bdb;hpb=36799f7fc9a4793236d9085aa87ee5baff167376;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSSuite.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSSuite.java index b856787cf..7ccb3ccd3 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSSuite.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSSuite.java @@ -1,10 +1,15 @@ package org.simantics.tests.modelled.utils; import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedList; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; -import java.util.stream.Collectors; import org.simantics.scl.compiler.module.Module; import org.simantics.scl.compiler.module.coverage.CombinedCoverage; @@ -19,10 +24,12 @@ public class ModelledSTSSuite { private List moduleNameFilterPatterns = new ArrayList<>(); private CoverageBuilder coverageBuilder; + private Map variables; - ModelledSTSSuite(String name, List children, String moduleNameFilter) { + ModelledSTSSuite(String name, List children, String moduleNameFilter, Map variables) { this.name = name; this.children = children; + this.variables = variables; this.moduleNameFilter = moduleNameFilter; for (String s : moduleNameFilter.split(",")) { try { @@ -42,8 +49,46 @@ public class ModelledSTSSuite { return children; } + static Comparator comparator = (test1, test2) -> compareTests(test1, test2); + public List getSortedChildren() { - return new ArrayList<>(children).stream().sorted(ModelledSTSSuite::compareTests).collect(Collectors.toList()); + Set testsWithDeps = new HashSet<>(); + // This TreeMap sorts the tests with the comparator + TreeMap sortedTests = new TreeMap<>(comparator); + for (ModelledSTSTest test : getChildren()) { + Set testDependencies = test.getDependencies(); + if (testDependencies.isEmpty()) { + // First tests that have no dependencies + sortedTests.put(test, test.getName()); + } else { + // These are resolved later + testsWithDeps.add(test); + } + } + + // Construct a LinkedList that is returned as a result + LinkedList results = new LinkedList<>(sortedTests.keySet()); + +// Set temp = new HashSet<>(testsWithDeps); + // Now resolve tests with dependencies + for (ModelledSTSTest testWithDep : testsWithDeps) { + boolean satisfied = true; + for (String dep : testWithDep.getDependencies()) { + if (!sortedTests.containsValue(dep)) { + satisfied = false; + } else { + testWithDep.resolveDependency(dep); + } + } + if (satisfied) { + results.addLast(testWithDep); + sortedTests.put(testWithDep, testWithDep.getName()); + } else { + // Not satisfied + System.out.println(testWithDep.getName() + " not satisfied"); + } + } + return results; } private static int compareTests(ModelledSTSTest test1, ModelledSTSTest test2) {