From 74888432477ef69916b42b0a9d67cb6edd2c1e08 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 22 Jul 2022 15:24:17 +0300 Subject: [PATCH 01/40] tuscan and alphabetical --- .../detectors/AlphabeticalDetector.java | 44 ++++++ .../detection/detectors/TuscanDetector.java | 44 ++++++ .../illinois/cs/dt/tools/utility/Tuscan.java | 130 ++++++++++++++++++ 3 files changed, 218 insertions(+) create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java new file mode 100644 index 00000000..93c26454 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -0,0 +1,44 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class AlphabeticalDetector extends ExecutingDetector { + final List tests; + private TestRunResult origResult; + private TestRunResult lastTuscanResult; + private DetectionRound lastTuscanDetectionRound; + + private final TestShuffler testShuffler; + public AlphabeticalDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + // this.count = 0; + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + lastTuscanResult = runList(testShuffler.alphabeticalOrder()); + lastTuscanDetectionRound = makeDts(origResult, lastTuscanResult); + return lastTuscanDetectionRound; + } + +} diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java new file mode 100644 index 00000000..0bc44102 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java @@ -0,0 +1,44 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class TuscanDetector extends ExecutingDetector { + final List tests; + private TestRunResult origResult; + private TestRunResult lastTuscanResult; + private DetectionRound lastTuscanDetectionRound; + + private final TestShuffler testShuffler; + public TuscanDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + // this.count = 0; + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + lastTuscanResult = runList(testShuffler.tuscanOrder(absoluteRound.get())); + lastTuscanDetectionRound = makeDts(origResult, lastTuscanResult); + return lastTuscanDetectionRound; + } + +} diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java new file mode 100644 index 00000000..0ae31376 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -0,0 +1,130 @@ +package edu.illinois.cs.dt.tools.utility; + +import scala.annotation.meta.getter; + +public class Tuscan { + public void main(int arg) { + int n = arg; + if (n == 3 || n == 5) { + throw new RuntimeException("Impossible to solve for n=3 or n=5."); + } + generateTuscanSquare(n); + } + static int[][] r; + static void helper(int[] a, int i) { + System.arraycopy(a, 0, r[i], 0, a.length); + } + static void generateTuscanSquare(int n) { + int nn = n; + while((n-1) % 4 == 0 && n != 1 && n != 9) n = (n-1)/2+1; + + r = new int[nn][]; + for (int i = 0; i < nn; i++) { + r[i] = new int[nn+1]; + } + + if (n % 2 == 0) { + // https://mathoverflow.net/questions/60856/hamilton-paths-in-k-2n/60859#60859 + int[] a = new int[n]; + for (int i = 0; i < n; i += 2) { + a[i] = i / 2; + a[i+1] = n - 1 - a[i]; + } + helper(a, 0); + for (int j = 1; j < n; j++) { + for (int i = 0; i < n; i++) { + a[i] = (a[i] + 1) % n; + } + helper(a, j); + } + } else if (n % 4 == 3) { + int k = (n - 3) / 4; + int[] b = new int[n]; + for (int i = 0; i < n - 1; i++) { + int p = (i == 0) ? 1 : + ((i == k + 1) ? 4*k + 2 : + ((i == 2*k + 2) ? 3 : + ((i == 3*k + 2) ? 4*k : 2*k))); + int[] a = new int[n]; + for (int j = 0; j < n; j++) { + a[(j < p) ? n+j-p : j-p] = (j == 0) ? (n - 1) : (i + ((j % 2 == 0) ? (j / 2) : (n - 1 - (j - 1) / 2))) % (n - 1); + } + b[a[n-1]] = a[0]; + helper(a, i); + } + int[] t = new int[n]; + t[0] = n - 1; + for (int i = 1; i < n; i++) { + t[i] = b[t[i-1]]; + } + helper(t, n-1); + } else if (n == 9) { + int[][] t = {{0,1,7,2,6,3,5,4,8}, + {3,7,4,6,5,8,1,2,0}, + {1,4,0,5,7,6,8,2,3}, + {6,0,7,8,3,4,2,5,1}, + {2,7,1,0,8,4,5,3,6}, + {7,3,0,2,1,8,5,6,4}, + {5,0,4,1,3,2,8,6,7}, + {4,3,8,7,0,6,1,5,2}, + {8,0,3,1,6,2,4,7,5}}; + for (int i = 0; i < 9; i++) { + helper(t[i], i); + } + } + else assert(false); + + while (nn != n){ + // n + 1 == 4*m - 2 + // https://www.sciencedirect.com/science/article/pii/0095895680900441 + + n = n * 2 - 1; + + int h = (n + 1) / 2; + + for (int i = 0; i < h; i++) { + for (int j = 0; j < h; j++) { + r[i][n-j] = r[i][j] + h; + } + // System.out.println(java.util.Arrays.toString(r[i])); + } + for (int i = h; i < n; i++) { + /* + for (int j = 0; j < n+1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (n - (j - 1) / 2))) % h; + } + */ + for (int j = 0; j < h - 1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (h - 2 - (j - 1) / 2))) % (h - 1); + } + r[i][h-1] = h-1; + for (int j = h; j < n + 1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + r[i][j-h] % h; + } + // System.out.println(java.util.Arrays.toString(r[i])); + } + for (int i = 0; i < n; i++) { + int l = 0; + for (; l < n; l++) { + if (r[i][l] == n) break; + } + int[] t = new int[n]; + System.arraycopy(r[i], l+1, t, 0, n-l); + System.arraycopy(r[i], 0, t, n-l, l); + + System.arraycopy(t, 0, r[i], 0, n); + } + } + + // for (int i = 0; i < nn; i++){ + // System.out.print("["); + // for (int j = 0; j < nn; j++) + // System.out.print((r[i][j]+ (j==nn-1?"":", "))); + // System.out.println("]"); + // } + } + + public int[][] getMatrix(){ + return r; + } +} From d17683cc76dca0a79efea3a29594f42a4cdb043b Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 22 Jul 2022 15:30:24 +0300 Subject: [PATCH 02/40] tuscan --- .../cs/dt/tools/detection/TestShuffler.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 42cc747a..2fcb8a70 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -10,6 +10,7 @@ import edu.illinois.cs.dt.tools.utility.Logger; import edu.illinois.cs.dt.tools.utility.MD5; import edu.illinois.cs.dt.tools.utility.PathManager; +import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.configuration.Configuration; import edu.illinois.cs.testrunner.data.results.TestRunResult; @@ -194,4 +195,35 @@ private int permutations(final int accum, final Iterator> iterator, } } } + + public List tuscanOrder(int count) { + List classes = new ArrayList<>(classToMethods.keySet()); + Collections.sort(classes); + System.out.println(count); + Tuscan t = new Tuscan(); + t.main(classes.size()); + int[][] res = t.getMatrix(); + int nn = res.length; + List fullTestOrder = new ArrayList(); + List permClasses = new ArrayList(); + for (int i = 0; i < nn; i++) { + permClasses.add(classes.get(res[count][i])); + } + + for (String className : permClasses) { + fullTestOrder.addAll(classToMethods.get(className)); + } + count++; + return fullTestOrder; + } + + public List alphabeticalOrder() { + List classes = new ArrayList<>(classToMethods.keySet()); + Collections.sort(classes); + final List fullTestOrder = new ArrayList<>(); + for (String className : classes) { + fullTestOrder.addAll(classToMethods.get(className)); + } + return fullTestOrder; + } } From 8ed860aaa4b284d775e7748391a3ca06c889dcc4 Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 22 Jul 2022 15:35:24 +0300 Subject: [PATCH 03/40] detector factory --- .../detection/detectors/DetectorFactory.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 3946285c..9461c5f7 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,9 +1,11 @@ package edu.illinois.cs.dt.tools.detection.detectors; +import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; +import java.util.ArrayList; import java.util.List; public class DetectorFactory { @@ -15,6 +17,16 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return makeDetector(runner, baseDir, tests, Configuration.config().getProperty("dt.randomize.rounds", 20)); } + public static int getClassesSize(List tests) { + List classes = new ArrayList(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + } + return classes.size(); + } public static Detector makeDetector(final InstrumentingSmartRunner runner, final File baseDir, final List tests, final int rounds) { if (detectorType().startsWith("random")) { return new RandomDetector(detectorType(), baseDir, runner, rounds, tests); @@ -24,8 +36,12 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new OriginalDetector(runner, baseDir, rounds, tests); } else if (detectorType().equals("smart-shuffle")) { return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); + } else if (detectorType().equals("tuscan")){ + int n = getClassesSize(tests); + return new TuscanDetector(runner, baseDir, rounds > n ? n : rounds, detectorType(), tests); + } else if (detectorType().equals("alphabetical")) { + return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } - return new RandomDetector("random", baseDir, runner, rounds, tests); } } From 05c121377a0a6e4dd2d8e3301386d591dad60590 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 23 Jul 2022 17:56:54 +0300 Subject: [PATCH 04/40] fixed tuscan for 3 and 5 --- .../cs/dt/tools/detection/TestShuffler.java | 18 ++++---- .../detection/detectors/DetectorFactory.java | 3 ++ .../illinois/cs/dt/tools/utility/Tuscan.java | 42 ++++++++++++++----- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 2fcb8a70..1e1da6e2 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -199,21 +199,25 @@ private int permutations(final int accum, final Iterator> iterator, public List tuscanOrder(int count) { List classes = new ArrayList<>(classToMethods.keySet()); Collections.sort(classes); - System.out.println(count); Tuscan t = new Tuscan(); - t.main(classes.size()); + int n = classes.size(); + t.main(n); int[][] res = t.getMatrix(); - int nn = res.length; List fullTestOrder = new ArrayList(); List permClasses = new ArrayList(); - for (int i = 0; i < nn; i++) { - permClasses.add(classes.get(res[count][i])); + if(n == 3 || n == 5) { + for (int i = 0; i < res[count].length; i++) { + permClasses.add(classes.get(res[count][i])); + } + } else { + int nn = res.length-1; + for (int i = 0; i < nn; i++) { + permClasses.add(classes.get(res[count][i])); + } } - for (String className : permClasses) { fullTestOrder.addAll(classToMethods.get(className)); } - count++; return fullTestOrder; } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 9461c5f7..f633452a 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -38,6 +38,9 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); } else if (detectorType().equals("tuscan")){ int n = getClassesSize(tests); + if(n == 3 || n == 5) { + return new TuscanDetector(runner, baseDir, rounds > (n+1) ? (n+1) : rounds, detectorType(), tests); + } return new TuscanDetector(runner, baseDir, rounds > n ? n : rounds, detectorType(), tests); } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 0ae31376..479debda 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -4,11 +4,13 @@ public class Tuscan { public void main(int arg) { - int n = arg; - if (n == 3 || n == 5) { - throw new RuntimeException("Impossible to solve for n=3 or n=5."); + if (arg == 3) { + generateThree(); + } else if (arg == 5) { + generateFive(); + } else { + generateTuscanSquare(arg); } - generateTuscanSquare(n); } static int[][] r; static void helper(int[] a, int i) { @@ -115,13 +117,33 @@ static void generateTuscanSquare(int n) { System.arraycopy(t, 0, r[i], 0, n); } } + } + static void generateThree() { + int[][] t = { + { 0, 1, 2 }, + { 1, 0, 2 }, + { 2, 0 }, + { 2, 1 } + }; + r = new int[4][]; + for (int k = 0; k < 4; k++) { + r[k] = t[k].clone(); + } + } - // for (int i = 0; i < nn; i++){ - // System.out.print("["); - // for (int j = 0; j < nn; j++) - // System.out.print((r[i][j]+ (j==nn-1?"":", "))); - // System.out.println("]"); - // } + static void generateFive() { + int[][] t = { + { 0, 1, 2, 3, 4 }, + { 1, 0, 3, 2, 4 }, + { 4, 3, 0, 2, 1 }, + { 1, 4, 2, 0 }, + { 0, 4, 1, 3 }, + { 4, 0, 3, 1 } + }; + r = new int[6][]; + for (int k = 0; k < 6; k++) { + r[k] = t[k].clone(); + } } public int[][] getMatrix(){ From ba89c16da1233633cffad291c2d7b86250c85db9 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 23 Jul 2022 17:59:42 +0300 Subject: [PATCH 05/40] fixed tuscan for 3 and 5 --- .../cs/dt/tools/detection/detectors/DetectorFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index f633452a..62a69964 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -45,6 +45,7 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } + return new RandomDetector("random", baseDir, runner, rounds, tests); } } From 9bf746695123f42f075d6034d18d4d6cb10f4659 Mon Sep 17 00:00:00 2001 From: mmk Date: Mon, 25 Jul 2022 19:33:18 +0300 Subject: [PATCH 06/40] fixed tuscan orders for 3 & 5 --- .../illinois/cs/dt/tools/utility/Tuscan.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 479debda..e478ae73 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -119,12 +119,20 @@ static void generateTuscanSquare(int n) { } } static void generateThree() { + // int[][] t = { + // { 0, 1, 2 }, + // { 1, 0, 2 }, + // { 2, 0 }, + // { 2, 1 } + // }; + int[][] t = { { 0, 1, 2 }, { 1, 0, 2 }, - { 2, 0 }, - { 2, 1 } + { 2, 0, 1 }, + { 2, 1, 0} }; + r = new int[4][]; for (int k = 0; k < 4; k++) { r[k] = t[k].clone(); @@ -132,13 +140,21 @@ static void generateThree() { } static void generateFive() { + // int[][] t = { + // { 0, 1, 2, 3, 4 }, + // { 1, 0, 3, 2, 4 }, + // { 4, 3, 0, 2, 1 }, + // { 1, 4, 2, 0 }, + // { 0, 4, 1, 3 }, + // { 4, 0, 3, 1 } + // }; int[][] t = { { 0, 1, 2, 3, 4 }, { 1, 0, 3, 2, 4 }, { 4, 3, 0, 2, 1 }, - { 1, 4, 2, 0 }, - { 0, 4, 1, 3 }, - { 4, 0, 3, 1 } + { 1, 4, 2, 0, 3}, + { 0, 4, 1, 3, 2}, + { 4, 0, 3, 1, 2} }; r = new int[6][]; for (int k = 0; k < 6; k++) { From 128a48918d8c604c1f8ba8fd876fd6c263f5d4b7 Mon Sep 17 00:00:00 2001 From: mmk Date: Mon, 25 Jul 2022 19:40:41 +0300 Subject: [PATCH 07/40] fixed typo --- .../detection/detectors/AlphabeticalDetector.java | 11 +++++------ .../dt/tools/detection/detectors/TuscanDetector.java | 1 - 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index 93c26454..5aedb4e0 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -15,8 +15,8 @@ public class AlphabeticalDetector extends ExecutingDetector { final List tests; private TestRunResult origResult; - private TestRunResult lastTuscanResult; - private DetectionRound lastTuscanDetectionRound; + private TestRunResult lastAlphabeticalResult; + private DetectionRound lastAlphabeticalDetectionRound; private final TestShuffler testShuffler; public AlphabeticalDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { @@ -24,7 +24,6 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); this.origResult = DetectorUtil.originalResults(tests, runner); - // this.count = 0; if (runner instanceof InstrumentingSmartRunner) { addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); } else { @@ -36,9 +35,9 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r @Override public DetectionRound results() throws Exception { - lastTuscanResult = runList(testShuffler.alphabeticalOrder()); - lastTuscanDetectionRound = makeDts(origResult, lastTuscanResult); - return lastTuscanDetectionRound; + lastAlphabeticalResult = runList(testShuffler.alphabeticalOrder()); + lastAlphabeticalDetectionRound = makeDts(origResult, lastAlphabeticalResult); + return lastAlphabeticalDetectionRound; } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java index 0bc44102..793361bc 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java @@ -24,7 +24,6 @@ public TuscanDetector(final Runner runner, final File baseDir, final int rounds, this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); this.origResult = DetectorUtil.originalResults(tests, runner); - // this.count = 0; if (runner instanceof InstrumentingSmartRunner) { addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); } else { From 59f11bfff8ae0c81c87b554ffd939bd86793b1be Mon Sep 17 00:00:00 2001 From: Mahdi Date: Fri, 22 Jul 2022 15:24:17 +0300 Subject: [PATCH 08/40] squashed commits tuscan and alphabetical tuscan detector factory fixed tuscan for 3 and 5 fixed tuscan for 3 and 5 fixed tuscan orders for 3 & 5 --- .../cs/dt/tools/detection/TestShuffler.java | 36 ++++ .../detectors/AlphabeticalDetector.java | 43 +++++ .../detection/detectors/DetectorFactory.java | 22 ++- .../detection/detectors/TuscanDetector.java | 43 +++++ .../illinois/cs/dt/tools/utility/Tuscan.java | 168 ++++++++++++++++++ 5 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 42cc747a..1e1da6e2 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -10,6 +10,7 @@ import edu.illinois.cs.dt.tools.utility.Logger; import edu.illinois.cs.dt.tools.utility.MD5; import edu.illinois.cs.dt.tools.utility.PathManager; +import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.configuration.Configuration; import edu.illinois.cs.testrunner.data.results.TestRunResult; @@ -194,4 +195,39 @@ private int permutations(final int accum, final Iterator> iterator, } } } + + public List tuscanOrder(int count) { + List classes = new ArrayList<>(classToMethods.keySet()); + Collections.sort(classes); + Tuscan t = new Tuscan(); + int n = classes.size(); + t.main(n); + int[][] res = t.getMatrix(); + List fullTestOrder = new ArrayList(); + List permClasses = new ArrayList(); + if(n == 3 || n == 5) { + for (int i = 0; i < res[count].length; i++) { + permClasses.add(classes.get(res[count][i])); + } + } else { + int nn = res.length-1; + for (int i = 0; i < nn; i++) { + permClasses.add(classes.get(res[count][i])); + } + } + for (String className : permClasses) { + fullTestOrder.addAll(classToMethods.get(className)); + } + return fullTestOrder; + } + + public List alphabeticalOrder() { + List classes = new ArrayList<>(classToMethods.keySet()); + Collections.sort(classes); + final List fullTestOrder = new ArrayList<>(); + for (String className : classes) { + fullTestOrder.addAll(classToMethods.get(className)); + } + return fullTestOrder; + } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java new file mode 100644 index 00000000..5aedb4e0 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -0,0 +1,43 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class AlphabeticalDetector extends ExecutingDetector { + final List tests; + private TestRunResult origResult; + private TestRunResult lastAlphabeticalResult; + private DetectionRound lastAlphabeticalDetectionRound; + + private final TestShuffler testShuffler; + public AlphabeticalDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + lastAlphabeticalResult = runList(testShuffler.alphabeticalOrder()); + lastAlphabeticalDetectionRound = makeDts(origResult, lastAlphabeticalResult); + return lastAlphabeticalDetectionRound; + } + +} diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 3946285c..62a69964 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,9 +1,11 @@ package edu.illinois.cs.dt.tools.detection.detectors; +import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; +import java.util.ArrayList; import java.util.List; public class DetectorFactory { @@ -15,6 +17,16 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return makeDetector(runner, baseDir, tests, Configuration.config().getProperty("dt.randomize.rounds", 20)); } + public static int getClassesSize(List tests) { + List classes = new ArrayList(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + } + return classes.size(); + } public static Detector makeDetector(final InstrumentingSmartRunner runner, final File baseDir, final List tests, final int rounds) { if (detectorType().startsWith("random")) { return new RandomDetector(detectorType(), baseDir, runner, rounds, tests); @@ -24,8 +36,16 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new OriginalDetector(runner, baseDir, rounds, tests); } else if (detectorType().equals("smart-shuffle")) { return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); + } else if (detectorType().equals("tuscan")){ + int n = getClassesSize(tests); + if(n == 3 || n == 5) { + return new TuscanDetector(runner, baseDir, rounds > (n+1) ? (n+1) : rounds, detectorType(), tests); + } + return new TuscanDetector(runner, baseDir, rounds > n ? n : rounds, detectorType(), tests); + } else if (detectorType().equals("alphabetical")) { + return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } - + return new RandomDetector("random", baseDir, runner, rounds, tests); } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java new file mode 100644 index 00000000..793361bc --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java @@ -0,0 +1,43 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class TuscanDetector extends ExecutingDetector { + final List tests; + private TestRunResult origResult; + private TestRunResult lastTuscanResult; + private DetectionRound lastTuscanDetectionRound; + + private final TestShuffler testShuffler; + public TuscanDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + lastTuscanResult = runList(testShuffler.tuscanOrder(absoluteRound.get())); + lastTuscanDetectionRound = makeDts(origResult, lastTuscanResult); + return lastTuscanDetectionRound; + } + +} diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java new file mode 100644 index 00000000..e478ae73 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -0,0 +1,168 @@ +package edu.illinois.cs.dt.tools.utility; + +import scala.annotation.meta.getter; + +public class Tuscan { + public void main(int arg) { + if (arg == 3) { + generateThree(); + } else if (arg == 5) { + generateFive(); + } else { + generateTuscanSquare(arg); + } + } + static int[][] r; + static void helper(int[] a, int i) { + System.arraycopy(a, 0, r[i], 0, a.length); + } + static void generateTuscanSquare(int n) { + int nn = n; + while((n-1) % 4 == 0 && n != 1 && n != 9) n = (n-1)/2+1; + + r = new int[nn][]; + for (int i = 0; i < nn; i++) { + r[i] = new int[nn+1]; + } + + if (n % 2 == 0) { + // https://mathoverflow.net/questions/60856/hamilton-paths-in-k-2n/60859#60859 + int[] a = new int[n]; + for (int i = 0; i < n; i += 2) { + a[i] = i / 2; + a[i+1] = n - 1 - a[i]; + } + helper(a, 0); + for (int j = 1; j < n; j++) { + for (int i = 0; i < n; i++) { + a[i] = (a[i] + 1) % n; + } + helper(a, j); + } + } else if (n % 4 == 3) { + int k = (n - 3) / 4; + int[] b = new int[n]; + for (int i = 0; i < n - 1; i++) { + int p = (i == 0) ? 1 : + ((i == k + 1) ? 4*k + 2 : + ((i == 2*k + 2) ? 3 : + ((i == 3*k + 2) ? 4*k : 2*k))); + int[] a = new int[n]; + for (int j = 0; j < n; j++) { + a[(j < p) ? n+j-p : j-p] = (j == 0) ? (n - 1) : (i + ((j % 2 == 0) ? (j / 2) : (n - 1 - (j - 1) / 2))) % (n - 1); + } + b[a[n-1]] = a[0]; + helper(a, i); + } + int[] t = new int[n]; + t[0] = n - 1; + for (int i = 1; i < n; i++) { + t[i] = b[t[i-1]]; + } + helper(t, n-1); + } else if (n == 9) { + int[][] t = {{0,1,7,2,6,3,5,4,8}, + {3,7,4,6,5,8,1,2,0}, + {1,4,0,5,7,6,8,2,3}, + {6,0,7,8,3,4,2,5,1}, + {2,7,1,0,8,4,5,3,6}, + {7,3,0,2,1,8,5,6,4}, + {5,0,4,1,3,2,8,6,7}, + {4,3,8,7,0,6,1,5,2}, + {8,0,3,1,6,2,4,7,5}}; + for (int i = 0; i < 9; i++) { + helper(t[i], i); + } + } + else assert(false); + + while (nn != n){ + // n + 1 == 4*m - 2 + // https://www.sciencedirect.com/science/article/pii/0095895680900441 + + n = n * 2 - 1; + + int h = (n + 1) / 2; + + for (int i = 0; i < h; i++) { + for (int j = 0; j < h; j++) { + r[i][n-j] = r[i][j] + h; + } + // System.out.println(java.util.Arrays.toString(r[i])); + } + for (int i = h; i < n; i++) { + /* + for (int j = 0; j < n+1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (n - (j - 1) / 2))) % h; + } + */ + for (int j = 0; j < h - 1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (h - 2 - (j - 1) / 2))) % (h - 1); + } + r[i][h-1] = h-1; + for (int j = h; j < n + 1; j++) { + r[i][j] = ((j % 2 == 0) ? 0 : h) + r[i][j-h] % h; + } + // System.out.println(java.util.Arrays.toString(r[i])); + } + for (int i = 0; i < n; i++) { + int l = 0; + for (; l < n; l++) { + if (r[i][l] == n) break; + } + int[] t = new int[n]; + System.arraycopy(r[i], l+1, t, 0, n-l); + System.arraycopy(r[i], 0, t, n-l, l); + + System.arraycopy(t, 0, r[i], 0, n); + } + } + } + static void generateThree() { + // int[][] t = { + // { 0, 1, 2 }, + // { 1, 0, 2 }, + // { 2, 0 }, + // { 2, 1 } + // }; + + int[][] t = { + { 0, 1, 2 }, + { 1, 0, 2 }, + { 2, 0, 1 }, + { 2, 1, 0} + }; + + r = new int[4][]; + for (int k = 0; k < 4; k++) { + r[k] = t[k].clone(); + } + } + + static void generateFive() { + // int[][] t = { + // { 0, 1, 2, 3, 4 }, + // { 1, 0, 3, 2, 4 }, + // { 4, 3, 0, 2, 1 }, + // { 1, 4, 2, 0 }, + // { 0, 4, 1, 3 }, + // { 4, 0, 3, 1 } + // }; + int[][] t = { + { 0, 1, 2, 3, 4 }, + { 1, 0, 3, 2, 4 }, + { 4, 3, 0, 2, 1 }, + { 1, 4, 2, 0, 3}, + { 0, 4, 1, 3, 2}, + { 4, 0, 3, 1, 2} + }; + r = new int[6][]; + for (int k = 0; k < 6; k++) { + r[k] = t[k].clone(); + } + } + + public int[][] getMatrix(){ + return r; + } +} From c54ee57cc6bfe0482d90741e71ffc571ecba595a Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 27 Jul 2022 10:50:36 +0300 Subject: [PATCH 09/40] fixed whitespaces --- .../cs/dt/tools/detection/TestShuffler.java | 4 +-- .../detection/detectors/DetectorFactory.java | 4 +-- .../illinois/cs/dt/tools/utility/Tuscan.java | 26 ++++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 1e1da6e2..f599c519 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -205,12 +205,12 @@ public List tuscanOrder(int count) { int[][] res = t.getMatrix(); List fullTestOrder = new ArrayList(); List permClasses = new ArrayList(); - if(n == 3 || n == 5) { + if (n == 3 || n == 5) { for (int i = 0; i < res[count].length; i++) { permClasses.add(classes.get(res[count][i])); } } else { - int nn = res.length-1; + int nn = res.length - 1; for (int i = 0; i < nn; i++) { permClasses.add(classes.get(res[count][i])); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 62a69964..d12e3c67 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -27,6 +27,7 @@ public static int getClassesSize(List tests) { } return classes.size(); } + public static Detector makeDetector(final InstrumentingSmartRunner runner, final File baseDir, final List tests, final int rounds) { if (detectorType().startsWith("random")) { return new RandomDetector(detectorType(), baseDir, runner, rounds, tests); @@ -38,14 +39,13 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); } else if (detectorType().equals("tuscan")){ int n = getClassesSize(tests); - if(n == 3 || n == 5) { + if (n == 3 || n == 5) { return new TuscanDetector(runner, baseDir, rounds > (n+1) ? (n+1) : rounds, detectorType(), tests); } return new TuscanDetector(runner, baseDir, rounds > n ? n : rounds, detectorType(), tests); } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } - return new RandomDetector("random", baseDir, runner, rounds, tests); } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index e478ae73..3f784406 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -5,11 +5,17 @@ public class Tuscan { public void main(int arg) { if (arg == 3) { + generateThree(); + } else if (arg == 5) { + generateFive(); + } else { + generateTuscanSquare(arg); + } } static int[][] r; @@ -18,11 +24,11 @@ static void helper(int[] a, int i) { } static void generateTuscanSquare(int n) { int nn = n; - while((n-1) % 4 == 0 && n != 1 && n != 9) n = (n-1)/2+1; + while((n - 1) % 4 == 0 && n != 1 && n != 9) n = (n - 1) / 2 + 1; r = new int[nn][]; for (int i = 0; i < nn; i++) { - r[i] = new int[nn+1]; + r[i] = new int[nn + 1]; } if (n % 2 == 0) { @@ -49,17 +55,17 @@ static void generateTuscanSquare(int n) { ((i == 3*k + 2) ? 4*k : 2*k))); int[] a = new int[n]; for (int j = 0; j < n; j++) { - a[(j < p) ? n+j-p : j-p] = (j == 0) ? (n - 1) : (i + ((j % 2 == 0) ? (j / 2) : (n - 1 - (j - 1) / 2))) % (n - 1); + a[(j < p) ? n + j - p : j - p] = (j == 0) ? (n - 1) : (i + ((j % 2 == 0) ? (j / 2) : (n - 1 - (j - 1) / 2))) % (n - 1); } - b[a[n-1]] = a[0]; + b[a[n - 1]] = a[0]; helper(a, i); } int[] t = new int[n]; t[0] = n - 1; for (int i = 1; i < n; i++) { - t[i] = b[t[i-1]]; + t[i] = b[t[i - 1]]; } - helper(t, n-1); + helper(t, n - 1); } else if (n == 9) { int[][] t = {{0,1,7,2,6,3,5,4,8}, {3,7,4,6,5,8,1,2,0}, @@ -130,7 +136,7 @@ static void generateThree() { { 0, 1, 2 }, { 1, 0, 2 }, { 2, 0, 1 }, - { 2, 1, 0} + { 2, 1, 0 } }; r = new int[4][]; @@ -152,9 +158,9 @@ static void generateFive() { { 0, 1, 2, 3, 4 }, { 1, 0, 3, 2, 4 }, { 4, 3, 0, 2, 1 }, - { 1, 4, 2, 0, 3}, - { 0, 4, 1, 3, 2}, - { 4, 0, 3, 1, 2} + { 1, 4, 2, 0, 3 }, + { 0, 4, 1, 3, 2 }, + { 4, 0, 3, 1, 2 } }; r = new int[6][]; for (int k = 0; k < 6; k++) { From 72a0e415cdc549bb97f180b7bad944e26a2adf37 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 27 Jul 2022 11:39:30 +0300 Subject: [PATCH 10/40] fixed Tuscan.java --- .../cs/dt/tools/detection/TestShuffler.java | 6 +-- .../illinois/cs/dt/tools/utility/Tuscan.java | 53 ++++++++----------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index f599c519..7839ed37 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -199,10 +199,8 @@ private int permutations(final int accum, final Iterator> iterator, public List tuscanOrder(int count) { List classes = new ArrayList<>(classToMethods.keySet()); Collections.sort(classes); - Tuscan t = new Tuscan(); int n = classes.size(); - t.main(n); - int[][] res = t.getMatrix(); + int[][] res = Tuscan.generateTuscanPermutations(n); List fullTestOrder = new ArrayList(); List permClasses = new ArrayList(); if (n == 3 || n == 5) { @@ -210,7 +208,7 @@ public List tuscanOrder(int count) { permClasses.add(classes.get(res[count][i])); } } else { - int nn = res.length - 1; + int nn = res.length; for (int i = 0; i < nn; i++) { permClasses.add(classes.get(res[count][i])); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 3f784406..e362cef5 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -3,7 +3,7 @@ import scala.annotation.meta.getter; public class Tuscan { - public void main(int arg) { + public static int[][] generateTuscanPermutations(int arg) { if (arg == 3) { generateThree(); @@ -17,6 +17,7 @@ public void main(int arg) { generateTuscanSquare(arg); } + return r; } static int[][] r; static void helper(int[] a, int i) { @@ -36,7 +37,7 @@ static void generateTuscanSquare(int n) { int[] a = new int[n]; for (int i = 0; i < n; i += 2) { a[i] = i / 2; - a[i+1] = n - 1 - a[i]; + a[i + 1] = n - 1 - a[i]; } helper(a, 0); for (int j = 1; j < n; j++) { @@ -67,15 +68,17 @@ static void generateTuscanSquare(int n) { } helper(t, n - 1); } else if (n == 9) { - int[][] t = {{0,1,7,2,6,3,5,4,8}, - {3,7,4,6,5,8,1,2,0}, - {1,4,0,5,7,6,8,2,3}, - {6,0,7,8,3,4,2,5,1}, - {2,7,1,0,8,4,5,3,6}, - {7,3,0,2,1,8,5,6,4}, - {5,0,4,1,3,2,8,6,7}, - {4,3,8,7,0,6,1,5,2}, - {8,0,3,1,6,2,4,7,5}}; + int[][] t = { + { 0, 1, 7, 2, 6, 3, 5, 4, 8 }, + { 3, 7, 4, 6, 5, 8, 1, 2, 0 }, + { 1, 4, 0, 5, 7, 6, 8, 2, 3 }, + { 6, 0, 7, 8, 3, 4, 2, 5, 1 }, + { 2, 7, 1, 0, 8, 4, 5, 3, 6 }, + { 7, 3, 0, 2, 1, 8, 5, 6, 4 }, + { 5, 0, 4, 1, 3, 2, 8, 6, 7 }, + { 4, 3, 8, 7, 0, 6, 1, 5, 2 }, + { 8, 0, 3, 1, 6, 2, 4, 7, 5 } + }; for (int i = 0; i < 9; i++) { helper(t[i], i); } @@ -92,9 +95,8 @@ static void generateTuscanSquare(int n) { for (int i = 0; i < h; i++) { for (int j = 0; j < h; j++) { - r[i][n-j] = r[i][j] + h; + r[i][n - j] = r[i][j] + h; } - // System.out.println(java.util.Arrays.toString(r[i])); } for (int i = h; i < n; i++) { /* @@ -109,7 +111,6 @@ static void generateTuscanSquare(int n) { for (int j = h; j < n + 1; j++) { r[i][j] = ((j % 2 == 0) ? 0 : h) + r[i][j-h] % h; } - // System.out.println(java.util.Arrays.toString(r[i])); } for (int i = 0; i < n; i++) { int l = 0; @@ -117,8 +118,8 @@ static void generateTuscanSquare(int n) { if (r[i][l] == n) break; } int[] t = new int[n]; - System.arraycopy(r[i], l+1, t, 0, n-l); - System.arraycopy(r[i], 0, t, n-l, l); + System.arraycopy(r[i], l+1, t, 0, n - l); + System.arraycopy(r[i], 0, t, n - l, l); System.arraycopy(t, 0, r[i], 0, n); } @@ -131,20 +132,14 @@ static void generateThree() { // { 2, 0 }, // { 2, 1 } // }; - int[][] t = { { 0, 1, 2 }, { 1, 0, 2 }, { 2, 0, 1 }, { 2, 1, 0 } }; - - r = new int[4][]; - for (int k = 0; k < 4; k++) { - r[k] = t[k].clone(); - } + r = t; } - static void generateFive() { // int[][] t = { // { 0, 1, 2, 3, 4 }, @@ -162,13 +157,9 @@ static void generateFive() { { 0, 4, 1, 3, 2 }, { 4, 0, 3, 1, 2 } }; - r = new int[6][]; - for (int k = 0; k < 6; k++) { - r[k] = t[k].clone(); - } - } - - public int[][] getMatrix(){ - return r; + r = t; } + // public int[][] getMatrix(){ + // return r; + // } } From bf1cc282e8efc8270171d2d43142b88ef3a70abe Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 27 Jul 2022 11:44:23 +0300 Subject: [PATCH 11/40] fixed alphabeticalDetector.java --- .../dt/tools/detection/detectors/AlphabeticalDetector.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index 5aedb4e0..cd02f41f 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -15,8 +15,6 @@ public class AlphabeticalDetector extends ExecutingDetector { final List tests; private TestRunResult origResult; - private TestRunResult lastAlphabeticalResult; - private DetectionRound lastAlphabeticalDetectionRound; private final TestShuffler testShuffler; public AlphabeticalDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { @@ -35,9 +33,7 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r @Override public DetectionRound results() throws Exception { - lastAlphabeticalResult = runList(testShuffler.alphabeticalOrder()); - lastAlphabeticalDetectionRound = makeDts(origResult, lastAlphabeticalResult); - return lastAlphabeticalDetectionRound; + return makeDts(origResult, runList(testShuffler.alphabeticalOrder())); } } From b2a9236d581f809471a108c71f31142832476da9 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 27 Jul 2022 12:10:31 +0300 Subject: [PATCH 12/40] fixed DetectorFactory.java --- .../detectors/AlphabeticalDetector.java | 1 + .../detection/detectors/DetectorFactory.java | 19 +------------------ .../detection/detectors/TuscanDetector.java | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index cd02f41f..4d57ac9a 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -17,6 +17,7 @@ public class AlphabeticalDetector extends ExecutingDetector { private TestRunResult origResult; private final TestShuffler testShuffler; + public AlphabeticalDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { super(runner, baseDir, rounds, type); this.tests = tests; diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index d12e3c67..ab2a2ddb 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,11 +1,9 @@ package edu.illinois.cs.dt.tools.detection.detectors; -import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; -import java.util.ArrayList; import java.util.List; public class DetectorFactory { @@ -17,17 +15,6 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return makeDetector(runner, baseDir, tests, Configuration.config().getProperty("dt.randomize.rounds", 20)); } - public static int getClassesSize(List tests) { - List classes = new ArrayList(); - for (final String test : tests) { - final String className = TestShuffler.className(test); - if (!classes.contains(className)) { - classes.add(className); - } - } - return classes.size(); - } - public static Detector makeDetector(final InstrumentingSmartRunner runner, final File baseDir, final List tests, final int rounds) { if (detectorType().startsWith("random")) { return new RandomDetector(detectorType(), baseDir, runner, rounds, tests); @@ -38,11 +25,7 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final } else if (detectorType().equals("smart-shuffle")) { return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); } else if (detectorType().equals("tuscan")){ - int n = getClassesSize(tests); - if (n == 3 || n == 5) { - return new TuscanDetector(runner, baseDir, rounds > (n+1) ? (n+1) : rounds, detectorType(), tests); - } - return new TuscanDetector(runner, baseDir, rounds > n ? n : rounds, detectorType(), tests); + return new TuscanDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java index 793361bc..b8edb175 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java @@ -1,6 +1,7 @@ package edu.illinois.cs.dt.tools.detection.detectors; import java.io.File; +import java.util.ArrayList; import java.util.List; import edu.illinois.cs.dt.tools.detection.DetectionRound; @@ -19,8 +20,26 @@ public class TuscanDetector extends ExecutingDetector { private DetectionRound lastTuscanDetectionRound; private final TestShuffler testShuffler; + + public static int getClassesSize(List tests) { + List classes = new ArrayList(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + } + return classes.size(); + } + public TuscanDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { super(runner, baseDir, rounds, type); + int n = getClassesSize(tests); + if (n == 3 || n == 5) { + if(this.rounds > n) this.rounds = n + 1; + } else { + if(this.rounds > n) this.rounds = n; + } this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); this.origResult = DetectorUtil.originalResults(tests, runner); From a29ea16fd450beb0196823a4175787b83a674b70 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 27 Jul 2022 12:20:16 +0300 Subject: [PATCH 13/40] fixed whitespaces --- .../dt/tools/detection/detectors/TuscanDetector.java | 10 +++++----- .../java/edu/illinois/cs/dt/tools/utility/Tuscan.java | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java index b8edb175..5bb7014d 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java @@ -35,11 +35,11 @@ public static int getClassesSize(List tests) { public TuscanDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { super(runner, baseDir, rounds, type); int n = getClassesSize(tests); - if (n == 3 || n == 5) { - if(this.rounds > n) this.rounds = n + 1; - } else { - if(this.rounds > n) this.rounds = n; - } + if (n == 3 || n == 5) { + if(this.rounds > n) this.rounds = n + 1; + } else { + if(this.rounds > n) this.rounds = n; + } this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); this.origResult = DetectorUtil.originalResults(tests, runner); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index e362cef5..6d4f4573 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -1,7 +1,5 @@ package edu.illinois.cs.dt.tools.utility; -import scala.annotation.meta.getter; - public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { if (arg == 3) { @@ -159,7 +157,4 @@ static void generateFive() { }; r = t; } - // public int[][] getMatrix(){ - // return r; - // } } From 9c305ec5c4b62c9a753908aaf5228ba7f1879883 Mon Sep 17 00:00:00 2001 From: mmk Date: Thu, 28 Jul 2022 15:34:38 +0300 Subject: [PATCH 14/40] fixed issues mentioned in PR review --- .../cs/dt/tools/detection/TestShuffler.java | 43 ++++----- .../detectors/AlphabeticalDetector.java | 5 +- .../detection/detectors/DetectorFactory.java | 2 +- ...ctor.java => TuscanOnlyClassDetector.java} | 21 ++--- .../illinois/cs/dt/tools/utility/Tuscan.java | 93 ++++++++----------- 5 files changed, 73 insertions(+), 91 deletions(-) rename idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/{TuscanDetector.java => TuscanOnlyClassDetector.java} (74%) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 7839ed37..9563ec85 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -196,36 +196,31 @@ private int permutations(final int accum, final Iterator> iterator, } } - public List tuscanOrder(int count) { + public List alphabeticalAndTuscanOrder(int count, boolean isTuscan) { List classes = new ArrayList<>(classToMethods.keySet()); Collections.sort(classes); - int n = classes.size(); - int[][] res = Tuscan.generateTuscanPermutations(n); - List fullTestOrder = new ArrayList(); - List permClasses = new ArrayList(); - if (n == 3 || n == 5) { - for (int i = 0; i < res[count].length; i++) { - permClasses.add(classes.get(res[count][i])); + final List fullTestOrder = new ArrayList<>(); + if (isTuscan) { + int n = classes.size(); + int[][] res = Tuscan.generateTuscanPermutations(n); + List permClasses = new ArrayList(); + if (n == 3 || n == 5) { + for (int i = 0; i < res[count].length; i++) { + permClasses.add(classes.get(res[count][i])); + } + } else { + for (int i = 0; i < res[count].length - 1; i++) { + permClasses.add(classes.get(res[count][i])); + } + } + for (String className : permClasses) { + fullTestOrder.addAll(classToMethods.get(className)); } } else { - int nn = res.length; - for (int i = 0; i < nn; i++) { - permClasses.add(classes.get(res[count][i])); + for (String className : classes) { + fullTestOrder.addAll(classToMethods.get(className)); } } - for (String className : permClasses) { - fullTestOrder.addAll(classToMethods.get(className)); - } - return fullTestOrder; - } - - public List alphabeticalOrder() { - List classes = new ArrayList<>(classToMethods.keySet()); - Collections.sort(classes); - final List fullTestOrder = new ArrayList<>(); - for (String className : classes) { - fullTestOrder.addAll(classToMethods.get(className)); - } return fullTestOrder; } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index 4d57ac9a..5a859362 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -13,7 +13,7 @@ import edu.illinois.cs.testrunner.runner.Runner; public class AlphabeticalDetector extends ExecutingDetector { - final List tests; + private final List tests; private TestRunResult origResult; private final TestShuffler testShuffler; @@ -28,13 +28,12 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r } else { addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); } - addFilter(new UniqueFilter()); } @Override public DetectionRound results() throws Exception { - return makeDts(origResult, runList(testShuffler.alphabeticalOrder())); + return makeDts(origResult, runList(testShuffler.alphabeticalAndTuscanOrder(absoluteRound.get(), false))); } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index ab2a2ddb..ebc96060 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -25,7 +25,7 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final } else if (detectorType().equals("smart-shuffle")) { return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); } else if (detectorType().equals("tuscan")){ - return new TuscanDetector(runner, baseDir, rounds, detectorType(), tests); + return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java similarity index 74% rename from idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java rename to idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java index 5bb7014d..727164ca 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java @@ -13,11 +13,9 @@ import edu.illinois.cs.testrunner.data.results.TestRunResult; import edu.illinois.cs.testrunner.runner.Runner; -public class TuscanDetector extends ExecutingDetector { - final List tests; +public class TuscanOnlyClassDetector extends ExecutingDetector { + private final List tests; private TestRunResult origResult; - private TestRunResult lastTuscanResult; - private DetectionRound lastTuscanDetectionRound; private final TestShuffler testShuffler; @@ -32,13 +30,17 @@ public static int getClassesSize(List tests) { return classes.size(); } - public TuscanDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + public TuscanOnlyClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { super(runner, baseDir, rounds, type); int n = getClassesSize(tests); if (n == 3 || n == 5) { - if(this.rounds > n) this.rounds = n + 1; + if (this.rounds > n) { + this.rounds = n + 1; + } } else { - if(this.rounds > n) this.rounds = n; + if (this.rounds > n) { + this.rounds = n; + } } this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); @@ -48,15 +50,12 @@ public TuscanDetector(final Runner runner, final File baseDir, final int rounds, } else { addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); } - addFilter(new UniqueFilter()); } @Override public DetectionRound results() throws Exception { - lastTuscanResult = runList(testShuffler.tuscanOrder(absoluteRound.get())); - lastTuscanDetectionRound = makeDts(origResult, lastTuscanResult); - return lastTuscanDetectionRound; + return makeDts(origResult, runList(testShuffler.alphabeticalAndTuscanOrder(absoluteRound.get(), true))); } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 6d4f4573..5f877202 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -3,32 +3,29 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { if (arg == 3) { - generateThree(); - } else if (arg == 5) { - generateFive(); - } else { - generateTuscanSquare(arg); - } return r; } - static int[][] r; - static void helper(int[] a, int i) { - System.arraycopy(a, 0, r[i], 0, a.length); + private static int[][] r; + + private static void helper(int[] a, int i) { + System.arraycopy(a, 0, r[i], 0, a.length); } - static void generateTuscanSquare(int n) { - int nn = n; - while((n - 1) % 4 == 0 && n != 1 && n != 9) n = (n - 1) / 2 + 1; - r = new int[nn][]; - for (int i = 0; i < nn; i++) { - r[i] = new int[nn + 1]; - } + private static void generateTuscanSquare(int n) { + int nn = n; + while((n - 1) % 4 == 0 && n != 1 && n != 9){ + n = (n - 1) / 2 + 1; + } + r = new int[nn][]; + for (int i = 0; i < nn; i++) { + r[i] = new int[nn + 1]; + } if (n % 2 == 0) { // https://mathoverflow.net/questions/60856/hamilton-paths-in-k-2n/60859#60859 @@ -49,9 +46,9 @@ static void generateTuscanSquare(int n) { int[] b = new int[n]; for (int i = 0; i < n - 1; i++) { int p = (i == 0) ? 1 : - ((i == k + 1) ? 4*k + 2 : - ((i == 2*k + 2) ? 3 : - ((i == 3*k + 2) ? 4*k : 2*k))); + ((i == k + 1) ? 4 * k + 2 : + ((i == 2 * k + 2) ? 3 : + ((i == 3 * k + 2) ? 4 * k : 2 * k))); int[] a = new int[n]; for (int j = 0; j < n; j++) { a[(j < p) ? n + j - p : j - p] = (j == 0) ? (n - 1) : (i + ((j % 2 == 0) ? (j / 2) : (n - 1 - (j - 1) / 2))) % (n - 1); @@ -84,24 +81,15 @@ static void generateTuscanSquare(int n) { else assert(false); while (nn != n){ - // n + 1 == 4*m - 2 // https://www.sciencedirect.com/science/article/pii/0095895680900441 - - n = n * 2 - 1; - + n = n * 2 - 1; int h = (n + 1) / 2; - for (int i = 0; i < h; i++) { for (int j = 0; j < h; j++) { r[i][n - j] = r[i][j] + h; } } for (int i = h; i < n; i++) { - /* - for (int j = 0; j < n+1; j++) { - r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (n - (j - 1) / 2))) % h; - } - */ for (int j = 0; j < h - 1; j++) { r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (h - 2 - (j - 1) / 2))) % (h - 1); } @@ -118,43 +106,44 @@ static void generateTuscanSquare(int n) { int[] t = new int[n]; System.arraycopy(r[i], l+1, t, 0, n - l); System.arraycopy(r[i], 0, t, n - l, l); - - System.arraycopy(t, 0, r[i], 0, n); + System.arraycopy(t, 0, r[i], 0, n); } } } - static void generateThree() { - // int[][] t = { - // { 0, 1, 2 }, - // { 1, 0, 2 }, - // { 2, 0 }, - // { 2, 1 } - // }; + + private static void generateThree() { int[][] t = { { 0, 1, 2 }, { 1, 0, 2 }, - { 2, 0, 1 }, - { 2, 1, 0 } + { 2, 0 }, + { 2, 1 } }; - r = t; - } - static void generateFive() { // int[][] t = { - // { 0, 1, 2, 3, 4 }, - // { 1, 0, 3, 2, 4 }, - // { 4, 3, 0, 2, 1 }, - // { 1, 4, 2, 0 }, - // { 0, 4, 1, 3 }, - // { 4, 0, 3, 1 } + // { 0, 1, 2 }, + // { 1, 0, 2 }, + // { 2, 0, 1 }, + // { 2, 1, 0 } // }; + r = t; + } + + private static void generateFive() { int[][] t = { { 0, 1, 2, 3, 4 }, { 1, 0, 3, 2, 4 }, { 4, 3, 0, 2, 1 }, - { 1, 4, 2, 0, 3 }, - { 0, 4, 1, 3, 2 }, - { 4, 0, 3, 1, 2 } + { 1, 4, 2, 0 }, + { 0, 4, 1, 3 }, + { 4, 0, 3, 1 } }; + // int[][] t = { + // { 0, 1, 2, 3, 4 }, + // { 1, 0, 3, 2, 4 }, + // { 4, 3, 0, 2, 1 }, + // { 1, 4, 2, 0, 3 }, + // { 0, 4, 1, 3, 2 }, + // { 4, 0, 3, 1, 2 } + // }; r = t; } } From 259518ce4a62640276aa819bd4917be767a1a6be Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 3 Aug 2022 18:00:33 +0300 Subject: [PATCH 15/40] TuscanIntraClass --- .../cs/dt/tools/detection/TestShuffler.java | 69 ++++++++++++++- .../detection/detectors/DetectorFactory.java | 2 + .../detectors/TuscanIntraClassDetector.java | 83 +++++++++++++++++++ 3 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 9563ec85..df19c555 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -34,7 +34,8 @@ public static String className(final String testName) { } private final HashMap> classToMethods; - + private static int row = 0; + private static int selectClass = 0; private final String type; private final List tests; private final Set alreadySeenOrders = new HashSet<>(); @@ -223,4 +224,68 @@ public List alphabeticalAndTuscanOrder(int count, boolean isTuscan) { } return fullTestOrder; } -} + + public List tuscanIntraClassOrder(int round) { + List classes = new ArrayList<>(classToMethods.keySet()); + HashMap classToPermutations = new HashMap(); + Collections.sort(classes); + final List fullTestOrder = new ArrayList<>(); + int n = classes.size(); // n is number of classes + int[][] classOrdering = Tuscan.generateTuscanPermutations(n); + for (String className : classes) { + int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); + classToPermutations.put(className, methodPermuation); + } + HashMap> newClassToMethods = new HashMap>(); + List permClasses = new ArrayList(); + int classRound = round; + if (classOrdering.length <= classRound) { + classRound = round - classOrdering.length; + } + if (n == 3 || n == 5) { + for (int i = 0; i < classOrdering[classRound].length; i++) { + permClasses.add(classes.get(classOrdering[classRound][i])); + } + } else { + for (int i = 0; i < classOrdering[classRound].length - 1; i++) { + permClasses.add(classes.get(classOrdering[classRound][i])); + } + } + for (String className : permClasses) { + List methods = classToMethods.get(className); + List permMethods = new ArrayList(); + int[][] currMethodOrdering = classToPermutations.get(className); + // System.out.println(className); + n = methods.size(); + // System.out.println(n); + int methodRound = round; + // System.out.println("methodRound: " + methodRound); + // for (int j = 0; j < currMethodOrdering.length; j++) { + // for (int k = 0; k < currMethodOrdering[j].length; k++) { + // System.out.print(currMethodOrdering[j][k]); + // } + // System.out.println(); + // } + if ((currMethodOrdering.length - 1) < methodRound) { + methodRound = round - currMethodOrdering.length; + } + // System.out.println("After methodRound: " + methodRound); + // System.out.println("After currMethod.length: " + currMethodOrdering.length); + if (n == 3 || n == 5) { + for (int i = 0; i < currMethodOrdering[methodRound].length; i++) { + permMethods.add(methods.get(currMethodOrdering[methodRound][i])); + } + } else { + for (int i = 0; i < currMethodOrdering[methodRound].length - 1; i++) { + permMethods.add(methods.get(currMethodOrdering[methodRound][i])); + } + } + newClassToMethods.put(className, permMethods); + } + + for (String className : permClasses) { + fullTestOrder.addAll(newClassToMethods.get(className)); + } + return fullTestOrder; + } +} \ No newline at end of file diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index ebc96060..27383b90 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -28,6 +28,8 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); + } else if (detectorType().equals("tuscan-intra-class")) { + return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); } return new RandomDetector("random", baseDir, runner, rounds, tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java new file mode 100644 index 00000000..c57608d3 --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java @@ -0,0 +1,83 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class TuscanIntraClassDetector extends ExecutingDetector { + private final List tests; + private TestRunResult origResult; + + private final HashMap> classToMethods; + private final TestShuffler testShuffler; + + public static int getClassesSize(List tests) { + List classes = new ArrayList(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + } + return classes.size(); + } + + public TuscanIntraClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + // int n = getClassesSize(tests); + // if (n == 3 || n == 5) { + // if (this.rounds > n) { + // this.rounds = n + 1; + // } + // } else { + // if (this.rounds > n) { + // this.rounds = n; + // } + // } + classToMethods = new HashMap<>(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classToMethods.containsKey(className)) { + classToMethods.put(className, new ArrayList<>()); + } + classToMethods.get(className).add(test); + } + int classSize = classToMethods.keySet().size(); + int maxMethodSize = 0; + for (String className : classToMethods.keySet()) { + int nn = classToMethods.get(className).size(); + if(maxMethodSize < nn) { + maxMethodSize = nn; + } + } + if (classSize > maxMethodSize) { + this.rounds = classSize; + } else { + this.rounds = maxMethodSize; + } + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + return makeDts(origResult, runList(testShuffler.tuscanIntraClassOrder(absoluteRound.get()))); + } +} From 9d726a3e6c072fa726c4f4721f6ce2ad3bfe323f Mon Sep 17 00:00:00 2001 From: mmk Date: Fri, 5 Aug 2022 13:21:41 +0300 Subject: [PATCH 16/40] update tuscanIntraClassOrder() --- .../illinois/cs/dt/tools/detection/TestShuffler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index df19c555..9d3932ae 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -239,15 +239,15 @@ public List tuscanIntraClassOrder(int round) { HashMap> newClassToMethods = new HashMap>(); List permClasses = new ArrayList(); int classRound = round; - if (classOrdering.length <= classRound) { - classRound = round - classOrdering.length; + while ((classOrdering.length - 1) < classRound) { + classRound -= classOrdering.length; } if (n == 3 || n == 5) { for (int i = 0; i < classOrdering[classRound].length; i++) { permClasses.add(classes.get(classOrdering[classRound][i])); } } else { - for (int i = 0; i < classOrdering[classRound].length - 1; i++) { + for (int i = 0; i < classOrdering[classRound].length - 1; i++) { // {0, 1, 0} {1, 0, 0} permClasses.add(classes.get(classOrdering[classRound][i])); } } @@ -266,8 +266,8 @@ public List tuscanIntraClassOrder(int round) { // } // System.out.println(); // } - if ((currMethodOrdering.length - 1) < methodRound) { - methodRound = round - currMethodOrdering.length; + while((currMethodOrdering.length - 1) < methodRound) { + methodRound -= currMethodOrdering.length; } // System.out.println("After methodRound: " + methodRound); // System.out.println("After currMethod.length: " + currMethodOrdering.length); From e8cff407c9f6c9eaf7ddd6c5b72b32256cc0dc64 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 6 Aug 2022 11:32:29 +0300 Subject: [PATCH 17/40] add test --- .../edu/illinois/cs/dt/tools/detection/TestShuffler.java | 2 -- .../src/test/java/edu/illinois/TuscanOnlyClassTest.java | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 9d3932ae..731c3d19 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -34,8 +34,6 @@ public static String className(final String testName) { } private final HashMap> classToMethods; - private static int row = 0; - private static int selectClass = 0; private final String type; private final List tests; private final Set alreadySeenOrders = new HashSet<>(); diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java new file mode 100644 index 00000000..a108c774 --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -0,0 +1,6 @@ +package edu.illinois; + +import edu.illinois.cs.dt.tools.detection.TestShuffler; + +public class TuscanOnlyClassTest { +} From 2c3f2057ae3d04ce9a2f1493cbbd1212e11eb4af Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 6 Aug 2022 11:35:41 +0300 Subject: [PATCH 18/40] update testshuffler --- .../illinois/cs/dt/tools/detection/TestShuffler.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 731c3d19..93b21233 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -203,14 +203,8 @@ public List alphabeticalAndTuscanOrder(int count, boolean isTuscan) { int n = classes.size(); int[][] res = Tuscan.generateTuscanPermutations(n); List permClasses = new ArrayList(); - if (n == 3 || n == 5) { - for (int i = 0; i < res[count].length; i++) { - permClasses.add(classes.get(res[count][i])); - } - } else { - for (int i = 0; i < res[count].length - 1; i++) { - permClasses.add(classes.get(res[count][i])); - } + for (int i = 0; i < res[count].length - 1; i++) { + permClasses.add(classes.get(res[count][i])); } for (String className : permClasses) { fullTestOrder.addAll(classToMethods.get(className)); From 1193c737b5a9c153188b4394dde295425ec8ee6c Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 6 Aug 2022 11:36:41 +0300 Subject: [PATCH 19/40] update tuscan only class detector --- .../cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java | 1 + 1 file changed, 1 insertion(+) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java index 727164ca..e0033d39 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java @@ -34,6 +34,7 @@ public TuscanOnlyClassDetector(final Runner runner, final File baseDir, final in super(runner, baseDir, rounds, type); int n = getClassesSize(tests); if (n == 3 || n == 5) { + // We need one more round than the number of classes if n is 3 or 5. if (this.rounds > n) { this.rounds = n + 1; } From a8e7b13c803b69335aef67c027fc6b5203268a67 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 6 Aug 2022 11:37:57 +0300 Subject: [PATCH 20/40] update tuscan --- .../illinois/cs/dt/tools/utility/Tuscan.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 5f877202..2422c0a0 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -14,18 +14,18 @@ public static int[][] generateTuscanPermutations(int arg) { private static int[][] r; private static void helper(int[] a, int i) { - System.arraycopy(a, 0, r[i], 0, a.length); + System.arraycopy(a, 0, r[i], 0, a.length); } private static void generateTuscanSquare(int n) { - int nn = n; - while((n - 1) % 4 == 0 && n != 1 && n != 9){ - n = (n - 1) / 2 + 1; + int nn = n; + while ((n - 1) % 4 == 0 && n != 1 && n != 9) { + n = (n - 1) / 2 + 1; + } + r = new int[nn][]; + for (int i = 0; i < nn; i++) { + r[i] = new int[nn + 1]; } - r = new int[nn][]; - for (int i = 0; i < nn; i++) { - r[i] = new int[nn + 1]; - } if (n % 2 == 0) { // https://mathoverflow.net/questions/60856/hamilton-paths-in-k-2n/60859#60859 @@ -91,11 +91,11 @@ private static void generateTuscanSquare(int n) { } for (int i = h; i < n; i++) { for (int j = 0; j < h - 1; j++) { - r[i][j] = ((j % 2 == 0) ? 0 : h) + (i-h + ((j % 2 == 0) ? (j / 2) : (h - 2 - (j - 1) / 2))) % (h - 1); + r[i][j] = ((j % 2 == 0) ? 0 : h) + (i - h + ((j % 2 == 0) ? (j / 2) : (h - 2 - (j - 1) / 2))) % (h - 1); } - r[i][h-1] = h-1; + r[i][h - 1] = h - 1; for (int j = h; j < n + 1; j++) { - r[i][j] = ((j % 2 == 0) ? 0 : h) + r[i][j-h] % h; + r[i][j] = ((j % 2 == 0) ? 0 : h) + r[i][j - h] % h; } } for (int i = 0; i < n; i++) { @@ -104,19 +104,19 @@ private static void generateTuscanSquare(int n) { if (r[i][l] == n) break; } int[] t = new int[n]; - System.arraycopy(r[i], l+1, t, 0, n - l); + System.arraycopy(r[i], l + 1, t, 0, n - l); System.arraycopy(r[i], 0, t, n - l, l); - System.arraycopy(t, 0, r[i], 0, n); + System.arraycopy(t, 0, r[i], 0, n); } } } private static void generateThree() { int[][] t = { - { 0, 1, 2 }, - { 1, 0, 2 }, - { 2, 0 }, - { 2, 1 } + { 0, 1, 2, 0 }, + { 1, 0, 2, 0 }, + { 2, 0, 0 }, + { 2, 1, 0 } }; // int[][] t = { // { 0, 1, 2 }, @@ -129,12 +129,12 @@ private static void generateThree() { private static void generateFive() { int[][] t = { - { 0, 1, 2, 3, 4 }, - { 1, 0, 3, 2, 4 }, - { 4, 3, 0, 2, 1 }, - { 1, 4, 2, 0 }, - { 0, 4, 1, 3 }, - { 4, 0, 3, 1 } + { 0, 1, 2, 3, 4, 0 }, + { 1, 0, 3, 2, 4, 0 }, + { 4, 3, 0, 2, 1, 0 }, + { 1, 4, 2, 0, 0 }, + { 0, 4, 1, 3, 0 }, + { 4, 0, 3, 1, 0 } }; // int[][] t = { // { 0, 1, 2, 3, 4 }, @@ -146,4 +146,4 @@ private static void generateFive() { // }; r = t; } -} +} \ No newline at end of file From 0a0d9100a4346a577052de10634cd064db64784b Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 10 Aug 2022 15:46:42 +0300 Subject: [PATCH 21/40] inter class --- .../cs/dt/tools/detection/TestShuffler.java | 122 +++++++++++++---- .../detection/detectors/DetectorFactory.java | 3 + .../detectors/TuscanInterClassDetector.java | 98 ++++++++++++++ .../detectors/TuscanIntraClassDetector.java | 42 +++--- .../illinois/cs/dt/tools/utility/Tuscan.java | 22 +-- .../src/test/java/edu/illinois/Pair.java | 41 ++++++ .../edu/illinois/TuscanInterClassTest.java | 98 ++++++++++++++ .../edu/illinois/TuscanIntraClassTest.java | 126 ++++++++++++++++++ .../edu/illinois/TuscanOnlyClassTest.java | 59 +++++++- 9 files changed, 555 insertions(+), 56 deletions(-) create mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java create mode 100644 idflakies-core/src/test/java/edu/illinois/Pair.java create mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java create mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 93b21233..08865da6 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -23,11 +23,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.Set; import java.util.stream.Collectors; +import javax.enterprise.inject.spi.InterceptionType; + public class TestShuffler { public static String className(final String testName) { return testName.substring(0, testName.lastIndexOf('.')); @@ -225,8 +228,15 @@ public List tuscanIntraClassOrder(int round) { int n = classes.size(); // n is number of classes int[][] classOrdering = Tuscan.generateTuscanPermutations(n); for (String className : classes) { - int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); - classToPermutations.put(className, methodPermuation); + if (classToMethods.get(className).size() == 1) { + int[][] methodPermuation = { + { 0, 0 } + }; + classToPermutations.put(className, methodPermuation); + } else { + int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); + classToPermutations.put(className, methodPermuation); + } } HashMap> newClassToMethods = new HashMap>(); List permClasses = new ArrayList(); @@ -234,50 +244,108 @@ public List tuscanIntraClassOrder(int round) { while ((classOrdering.length - 1) < classRound) { classRound -= classOrdering.length; } - if (n == 3 || n == 5) { - for (int i = 0; i < classOrdering[classRound].length; i++) { - permClasses.add(classes.get(classOrdering[classRound][i])); - } - } else { - for (int i = 0; i < classOrdering[classRound].length - 1; i++) { // {0, 1, 0} {1, 0, 0} - permClasses.add(classes.get(classOrdering[classRound][i])); - } + for (int i = 0; i < classOrdering[classRound].length - 1; i++) { // {0, 1, 0} {1, 0, 0} + permClasses.add(classes.get(classOrdering[classRound][i])); } for (String className : permClasses) { List methods = classToMethods.get(className); List permMethods = new ArrayList(); int[][] currMethodOrdering = classToPermutations.get(className); - // System.out.println(className); n = methods.size(); - // System.out.println(n); int methodRound = round; - // System.out.println("methodRound: " + methodRound); - // for (int j = 0; j < currMethodOrdering.length; j++) { - // for (int k = 0; k < currMethodOrdering[j].length; k++) { - // System.out.print(currMethodOrdering[j][k]); - // } - // System.out.println(); - // } while((currMethodOrdering.length - 1) < methodRound) { methodRound -= currMethodOrdering.length; } - // System.out.println("After methodRound: " + methodRound); - // System.out.println("After currMethod.length: " + currMethodOrdering.length); - if (n == 3 || n == 5) { - for (int i = 0; i < currMethodOrdering[methodRound].length; i++) { - permMethods.add(methods.get(currMethodOrdering[methodRound][i])); + for (int i = 0; i < currMethodOrdering[methodRound].length - 1; i++) { + permMethods.add(methods.get(currMethodOrdering[methodRound][i])); + } + newClassToMethods.put(className, permMethods); + } + for (String className : permClasses) { + fullTestOrder.addAll(newClassToMethods.get(className)); + } + return fullTestOrder; + } + + private static int interClassRound = 0; // which class permutation to choose + private static int interCurrentMethodRound = 0; // first class of pair + private static int interNextMethodRound = 0; // second class of pair + private static int i1 = 0; // current class + private static int i2 = 1; // next class + private static boolean isNewOrdering = false; // To change the permutation of classes + + public List tuscanInterClass(int round) { + List classes = new ArrayList<>(classToMethods.keySet()); + HashMap classToPermutations = new HashMap(); + Collections.sort(classes); + final List fullTestOrder = new ArrayList<>(); + int n = classes.size(); // n is number of classes + int[][] classOrdering = Tuscan.generateTuscanPermutations(n); // Tuscan square for classes + + for (String className : classes) { + int methodSize = classToMethods.get(className).size(); + int[][] methodPermuation = Tuscan.generateTuscanPermutations(methodSize); + classToPermutations.put(className, methodPermuation); + } + HashMap> newClassToMethods = new HashMap>(); // class to permutated methods + List permClasses = new ArrayList(); + if (isNewOrdering) { + // When we reach end of a permutation for classes only + i1 = 0; + i2 = 1; + interNextMethodRound = 0; + interCurrentMethodRound = 0; + interClassRound++; + isNewOrdering = false; + } + for (int i = 0; i < classOrdering[interClassRound].length - 1; i++) { + permClasses.add(classes.get(classOrdering[interClassRound][i])); + } + String currentClass = permClasses.get(i1), nextClass = permClasses.get(i2); + int currentClassMethodSize = classToMethods.get(currentClass).size(); + int nextClassMethodSize = classToMethods.get(nextClass).size(); + if (currentClassMethodSize == interCurrentMethodRound && nextClassMethodSize == (interNextMethodRound + 1)) { + // To change the pair so we change i1 & i2 + i1++; + i2++; + interNextMethodRound = 0; + interCurrentMethodRound = 0; + } + else if (currentClassMethodSize == (interCurrentMethodRound)) { + // To change the *next* class methods + interNextMethodRound++; + interCurrentMethodRound = 0; + } + int[] currentClassTuscan = classToPermutations.get(currentClass)[interCurrentMethodRound]; + int[] nextClassTuscan = classToPermutations.get(nextClass)[interNextMethodRound]; + for (String className : permClasses) { + List methods = classToMethods.get(className); + List permMethods = new ArrayList(); + if (className == currentClass) { + for (int i = 0; i < currentClassTuscan.length - 1; i++) { + permMethods.add(methods.get(currentClassTuscan[i])); + } + } + else if (className == nextClass) { + for (int i = 0; i < nextClassTuscan.length - 1; i++) { + permMethods.add(methods.get(nextClassTuscan[i])); } } else { - for (int i = 0; i < currMethodOrdering[methodRound].length - 1; i++) { - permMethods.add(methods.get(currMethodOrdering[methodRound][i])); + // We don't care about this classes permutations yet + for (int i = 0; i < nextClassTuscan.length; i++) { + permMethods = methods; } } newClassToMethods.put(className, permMethods); } - for (String className : permClasses) { fullTestOrder.addAll(newClassToMethods.get(className)); } + interCurrentMethodRound++; + if (nextClass == permClasses.get(permClasses.size() - 1) && currentClassMethodSize == interCurrentMethodRound && nextClassMethodSize == (interNextMethodRound + 1)) { + // if the *next class* is our last class then there is no pair so change to the next order + isNewOrdering = true; + } return fullTestOrder; } } \ No newline at end of file diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 27383b90..3a3ba305 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,6 +1,7 @@ package edu.illinois.cs.dt.tools.detection.detectors; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; @@ -30,6 +31,8 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("tuscan-intra-class")) { return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); + } else if (detectorType().equals("tuscan-inter-class")) { + return new TuscanInterClassDetector(runner, baseDir, rounds, detectorType(), tests); } return new RandomDetector("random", baseDir, runner, rounds, tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java new file mode 100644 index 00000000..36ea4b7a --- /dev/null +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java @@ -0,0 +1,98 @@ +package edu.illinois.cs.dt.tools.detection.detectors; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import edu.illinois.cs.dt.tools.detection.DetectionRound; +import edu.illinois.cs.dt.tools.detection.DetectorUtil; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; +import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; +import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.testrunner.data.results.TestRunResult; +import edu.illinois.cs.testrunner.runner.Runner; + +public class TuscanInterClassDetector extends ExecutingDetector { + private final List tests; + private TestRunResult origResult; + + private final HashMap> classToMethods; + private final TestShuffler testShuffler; + + public static int getClassesSize(List tests) { + List classes = new ArrayList(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + } + return classes.size(); + } + + public static int findNumberOfRounds (HashMap> classToMethods) { + int classSize = classToMethods.keySet().size(); + if (classSize == 3 || classSize == 5) { + classSize++; + } + int totalMethodSize = 1; + for (String className : classToMethods.keySet()) { + int methodSize = classToMethods.get(className).size(); + if (methodSize == 3 || methodSize == 5) { + totalMethodSize *= (methodSize + 1); + } else { + totalMethodSize *= methodSize; + } + } + int tempRounds = classSize * totalMethodSize; + return tempRounds; + } + + public TuscanInterClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { + super(runner, baseDir, rounds, type); + classToMethods = new HashMap<>(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classToMethods.containsKey(className)) { + classToMethods.put(className, new ArrayList<>()); + } + classToMethods.get(className).add(test); + } + // int classSize = classToMethods.keySet().size(); + // if (classSize == 3 || classSize == 5) { + // classSize++; + // } + // int totalMethodSize = 1; + // for (String className : classToMethods.keySet()) { + // int methodSize = classToMethods.get(className).size(); + // if (methodSize == 3 || methodSize == 5) { + // totalMethodSize *= (methodSize + 1); + // } else { + // totalMethodSize *= methodSize; + // } + // } + // int tempRounds = classSize * totalMethodSize; + int tempRounds = findNumberOfRounds(classToMethods); + if (rounds > tempRounds) { + this.rounds = tempRounds; + } else { + this.rounds = rounds; + } + this.tests = tests; + this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); + this.origResult = DetectorUtil.originalResults(tests, runner); + if (runner instanceof InstrumentingSmartRunner) { + addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); + } else { + addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); + } + addFilter(new UniqueFilter()); + } + + @Override + public DetectionRound results() throws Exception { + return makeDts(origResult, runList(testShuffler.tuscanInterClass(absoluteRound.get()))); + } +} diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java index c57608d3..42863edf 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java @@ -32,18 +32,19 @@ public static int getClassesSize(List tests) { return classes.size(); } + public static int findMaxMethodSize(HashMap> classToMethods) { + int maxMethodSize = 0; + for (String className : classToMethods.keySet()) { + int nn = classToMethods.get(className).size(); + if(maxMethodSize < nn) { + maxMethodSize = nn; + } + } + return maxMethodSize; + } + public TuscanIntraClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { super(runner, baseDir, rounds, type); - // int n = getClassesSize(tests); - // if (n == 3 || n == 5) { - // if (this.rounds > n) { - // this.rounds = n + 1; - // } - // } else { - // if (this.rounds > n) { - // this.rounds = n; - // } - // } classToMethods = new HashMap<>(); for (final String test : tests) { final String className = TestShuffler.className(test); @@ -53,17 +54,22 @@ public TuscanIntraClassDetector(final Runner runner, final File baseDir, final i classToMethods.get(className).add(test); } int classSize = classToMethods.keySet().size(); - int maxMethodSize = 0; - for (String className : classToMethods.keySet()) { - int nn = classToMethods.get(className).size(); - if(maxMethodSize < nn) { - maxMethodSize = nn; - } + if (classSize == 3 || classSize == 5) { + classSize++; + } + int maxMethodSize = findMaxMethodSize(classToMethods); + if (maxMethodSize == 3 || maxMethodSize == 5) { + maxMethodSize++; } + this.rounds = rounds; if (classSize > maxMethodSize) { - this.rounds = classSize; + if (this.rounds > classSize) { + this.rounds = classSize; + } } else { - this.rounds = maxMethodSize; + if (this.rounds > maxMethodSize) { + this.rounds = maxMethodSize; + } } this.tests = tests; this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 2422c0a0..e81ee4b3 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -26,7 +26,6 @@ private static void generateTuscanSquare(int n) { for (int i = 0; i < nn; i++) { r[i] = new int[nn + 1]; } - if (n % 2 == 0) { // https://mathoverflow.net/questions/60856/hamilton-paths-in-k-2n/60859#60859 int[] a = new int[n]; @@ -42,6 +41,7 @@ private static void generateTuscanSquare(int n) { helper(a, j); } } else if (n % 4 == 3) { + System.out.println("Here we are" + n); int k = (n - 3) / 4; int[] b = new int[n]; for (int i = 0; i < n - 1; i++) { @@ -78,7 +78,9 @@ private static void generateTuscanSquare(int n) { helper(t[i], i); } } - else assert(false); + else { + assert(false); + } while (nn != n){ // https://www.sciencedirect.com/science/article/pii/0095895680900441 @@ -112,18 +114,18 @@ private static void generateTuscanSquare(int n) { } private static void generateThree() { + // int[][] t = { + // { 0, 1, 2, 0 }, + // { 1, 0, 2, 0 }, + // { 2, 0, 0 }, + // { 2, 1, 0 } + // }; int[][] t = { { 0, 1, 2, 0 }, { 1, 0, 2, 0 }, - { 2, 0, 0 }, - { 2, 1, 0 } + { 2, 0, 1, 0 }, + { 2, 1, 0, 0 } }; - // int[][] t = { - // { 0, 1, 2 }, - // { 1, 0, 2 }, - // { 2, 0, 1 }, - // { 2, 1, 0 } - // }; r = t; } diff --git a/idflakies-core/src/test/java/edu/illinois/Pair.java b/idflakies-core/src/test/java/edu/illinois/Pair.java new file mode 100644 index 00000000..b5b96490 --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/Pair.java @@ -0,0 +1,41 @@ +package edu.illinois; + +import java.util.Objects; + +public class Pair { + private String x; + private String y; + + Pair(String x, String y) { + this.x = x; + this.y = y; + } + + public String toString() { + return "(" + this.x + ", " + this.y + ")"; + } + + @Override + public boolean equals(Object rhs) { + if (rhs instanceof Pair) { + Pair o = (Pair) rhs; + // if (this.x == o.x && this.y == o.y) { + // System.out.println(o.x + " " + this.x); + // System.out.println(o.y + " " + this.y); + // System.out.println(); + // } + return this.x == o.x && this.y == o.y; + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(x, y); + } + + // public Pair reverse() { + // Pair reversedPair = new Pair(this.y, this.x); + // return reversedPair; + // } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java new file mode 100644 index 00000000..5a3b7f2a --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java @@ -0,0 +1,98 @@ +package edu.illinois; + +import java.util.ArrayList; +import java.util.List; +import java.util.*; + +import org.junit.Test; + +import edu.emory.mathcs.backport.java.util.Arrays; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.detectors.TuscanInterClassDetector; + + +public class TuscanInterClassTest { + @Test + public void test() throws Exception { + String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector"}; + // "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + // "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + // "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + // "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + List tests = Arrays.asList(testArray); + HashMap> tempClassToMethods = TuscanIntraClassTest.generateClassToMethods(tests); + int rounds = TuscanInterClassDetector.findNumberOfRounds(tempClassToMethods); + TestShuffler testShuffler = new TestShuffler("", 0, tests, null); + // int n = TuscanOnlyClassDetector.getClassesSize(tests); + List tempClasses = new ArrayList(tempClassToMethods.keySet()); + // System.out.println(classes); + LinkedHashMap> classToMethods = new LinkedHashMap>(); + List allClassPairs = TuscanIntraClassTest.generateAllPairs(tempClasses); + List allMethodPairs = new ArrayList(); + List visitedMethodPairs = new ArrayList(); + List visitedClassPairs = new ArrayList(); + List classes = new ArrayList(); + System.out.println("Rounds: " + rounds); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.tuscanIntraClassOrder(i); + for (String test : currentOrder) { + String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + if (!classToMethods.containsKey(className)) { + classToMethods.put(className, new ArrayList()); + } + classToMethods.get(className).add(test); + } + // List currentClassPairs = TuscanIntraClassTest.generateAllPairs(classes); + // allClassPairs.addAll(currentClassPairs); + for (int j = 0; j < classes.size() - 1; j++) { + // Check if class pairs are covered + Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); + if (!allClassPairs.contains(newPair)) { + // System.out.println("1" + allClassPairs.get(2) + "1"); + // if (allClassPairs.get(2).equals(newPair)) { + // System.out.println("HELLO"); + // } else { + // System.out.println("NO"); + // } + // System.out.println("NEWPAIR " + newPair); + // System.out.println("1" + newPair + "1"); + // throw new Exception("Not included Classes"); + System.out.println(newPair); + System.out.println(allClassPairs); + System.out.println("Not included classes"); + } + if (!visitedClassPairs.contains(newPair)) { + visitedClassPairs.add(newPair); + } + } + for (String className : classes) { + List currentMethodOrdering = classToMethods.get(className); + List currentMethodPairs = TuscanIntraClassTest.generateAllPairs(currentMethodOrdering); + allMethodPairs.addAll(currentMethodPairs); + // System.out.println(currentMethodPairs.size()); + for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { + Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); + if(!currentMethodPairs.contains(newPair)) { + System.out.println(newPair); + throw new Exception("Not included Method Pairs"); + } + if (!visitedMethodPairs.contains(newPair)) { + visitedMethodPairs.add(newPair); + } + } + currentMethodOrdering.clear(); + } + } + System.out.println(allClassPairs.size()); + System.out.println(visitedClassPairs.size()); + System.out.println(visitedClassPairs.size()); + } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java new file mode 100644 index 00000000..28f0df1f --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -0,0 +1,126 @@ +package edu.illinois; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Objects; +import java.util.*; + +import org.junit.Test; +import org.junit.Assert; + +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.detectors.TuscanIntraClassDetector; +import edu.illinois.cs.dt.tools.detection.detectors.TuscanOnlyClassDetector; +import javassist.bytecode.stackmap.TypeData.ClassName; + +import edu.illinois.Pair; + +public class TuscanIntraClassTest { + @Test + public void test() throws Exception { + String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + List tests = Arrays.asList(testArray); + TestShuffler testShuffler = new TestShuffler("", 0, tests, null); + // int n = TuscanOnlyClassDetector.getClassesSize(tests); + HashMap> tempClassToMethods = generateClassToMethods(tests); + int maxMethodSize = TuscanIntraClassDetector.findMaxMethodSize(tempClassToMethods); + if (maxMethodSize == 3 || maxMethodSize == 5) { + maxMethodSize++; + } + int rounds; + int classSize = tempClassToMethods.keySet().size(); + if (classSize == 3 || classSize == 5) { + classSize++; + } + if (classSize > maxMethodSize) { + rounds = classSize; + } else { + rounds = maxMethodSize; + } + // System.out.println(rounds); + List classes = new ArrayList(); + LinkedHashMap> classToMethods = new LinkedHashMap>(); + List visitedMethodPairs = new ArrayList(); + // List visitedClassPairs = new ArrayList(); + Set allMethodPairs = new HashSet(); + // Set allClassPairs = new HashSet(); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.tuscanIntraClassOrder(i); + for (String test : currentOrder) { + String className = TestShuffler.className(test); + if (!classes.contains(className)) { + classes.add(className); + } + if (!classToMethods.containsKey(className)) { + classToMethods.put(className, new ArrayList()); + } + classToMethods.get(className).add(test); + } + List currentClassPairs = generateAllPairs(classes); + // allClassPairs.addAll(currentClassPairs); + for (int j = 0; j < classes.size() - 1; j++) { + // Check if class pairs are covered + Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); + if (!currentClassPairs.contains(newPair)) { + throw new Exception("Not included Classes"); + } + // if (!visitedClassPairs.contains(newPair)) { + // visitedClassPairs.add(newPair); + // } + } + for (String className : classes) { + List currentMethodOrdering = classToMethods.get(className); + List currentMethodPairs = generateAllPairs(currentMethodOrdering); + allMethodPairs.addAll(currentMethodPairs); + // System.out.println(currentMethodPairs.size()); + for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { + Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); + if(!currentMethodPairs.contains(newPair)) { + System.out.println(newPair); + throw new Exception("Not included Method Pairs"); + } + if (!visitedMethodPairs.contains(newPair)) { + visitedMethodPairs.add(newPair); + } + } + currentMethodOrdering.clear(); + } + } + Assert.assertEquals(visitedMethodPairs.size(), allMethodPairs.size()); + } + + public static List generateAllPairs(List tests) { + List allPairs = new ArrayList(); + for (int i = 0; i < tests.size(); i++) { + for (int j = 0; j < tests.size(); j++) { + if (tests.get(i) != tests.get(j)) { + Pair newPair = new Pair(tests.get(i), tests.get(j)); + allPairs.add(newPair); + } + } + } + return allPairs; + } + + public static HashMap> generateClassToMethods (List tests) { + HashMap> classToMethods = new HashMap<>(); + for (final String test : tests) { + final String className = TestShuffler.className(test); + if (!classToMethods.containsKey(className)) { + classToMethods.put(className, new ArrayList<>()); + } + classToMethods.get(className).add(test); + } + return classToMethods; + } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index a108c774..615e69d0 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -1,6 +1,63 @@ package edu.illinois; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Objects; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Test; + +import edu.emory.mathcs.backport.java.util.Arrays; import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.detectors.TuscanOnlyClassDetector; +import scala.collection.mutable.ArrayBuilder.ofBoolean; public class TuscanOnlyClassTest { -} + @Test + public void test() throws Exception { + String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + List tests = Arrays.asList(testArray); + // System.out.println(tests); + TestShuffler testShuffler = new TestShuffler("", 0, tests, null); + int n = TuscanOnlyClassDetector.getClassesSize(tests); + int rounds = n; + if (n == 3 || n == 5) { + rounds++; + } + List listOfPairs = new ArrayList(); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.alphabeticalAndTuscanOrder(i, true); + Set classes = new LinkedHashSet(); + // System.out.println("currentORder.size()" + currentOrder.size()); + for (int j = 0; j < currentOrder.size(); j++) { + classes.add(TestShuffler.className(currentOrder.get(j))); + } + // System.out.println("classes.size()" + classes.size()); + String[] classesArray = classes.toArray(new String[classes.size()]); + for (int j = 0; j < classesArray.length - 1; j++) { + Pair newPair = new Pair(classesArray[j], classesArray[j + 1]); + if (listOfPairs.contains(newPair)) { + throw new Exception("new"); + } + listOfPairs.add(newPair); + } + } + int count = listOfPairs.size(); + if (n == 5) { + Assert.assertEquals(count, 21); + } else { + Assert.assertEquals(count, n * (n - 1)); + } + } +} \ No newline at end of file From 6553dcb68417be3e4abed5092006dee2e305ab20 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 13 Aug 2022 20:32:05 +0300 Subject: [PATCH 22/40] fixed round calculation in inter-class --- .../cs/dt/tools/detection/TestShuffler.java | 43 +++++--- .../detectors/TuscanInterClassDetector.java | 42 ++++---- .../detectors/TuscanIntraClassDetector.java | 12 +-- .../src/test/java/edu/illinois/Pair.java | 10 -- .../edu/illinois/TuscanInterClassTest.java | 98 ------------------- .../edu/illinois/TuscanIntraClassTest.java | 4 - 6 files changed, 56 insertions(+), 153 deletions(-) delete mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 08865da6..a5dadd05 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -14,6 +14,8 @@ import edu.illinois.cs.testrunner.configuration.Configuration; import edu.illinois.cs.testrunner.data.results.TestRunResult; +import static org.junit.Assert.assertNotSame; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -23,7 +25,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Random; import java.util.Set; @@ -41,6 +42,13 @@ public static String className(final String testName) { private final List tests; private final Set alreadySeenOrders = new HashSet<>(); private final File baseDir; + // For tuscanInterClass + private static int interClassRound = 0; // which class permutation to choose + private static int interCurrentMethodRound = 0; // first class of pair + private static int interNextMethodRound = 0; // second class of pair + private static int i1 = 0; // current class + private static int i2 = 1; // next class + private static boolean isNewOrdering = false; // To change the permutation of classes private final Random random; @@ -267,25 +275,38 @@ public List tuscanIntraClassOrder(int round) { return fullTestOrder; } - private static int interClassRound = 0; // which class permutation to choose - private static int interCurrentMethodRound = 0; // first class of pair - private static int interNextMethodRound = 0; // second class of pair - private static int i1 = 0; // current class - private static int i2 = 1; // next class - private static boolean isNewOrdering = false; // To change the permutation of classes - public List tuscanInterClass(int round) { List classes = new ArrayList<>(classToMethods.keySet()); HashMap classToPermutations = new HashMap(); Collections.sort(classes); final List fullTestOrder = new ArrayList<>(); int n = classes.size(); // n is number of classes - int[][] classOrdering = Tuscan.generateTuscanPermutations(n); // Tuscan square for classes + int[][] classOrdering = Tuscan.generateTuscanPermutations(n); for (String className : classes) { int methodSize = classToMethods.get(className).size(); - int[][] methodPermuation = Tuscan.generateTuscanPermutations(methodSize); - classToPermutations.put(className, methodPermuation); + int[][] result; + if (methodSize == 3) { + int[][] methodPermuation = { + { 0, 1, 2, 0 }, + { 1, 2, 0, 0 }, + { 2, 0, 1, 0 }, + }; + result = methodPermuation; + } else if (methodSize == 5) { + int[][] methodPermuation = { + { 0, 1, 2, 3, 4, 0 }, + { 1, 0, 2, 4, 3, 0 }, + { 2, 4, 0, 3, 1, 0 }, + { 3, 1, 0, 4, 2, 0 }, + { 4, 1, 2, 3, 0, 0 }, + }; + result = methodPermuation; + } else { + int[][] methodPermuation = Tuscan.generateTuscanPermutations(methodSize); + result = methodPermuation; + } + classToPermutations.put(className, result); } HashMap> newClassToMethods = new HashMap>(); // class to permutated methods List permClasses = new ArrayList(); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java index 36ea4b7a..9f0386a2 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java @@ -5,12 +5,14 @@ import java.util.HashMap; import java.util.List; +import edu.emory.mathcs.backport.java.util.Collections; import edu.illinois.cs.dt.tools.detection.DetectionRound; import edu.illinois.cs.dt.tools.detection.DetectorUtil; import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.data.results.TestRunResult; import edu.illinois.cs.testrunner.runner.Runner; @@ -34,19 +36,25 @@ public static int getClassesSize(List tests) { public static int findNumberOfRounds (HashMap> classToMethods) { int classSize = classToMethods.keySet().size(); - if (classSize == 3 || classSize == 5) { - classSize++; - } - int totalMethodSize = 1; + List classes = new ArrayList<>(classToMethods.keySet()); + Collections.sort(classes); + int[][] classPermutations = Tuscan.generateTuscanPermutations(classSize); + HashMap classToSize = new HashMap<>(); for (String className : classToMethods.keySet()) { - int methodSize = classToMethods.get(className).size(); - if (methodSize == 3 || methodSize == 5) { - totalMethodSize *= (methodSize + 1); - } else { - totalMethodSize *= methodSize; + classToSize.put(className, classToMethods.get(className).size()); + } + int tempRounds = 0; + for (int i = 0; i < classPermutations.length; i++) { + int methodSize = 0; + for (int j = 0; j < classPermutations.length - 2; j++) { + String current = classes.get(classPermutations[i][j]); + String next = classes.get(classPermutations[i][j + 1]); + int size1 = classToMethods.get(current).size(); + int size2 = classToMethods.get(next).size(); + methodSize += (size1 * size2); } + tempRounds += methodSize; } - int tempRounds = classSize * totalMethodSize; return tempRounds; } @@ -60,20 +68,6 @@ public TuscanInterClassDetector(final Runner runner, final File baseDir, final i } classToMethods.get(className).add(test); } - // int classSize = classToMethods.keySet().size(); - // if (classSize == 3 || classSize == 5) { - // classSize++; - // } - // int totalMethodSize = 1; - // for (String className : classToMethods.keySet()) { - // int methodSize = classToMethods.get(className).size(); - // if (methodSize == 3 || methodSize == 5) { - // totalMethodSize *= (methodSize + 1); - // } else { - // totalMethodSize *= methodSize; - // } - // } - // int tempRounds = classSize * totalMethodSize; int tempRounds = findNumberOfRounds(classToMethods); if (rounds > tempRounds) { this.rounds = tempRounds; diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java index 42863edf..4e237715 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java @@ -54,13 +54,13 @@ public TuscanIntraClassDetector(final Runner runner, final File baseDir, final i classToMethods.get(className).add(test); } int classSize = classToMethods.keySet().size(); - if (classSize == 3 || classSize == 5) { - classSize++; - } + // if (classSize == 3 || classSize == 5) { + // classSize++; + // } int maxMethodSize = findMaxMethodSize(classToMethods); - if (maxMethodSize == 3 || maxMethodSize == 5) { - maxMethodSize++; - } + // if (maxMethodSize == 3 || maxMethodSize == 5) { + // maxMethodSize++; + // } this.rounds = rounds; if (classSize > maxMethodSize) { if (this.rounds > classSize) { diff --git a/idflakies-core/src/test/java/edu/illinois/Pair.java b/idflakies-core/src/test/java/edu/illinois/Pair.java index b5b96490..5e10a3cb 100644 --- a/idflakies-core/src/test/java/edu/illinois/Pair.java +++ b/idflakies-core/src/test/java/edu/illinois/Pair.java @@ -19,11 +19,6 @@ public String toString() { public boolean equals(Object rhs) { if (rhs instanceof Pair) { Pair o = (Pair) rhs; - // if (this.x == o.x && this.y == o.y) { - // System.out.println(o.x + " " + this.x); - // System.out.println(o.y + " " + this.y); - // System.out.println(); - // } return this.x == o.x && this.y == o.y; } return false; @@ -33,9 +28,4 @@ public boolean equals(Object rhs) { public int hashCode() { return Objects.hash(x, y); } - - // public Pair reverse() { - // Pair reversedPair = new Pair(this.y, this.x); - // return reversedPair; - // } } \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java deleted file mode 100644 index 5a3b7f2a..00000000 --- a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package edu.illinois; - -import java.util.ArrayList; -import java.util.List; -import java.util.*; - -import org.junit.Test; - -import edu.emory.mathcs.backport.java.util.Arrays; -import edu.illinois.cs.dt.tools.detection.TestShuffler; -import edu.illinois.cs.dt.tools.detection.detectors.TuscanInterClassDetector; - - -public class TuscanInterClassTest { - @Test - public void test() throws Exception { - String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector"}; - // "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", - // "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", - // "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - // "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; - List tests = Arrays.asList(testArray); - HashMap> tempClassToMethods = TuscanIntraClassTest.generateClassToMethods(tests); - int rounds = TuscanInterClassDetector.findNumberOfRounds(tempClassToMethods); - TestShuffler testShuffler = new TestShuffler("", 0, tests, null); - // int n = TuscanOnlyClassDetector.getClassesSize(tests); - List tempClasses = new ArrayList(tempClassToMethods.keySet()); - // System.out.println(classes); - LinkedHashMap> classToMethods = new LinkedHashMap>(); - List allClassPairs = TuscanIntraClassTest.generateAllPairs(tempClasses); - List allMethodPairs = new ArrayList(); - List visitedMethodPairs = new ArrayList(); - List visitedClassPairs = new ArrayList(); - List classes = new ArrayList(); - System.out.println("Rounds: " + rounds); - for (int i = 0; i < rounds; i++) { - List currentOrder = testShuffler.tuscanIntraClassOrder(i); - for (String test : currentOrder) { - String className = TestShuffler.className(test); - if (!classes.contains(className)) { - classes.add(className); - } - if (!classToMethods.containsKey(className)) { - classToMethods.put(className, new ArrayList()); - } - classToMethods.get(className).add(test); - } - // List currentClassPairs = TuscanIntraClassTest.generateAllPairs(classes); - // allClassPairs.addAll(currentClassPairs); - for (int j = 0; j < classes.size() - 1; j++) { - // Check if class pairs are covered - Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); - if (!allClassPairs.contains(newPair)) { - // System.out.println("1" + allClassPairs.get(2) + "1"); - // if (allClassPairs.get(2).equals(newPair)) { - // System.out.println("HELLO"); - // } else { - // System.out.println("NO"); - // } - // System.out.println("NEWPAIR " + newPair); - // System.out.println("1" + newPair + "1"); - // throw new Exception("Not included Classes"); - System.out.println(newPair); - System.out.println(allClassPairs); - System.out.println("Not included classes"); - } - if (!visitedClassPairs.contains(newPair)) { - visitedClassPairs.add(newPair); - } - } - for (String className : classes) { - List currentMethodOrdering = classToMethods.get(className); - List currentMethodPairs = TuscanIntraClassTest.generateAllPairs(currentMethodOrdering); - allMethodPairs.addAll(currentMethodPairs); - // System.out.println(currentMethodPairs.size()); - for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { - Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); - if(!currentMethodPairs.contains(newPair)) { - System.out.println(newPair); - throw new Exception("Not included Method Pairs"); - } - if (!visitedMethodPairs.contains(newPair)) { - visitedMethodPairs.add(newPair); - } - } - currentMethodOrdering.clear(); - } - } - System.out.println(allClassPairs.size()); - System.out.println(visitedClassPairs.size()); - System.out.println(visitedClassPairs.size()); - } -} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index 28f0df1f..6255802a 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -67,16 +67,12 @@ public void test() throws Exception { classToMethods.get(className).add(test); } List currentClassPairs = generateAllPairs(classes); - // allClassPairs.addAll(currentClassPairs); for (int j = 0; j < classes.size() - 1; j++) { // Check if class pairs are covered Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); if (!currentClassPairs.contains(newPair)) { throw new Exception("Not included Classes"); } - // if (!visitedClassPairs.contains(newPair)) { - // visitedClassPairs.add(newPair); - // } } for (String className : classes) { List currentMethodOrdering = classToMethods.get(className); From 6ce0959e27547dcd28cec00e79fae6dd2c93460c Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 13 Aug 2022 20:35:50 +0300 Subject: [PATCH 23/40] removed unnecessary imports --- .../java/edu/illinois/cs/dt/tools/detection/TestShuffler.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index a5dadd05..23bbef49 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -14,8 +14,6 @@ import edu.illinois.cs.testrunner.configuration.Configuration; import edu.illinois.cs.testrunner.data.results.TestRunResult; -import static org.junit.Assert.assertNotSame; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -30,8 +28,6 @@ import java.util.Set; import java.util.stream.Collectors; -import javax.enterprise.inject.spi.InterceptionType; - public class TestShuffler { public static String className(final String testName) { return testName.substring(0, testName.lastIndexOf('.')); From 2e5dc88199073fa870f29cc00bde572c5b7cc8ad Mon Sep 17 00:00:00 2001 From: mmk Date: Mon, 15 Aug 2022 11:36:23 +0300 Subject: [PATCH 24/40] added tuscan inter class test --- .../detectors/TuscanInterClassDetector.java | 2 +- .../illinois/cs/dt/tools/utility/Tuscan.java | 12 ++- .../src/test/java/edu/illinois/Pair.java | 12 +-- .../src/test/java/edu/illinois/Test.java | 48 ++++++++++ .../edu/illinois/TuscanInterClassTest.java | 90 +++++++++++++++++++ .../edu/illinois/TuscanIntraClassTest.java | 25 ++---- 6 files changed, 164 insertions(+), 25 deletions(-) create mode 100644 idflakies-core/src/test/java/edu/illinois/Test.java create mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java index 9f0386a2..46bb9e72 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java @@ -46,7 +46,7 @@ public static int findNumberOfRounds (HashMap> classToMetho int tempRounds = 0; for (int i = 0; i < classPermutations.length; i++) { int methodSize = 0; - for (int j = 0; j < classPermutations.length - 2; j++) { + for (int j = 0; j < classPermutations[i].length - 2; j++) { String current = classes.get(classPermutations[i][j]); String next = classes.get(classPermutations[i][j + 1]); int size1 = classToMethods.get(current).size(); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index e81ee4b3..d53810e8 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -2,7 +2,9 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { - if (arg == 3) { + if (arg == 1) { + generateOne(); + } else if (arg == 3) { generateThree(); } else if (arg == 5) { generateFive(); @@ -41,7 +43,6 @@ private static void generateTuscanSquare(int n) { helper(a, j); } } else if (n % 4 == 3) { - System.out.println("Here we are" + n); int k = (n - 3) / 4; int[] b = new int[n]; for (int i = 0; i < n - 1; i++) { @@ -113,6 +114,13 @@ private static void generateTuscanSquare(int n) { } } + private static void generateOne() { + int[][] t = { + { 0, 0 } + }; + r = t; + } + private static void generateThree() { // int[][] t = { // { 0, 1, 2, 0 }, diff --git a/idflakies-core/src/test/java/edu/illinois/Pair.java b/idflakies-core/src/test/java/edu/illinois/Pair.java index 5e10a3cb..dc6bd597 100644 --- a/idflakies-core/src/test/java/edu/illinois/Pair.java +++ b/idflakies-core/src/test/java/edu/illinois/Pair.java @@ -2,11 +2,11 @@ import java.util.Objects; -public class Pair { - private String x; - private String y; +public class Pair { + private T x; + private T y; - Pair(String x, String y) { + Pair(T x, T y) { this.x = x; this.y = y; } @@ -17,8 +17,8 @@ public String toString() { @Override public boolean equals(Object rhs) { - if (rhs instanceof Pair) { - Pair o = (Pair) rhs; + if (rhs instanceof Pair) { + Pair o = (Pair)rhs; return this.x == o.x && this.y == o.y; } return false; diff --git a/idflakies-core/src/test/java/edu/illinois/Test.java b/idflakies-core/src/test/java/edu/illinois/Test.java new file mode 100644 index 00000000..7418a3ea --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/Test.java @@ -0,0 +1,48 @@ +package edu.illinois; + +import java.util.*; +import java.util.stream.IntStream; + +import org.junit.Assert; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.experimental.theories.Theory; +import org.junit.runner.RunWith; + +import edu.illinois.cs.dt.tools.utility.Tuscan; + +@RunWith(Theories.class) +public class Test { + private static int[][] matrix; + + @DataPoints + public static int[] integers() { + int[] range = IntStream.rangeClosed(2, 20).toArray(); + return range; + } + + @Theory + public void test(int n) throws Exception { + int count; + List> s = new ArrayList>(); + matrix = Tuscan.generateTuscanPermutations(n); + // System.out.println("Tuscan " + n + ":"); + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[i].length - 2; j++) { + Pair newPair = new Pair(matrix[i][j], matrix[i][j + 1]); + if (n != 3 && n != 5 && s.contains(newPair)) { + throw new Exception("Not unique"); + } + s.add(newPair); + } + } + count = s.size(); + if (n == 5) { + Assert.assertEquals(count, 21); + } else if (n == 3) { + Assert.assertEquals(count, 8); + } else { + Assert.assertEquals(n * (n - 1), count); + } + } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java new file mode 100644 index 00000000..201f8c30 --- /dev/null +++ b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java @@ -0,0 +1,90 @@ +package edu.illinois; + +import java.util.*; + +import org.junit.Test; + +import edu.emory.mathcs.backport.java.util.Arrays; +import edu.illinois.cs.dt.tools.detection.TestShuffler; +import edu.illinois.cs.dt.tools.detection.detectors.TuscanInterClassDetector; + + +public class TuscanInterClassTest { + @Test + public void test() throws Exception { + String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMock1", + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + List tests = Arrays.asList(testArray); + HashMap> tempClassToMethods = TuscanIntraClassTest.generateClassToMethods(tests); + int rounds = TuscanInterClassDetector.findNumberOfRounds(tempClassToMethods); + TestShuffler testShuffler = new TestShuffler("", 0, tests, null); + List classes = new ArrayList(); + Set> finalPairs = new LinkedHashSet>(); + Set> visitedClassPairs = new LinkedHashSet>(); + for (int i = 0; i < rounds; i++) { + List currentRoundPermutation = testShuffler.tuscanInterClass(i); + List permutatedClasses = new ArrayList(); + for (String testName : currentRoundPermutation) { + String className = TestShuffler.className(testName); + if (!permutatedClasses.contains(className)) { + permutatedClasses.add(className); + } + if (!classes.contains(className)) { + classes.add(className); + } + } + List> allClassPairs = generateAllPairs(classes); + for (int j = 0; j < permutatedClasses.size() - 1; j++) { + List newPair = new ArrayList(); + newPair.add(permutatedClasses.get(j)); + newPair.add(permutatedClasses.get(j + 1)); + // System.out.println(newPair); + if (!(allClassPairs.contains(newPair))) { + throw new Exception("Not included pair"); + } + if (!visitedClassPairs.contains(newPair)) { + visitedClassPairs.add(newPair); + } + } + finalPairs.addAll(allClassPairs); + } + System.out.println(finalPairs.size()); + System.out.println(visitedClassPairs.size()); + if (finalPairs.size() != visitedClassPairs.size()) { + printDifference(visitedClassPairs, finalPairs); + } + } + + public static void printDifference(Set> visited, Set> expected) { + System.out.println("Difference: "); + for (List item : expected) { + if (expected.contains(item) && !visited.contains(item)) { + System.out.println(item); + } + } + } + + public static List> generateAllPairs(List tests) { + List> allPairs = new ArrayList<>(); + for (int i = 0; i < tests.size(); i++) { + for (int j = 0; j < tests.size(); j++) { + if (tests.get(i) != tests.get(j)) { + List newPair = new ArrayList(); + newPair.add(tests.get(i)); + newPair.add(tests.get(j)); + allPairs.add(newPair); + } + } + } + return allPairs; + } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index 6255802a..9f6a77e1 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; -import java.util.Objects; import java.util.*; import org.junit.Test; @@ -12,10 +11,6 @@ import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.detection.detectors.TuscanIntraClassDetector; -import edu.illinois.cs.dt.tools.detection.detectors.TuscanOnlyClassDetector; -import javassist.bytecode.stackmap.TypeData.ClassName; - -import edu.illinois.Pair; public class TuscanIntraClassTest { @Test @@ -50,10 +45,8 @@ public void test() throws Exception { // System.out.println(rounds); List classes = new ArrayList(); LinkedHashMap> classToMethods = new LinkedHashMap>(); - List visitedMethodPairs = new ArrayList(); - // List visitedClassPairs = new ArrayList(); - Set allMethodPairs = new HashSet(); - // Set allClassPairs = new HashSet(); + List> visitedMethodPairs = new ArrayList>(); + Set> allMethodPairs = new HashSet>(); for (int i = 0; i < rounds; i++) { List currentOrder = testShuffler.tuscanIntraClassOrder(i); for (String test : currentOrder) { @@ -66,21 +59,21 @@ public void test() throws Exception { } classToMethods.get(className).add(test); } - List currentClassPairs = generateAllPairs(classes); + List> currentClassPairs = generateAllPairs(classes); for (int j = 0; j < classes.size() - 1; j++) { // Check if class pairs are covered - Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); + Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); if (!currentClassPairs.contains(newPair)) { throw new Exception("Not included Classes"); } } for (String className : classes) { List currentMethodOrdering = classToMethods.get(className); - List currentMethodPairs = generateAllPairs(currentMethodOrdering); + List> currentMethodPairs = generateAllPairs(currentMethodOrdering); allMethodPairs.addAll(currentMethodPairs); // System.out.println(currentMethodPairs.size()); for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { - Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); + Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); if(!currentMethodPairs.contains(newPair)) { System.out.println(newPair); throw new Exception("Not included Method Pairs"); @@ -95,12 +88,12 @@ public void test() throws Exception { Assert.assertEquals(visitedMethodPairs.size(), allMethodPairs.size()); } - public static List generateAllPairs(List tests) { - List allPairs = new ArrayList(); + public static List> generateAllPairs(List tests) { + List> allPairs = new ArrayList>(); for (int i = 0; i < tests.size(); i++) { for (int j = 0; j < tests.size(); j++) { if (tests.get(i) != tests.get(j)) { - Pair newPair = new Pair(tests.get(i), tests.get(j)); + Pair newPair = new Pair(tests.get(i), tests.get(j)); allPairs.add(newPair); } } From cb62cf86f42bbab4329ae86eaaf89b1c7e4d0f7f Mon Sep 17 00:00:00 2001 From: mmk Date: Tue, 16 Aug 2022 19:22:18 +0300 Subject: [PATCH 25/40] added inter-class test --- .../edu/illinois/TuscanInterClassTest.java | 87 +++++++++++++------ .../illinois/{Test.java => TuscanTest.java} | 2 +- 2 files changed, 61 insertions(+), 28 deletions(-) rename idflakies-core/src/test/java/edu/illinois/{Test.java => TuscanTest.java} (98%) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java index 201f8c30..637488a3 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java @@ -2,22 +2,24 @@ import java.util.*; +import javax.annotation.security.PermitAll; + +import org.junit.Assert; import org.junit.Test; import edu.emory.mathcs.backport.java.util.Arrays; import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.detection.detectors.TuscanInterClassDetector; - public class TuscanInterClassTest { @Test public void test() throws Exception { - String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + String[] testArray = { "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", @@ -30,10 +32,13 @@ public void test() throws Exception { List classes = new ArrayList(); Set> finalPairs = new LinkedHashSet>(); Set> visitedClassPairs = new LinkedHashSet>(); + Set> visitedMethodPairs = new LinkedHashSet>(); + Set> finalPairsMethods= new LinkedHashSet>(); for (int i = 0; i < rounds; i++) { - List currentRoundPermutation = testShuffler.tuscanInterClass(i); - List permutatedClasses = new ArrayList(); - for (String testName : currentRoundPermutation) { + List currentRoundPermutation = testShuffler.tuscanInterClass(i); + List permutatedClasses = new ArrayList(); + HashMap> classToPermutations = new HashMap>(); + for (String testName : currentRoundPermutation) { String className = TestShuffler.className(testName); if (!permutatedClasses.contains(className)) { permutatedClasses.add(className); @@ -41,9 +46,13 @@ public void test() throws Exception { if (!classes.contains(className)) { classes.add(className); } - } - List> allClassPairs = generateAllPairs(classes); - for (int j = 0; j < permutatedClasses.size() - 1; j++) { + if (!classToPermutations.containsKey(className)) { + classToPermutations.put(className, new ArrayList<>()); + } + classToPermutations.get(className).add(testName); + } + List> allClassPairs = generateAllPairs(classes); + for (int j = 0; j < permutatedClasses.size() - 1; j++) { List newPair = new ArrayList(); newPair.add(permutatedClasses.get(j)); newPair.add(permutatedClasses.get(j + 1)); @@ -54,23 +63,34 @@ public void test() throws Exception { if (!visitedClassPairs.contains(newPair)) { visitedClassPairs.add(newPair); } - } - finalPairs.addAll(allClassPairs); - } - System.out.println(finalPairs.size()); - System.out.println(visitedClassPairs.size()); - if (finalPairs.size() != visitedClassPairs.size()) { - printDifference(visitedClassPairs, finalPairs); - } - } + } + finalPairs.addAll(allClassPairs); + // Now we will explore the inter-class method pairs + for (int j = 0; j < permutatedClasses.size() - 1; j++) { + String currentClass = permutatedClasses.get(j); + List currentMethods = classToPermutations.get(currentClass); + String lastMethod = currentMethods.get(currentMethods.size() - 1); + String nextClass = permutatedClasses.get(j + 1); + List nextMethods = classToPermutations.get(nextClass); + String firstMethod = nextMethods.get(0); - public static void printDifference(Set> visited, Set> expected) { - System.out.println("Difference: "); - for (List item : expected) { - if (expected.contains(item) && !visited.contains(item)) { - System.out.println(item); + List> allMethodPairs = generateAllMethodPairs(currentMethods, nextMethods); + + List newPair = new ArrayList(); + newPair.add(lastMethod); + newPair.add(firstMethod); + if (!allMethodPairs.contains(newPair)) { + System.out.println(newPair); + throw new Exception("Doents contain all method paris"); + } + if (!visitedMethodPairs.contains(newPair)) { + visitedMethodPairs.add(newPair); + } + finalPairsMethods.addAll(allMethodPairs); } } + Assert.assertEquals(finalPairs, visitedClassPairs); + Assert.assertEquals(finalPairsMethods, visitedMethodPairs); } public static List> generateAllPairs(List tests) { @@ -87,4 +107,17 @@ public static List> generateAllPairs(List tests) { } return allPairs; } + + public static List> generateAllMethodPairs(List currentMethods, List nextMethods) { + List> allPairs = new ArrayList<>(); + for (int i = 0; i < currentMethods.size(); i++) { + for (int j = 0; j < nextMethods.size(); j++) { + List newPair = new ArrayList(); + newPair.add(currentMethods.get(i)); + newPair.add(nextMethods.get(j)); + allPairs.add(newPair); + } + } + return allPairs; + } } \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/Test.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java similarity index 98% rename from idflakies-core/src/test/java/edu/illinois/Test.java rename to idflakies-core/src/test/java/edu/illinois/TuscanTest.java index 7418a3ea..1ea29c9f 100644 --- a/idflakies-core/src/test/java/edu/illinois/Test.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -12,7 +12,7 @@ import edu.illinois.cs.dt.tools.utility.Tuscan; @RunWith(Theories.class) -public class Test { +public class TuscanTest { private static int[][] matrix; @DataPoints From a489f2c220ef25622f4a2582ae27f3eba9a901bf Mon Sep 17 00:00:00 2001 From: mmk Date: Tue, 16 Aug 2022 19:51:34 +0300 Subject: [PATCH 26/40] fixed tests --- .../cs/dt/tools/detection/TestShuffler.java | 8 +++- .../illinois/cs/dt/tools/utility/Tuscan.java | 16 +++---- .../src/test/java/edu/illinois/Pair.java | 31 ------------- .../edu/illinois/TuscanInterClassTest.java | 4 +- .../edu/illinois/TuscanIntraClassTest.java | 31 +++++-------- .../edu/illinois/TuscanOnlyClassTest.java | 14 +++--- .../test/java/edu/illinois/TuscanTest.java | 44 ++++++++++++------- 7 files changed, 62 insertions(+), 86 deletions(-) delete mode 100644 idflakies-core/src/test/java/edu/illinois/Pair.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 23bbef49..d6fbc6db 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -248,7 +248,7 @@ public List tuscanIntraClassOrder(int round) { while ((classOrdering.length - 1) < classRound) { classRound -= classOrdering.length; } - for (int i = 0; i < classOrdering[classRound].length - 1; i++) { // {0, 1, 0} {1, 0, 0} + for (int i = 0; i < classOrdering[classRound].length - 1; i++) { permClasses.add(classes.get(classOrdering[classRound][i])); } for (String className : permClasses) { @@ -283,13 +283,16 @@ public List tuscanInterClass(int round) { int methodSize = classToMethods.get(className).size(); int[][] result; if (methodSize == 3) { + int[][] methodPermuation = { { 0, 1, 2, 0 }, { 1, 2, 0, 0 }, { 2, 0, 1, 0 }, }; result = methodPermuation; + } else if (methodSize == 5) { + int[][] methodPermuation = { { 0, 1, 2, 3, 4, 0 }, { 1, 0, 2, 4, 3, 0 }, @@ -298,9 +301,12 @@ public List tuscanInterClass(int round) { { 4, 1, 2, 3, 0, 0 }, }; result = methodPermuation; + } else { + int[][] methodPermuation = Tuscan.generateTuscanPermutations(methodSize); result = methodPermuation; + } classToPermutations.put(className, result); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index d53810e8..a3a3ced6 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -122,18 +122,18 @@ private static void generateOne() { } private static void generateThree() { - // int[][] t = { - // { 0, 1, 2, 0 }, - // { 1, 0, 2, 0 }, - // { 2, 0, 0 }, - // { 2, 1, 0 } - // }; int[][] t = { { 0, 1, 2, 0 }, { 1, 0, 2, 0 }, - { 2, 0, 1, 0 }, - { 2, 1, 0, 0 } + { 2, 0, 0 }, + { 2, 1, 0 } }; + // int[][] t = { + // { 0, 1, 2, 0 }, + // { 1, 0, 2, 0 }, + // { 2, 0, 1, 0 }, + // { 2, 1, 0, 0 } + // }; r = t; } diff --git a/idflakies-core/src/test/java/edu/illinois/Pair.java b/idflakies-core/src/test/java/edu/illinois/Pair.java deleted file mode 100644 index dc6bd597..00000000 --- a/idflakies-core/src/test/java/edu/illinois/Pair.java +++ /dev/null @@ -1,31 +0,0 @@ -package edu.illinois; - -import java.util.Objects; - -public class Pair { - private T x; - private T y; - - Pair(T x, T y) { - this.x = x; - this.y = y; - } - - public String toString() { - return "(" + this.x + ", " + this.y + ")"; - } - - @Override - public boolean equals(Object rhs) { - if (rhs instanceof Pair) { - Pair o = (Pair)rhs; - return this.x == o.x && this.y == o.y; - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(x, y); - } -} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java index 637488a3..1dd0285a 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java @@ -89,8 +89,8 @@ public void test() throws Exception { finalPairsMethods.addAll(allMethodPairs); } } - Assert.assertEquals(finalPairs, visitedClassPairs); - Assert.assertEquals(finalPairsMethods, visitedMethodPairs); + Assert.assertEquals(finalPairs.size(), visitedClassPairs.size()); + Assert.assertEquals(finalPairsMethods.size(), visitedMethodPairs.size()); } public static List> generateAllPairs(List tests) { diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index 9f6a77e1..fd17828b 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -45,8 +45,8 @@ public void test() throws Exception { // System.out.println(rounds); List classes = new ArrayList(); LinkedHashMap> classToMethods = new LinkedHashMap>(); - List> visitedMethodPairs = new ArrayList>(); - Set> allMethodPairs = new HashSet>(); + List> visitedMethodPairs = new ArrayList>(); + Set> allMethodPairs = new HashSet>(); for (int i = 0; i < rounds; i++) { List currentOrder = testShuffler.tuscanIntraClassOrder(i); for (String test : currentOrder) { @@ -59,21 +59,25 @@ public void test() throws Exception { } classToMethods.get(className).add(test); } - List> currentClassPairs = generateAllPairs(classes); + List> currentClassPairs = TuscanInterClassTest.generateAllPairs(classes); for (int j = 0; j < classes.size() - 1; j++) { // Check if class pairs are covered - Pair newPair = new Pair(classes.get(j), classes.get(j + 1)); + List newPair = new ArrayList(); + newPair.add(classes.get(j)); + newPair.add(classes.get(j + 1)); if (!currentClassPairs.contains(newPair)) { throw new Exception("Not included Classes"); } } for (String className : classes) { List currentMethodOrdering = classToMethods.get(className); - List> currentMethodPairs = generateAllPairs(currentMethodOrdering); + List> currentMethodPairs = TuscanInterClassTest.generateAllPairs(currentMethodOrdering); allMethodPairs.addAll(currentMethodPairs); // System.out.println(currentMethodPairs.size()); for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { - Pair newPair = new Pair(currentMethodOrdering.get(j), currentMethodOrdering.get(j + 1)); + List newPair = new ArrayList(); + newPair.add(currentMethodOrdering.get(j)); + newPair.add(currentMethodOrdering.get(j + 1)); if(!currentMethodPairs.contains(newPair)) { System.out.println(newPair); throw new Exception("Not included Method Pairs"); @@ -85,22 +89,9 @@ public void test() throws Exception { currentMethodOrdering.clear(); } } - Assert.assertEquals(visitedMethodPairs.size(), allMethodPairs.size()); + Assert.assertEquals(allMethodPairs.size(), visitedMethodPairs.size()); } - public static List> generateAllPairs(List tests) { - List> allPairs = new ArrayList>(); - for (int i = 0; i < tests.size(); i++) { - for (int j = 0; j < tests.size(); j++) { - if (tests.get(i) != tests.get(j)) { - Pair newPair = new Pair(tests.get(i), tests.get(j)); - allPairs.add(newPair); - } - } - } - return allPairs; - } - public static HashMap> generateClassToMethods (List tests) { HashMap> classToMethods = new HashMap<>(); for (final String test : tests) { diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index 615e69d0..a5762fd7 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -35,18 +35,18 @@ public void test() throws Exception { if (n == 3 || n == 5) { rounds++; } - List listOfPairs = new ArrayList(); + List> listOfPairs = new ArrayList>(); for (int i = 0; i < rounds; i++) { List currentOrder = testShuffler.alphabeticalAndTuscanOrder(i, true); Set classes = new LinkedHashSet(); - // System.out.println("currentORder.size()" + currentOrder.size()); for (int j = 0; j < currentOrder.size(); j++) { classes.add(TestShuffler.className(currentOrder.get(j))); } - // System.out.println("classes.size()" + classes.size()); String[] classesArray = classes.toArray(new String[classes.size()]); for (int j = 0; j < classesArray.length - 1; j++) { - Pair newPair = new Pair(classesArray[j], classesArray[j + 1]); + List newPair = new ArrayList(); + newPair.add(classesArray[j]); + newPair.add(classesArray[j + 1]); if (listOfPairs.contains(newPair)) { throw new Exception("new"); } @@ -54,10 +54,6 @@ public void test() throws Exception { } } int count = listOfPairs.size(); - if (n == 5) { - Assert.assertEquals(count, 21); - } else { - Assert.assertEquals(count, n * (n - 1)); - } + Assert.assertEquals(count, n * (n - 1)); } } \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java index 1ea29c9f..850ba752 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -3,6 +3,7 @@ import java.util.*; import java.util.stream.IntStream; +import org.checkerframework.checker.units.qual.A; import org.junit.Assert; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; @@ -13,7 +14,7 @@ @RunWith(Theories.class) public class TuscanTest { - private static int[][] matrix; + // private static int[][] matrix; @DataPoints public static int[] integers() { @@ -24,25 +25,38 @@ public static int[] integers() { @Theory public void test(int n) throws Exception { int count; - List> s = new ArrayList>(); - matrix = Tuscan.generateTuscanPermutations(n); - // System.out.println("Tuscan " + n + ":"); + int[][] matrix = Tuscan.generateTuscanPermutations(n); + Set> finalPairs = new LinkedHashSet>(); + Set> visitedPairs = new LinkedHashSet>(); for (int i = 0; i < matrix.length; i++) { + List> allPairs = generateAllPairs(matrix[i]); for (int j = 0; j < matrix[i].length - 2; j++) { - Pair newPair = new Pair(matrix[i][j], matrix[i][j + 1]); - if (n != 3 && n != 5 && s.contains(newPair)) { - throw new Exception("Not unique"); + // All rows will have an extra 0 at the end hence we have -2 + List newPair = new ArrayList(); + newPair.add(matrix[i][j]); + newPair.add(matrix[i][j + 1]); + if (!allPairs.contains(newPair)) { + throw new Exception("Does not contain pair"); } - s.add(newPair); + visitedPairs.add(newPair); } + finalPairs.addAll(allPairs); } - count = s.size(); - if (n == 5) { - Assert.assertEquals(count, 21); - } else if (n == 3) { - Assert.assertEquals(count, 8); - } else { - Assert.assertEquals(n * (n - 1), count); + Assert.assertEquals(finalPairs.size(), visitedPairs.size()); + } + + private static List> generateAllPairs (int[] row) { + List> allPairs = new ArrayList<>(); + for (int i = 0; i < row.length - 1; i++) { + for (int j = 0; j < row.length - 1; j++) { + if (row[i] != row[j]) { + List newPair = new ArrayList(); + newPair.add(row[i]); + newPair.add(row[j]); + allPairs.add(newPair); + } + } } + return allPairs; } } \ No newline at end of file From 964d15012e399f6f976e3e5b2abe706adafdd75b Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 17 Aug 2022 10:56:59 +0300 Subject: [PATCH 27/40] fixed onlyclass --- .../edu/illinois/TuscanInterClassTest.java | 26 +++++------ .../edu/illinois/TuscanIntraClassTest.java | 10 ++--- .../edu/illinois/TuscanOnlyClassTest.java | 44 +++++++++++-------- .../test/java/edu/illinois/TuscanTest.java | 5 +-- 4 files changed, 43 insertions(+), 42 deletions(-) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java index 1dd0285a..389c6727 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java @@ -2,8 +2,6 @@ import java.util.*; -import javax.annotation.security.PermitAll; - import org.junit.Assert; import org.junit.Test; @@ -14,17 +12,19 @@ public class TuscanInterClassTest { @Test public void test() throws Exception { - String[] testArray = { "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + String[] testArray = { + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMock1", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" + }; List tests = Arrays.asList(testArray); HashMap> tempClassToMethods = TuscanIntraClassTest.generateClassToMethods(tests); int rounds = TuscanInterClassDetector.findNumberOfRounds(tempClassToMethods); @@ -60,9 +60,7 @@ public void test() throws Exception { if (!(allClassPairs.contains(newPair))) { throw new Exception("Not included pair"); } - if (!visitedClassPairs.contains(newPair)) { - visitedClassPairs.add(newPair); - } + visitedClassPairs.add(newPair); } finalPairs.addAll(allClassPairs); // Now we will explore the inter-class method pairs @@ -81,7 +79,7 @@ public void test() throws Exception { newPair.add(firstMethod); if (!allMethodPairs.contains(newPair)) { System.out.println(newPair); - throw new Exception("Doents contain all method paris"); + throw new Exception("Doesn't contain all method pairs"); } if (!visitedMethodPairs.contains(newPair)) { visitedMethodPairs.add(newPair); @@ -120,4 +118,4 @@ public static List> generateAllMethodPairs(List currentMeth } return allPairs; } -} \ No newline at end of file +} diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index fd17828b..4870057b 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -15,7 +15,8 @@ public class TuscanIntraClassTest { @Test public void test() throws Exception { - String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + String[] testArray = { + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", @@ -23,7 +24,8 @@ public void test() throws Exception { "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" + }; List tests = Arrays.asList(testArray); TestShuffler testShuffler = new TestShuffler("", 0, tests, null); // int n = TuscanOnlyClassDetector.getClassesSize(tests); @@ -42,7 +44,6 @@ public void test() throws Exception { } else { rounds = maxMethodSize; } - // System.out.println(rounds); List classes = new ArrayList(); LinkedHashMap> classToMethods = new LinkedHashMap>(); List> visitedMethodPairs = new ArrayList>(); @@ -73,7 +74,6 @@ public void test() throws Exception { List currentMethodOrdering = classToMethods.get(className); List> currentMethodPairs = TuscanInterClassTest.generateAllPairs(currentMethodOrdering); allMethodPairs.addAll(currentMethodPairs); - // System.out.println(currentMethodPairs.size()); for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { List newPair = new ArrayList(); newPair.add(currentMethodOrdering.get(j)); @@ -103,4 +103,4 @@ public static HashMap> generateClassToMethods (List } return classToMethods; } -} \ No newline at end of file +} diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index a5762fd7..982ad9e8 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -1,10 +1,8 @@ package edu.illinois; import java.util.ArrayList; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import org.junit.Assert; @@ -13,12 +11,12 @@ import edu.emory.mathcs.backport.java.util.Arrays; import edu.illinois.cs.dt.tools.detection.TestShuffler; import edu.illinois.cs.dt.tools.detection.detectors.TuscanOnlyClassDetector; -import scala.collection.mutable.ArrayBuilder.ofBoolean; public class TuscanOnlyClassTest { @Test public void test() throws Exception { - String[] testArray = {"cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + String[] testArray = { + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", @@ -26,7 +24,8 @@ public void test() throws Exception { "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode"}; + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" + }; List tests = Arrays.asList(testArray); // System.out.println(tests); TestShuffler testShuffler = new TestShuffler("", 0, tests, null); @@ -35,25 +34,32 @@ public void test() throws Exception { if (n == 3 || n == 5) { rounds++; } - List> listOfPairs = new ArrayList>(); + Set> finalPairs = new LinkedHashSet>(); + Set> visitedPairs = new LinkedHashSet>(); + for (int i = 0; i < rounds; i++) { - List currentOrder = testShuffler.alphabeticalAndTuscanOrder(i, true); - Set classes = new LinkedHashSet(); - for (int j = 0; j < currentOrder.size(); j++) { - classes.add(TestShuffler.className(currentOrder.get(j))); + List currentRoundPermutation = testShuffler.alphabeticalAndTuscanOrder(i, true); + List permutatedClasses = new ArrayList(); + for (String test : currentRoundPermutation) { + String className = TestShuffler.className(test); + // classes.add(TestShuffler.className(currentOrder.get(j))); + if (!permutatedClasses.contains(className)) { + permutatedClasses.add(className); + } } - String[] classesArray = classes.toArray(new String[classes.size()]); - for (int j = 0; j < classesArray.length - 1; j++) { + List> allPairs = TuscanInterClassTest.generateAllPairs(permutatedClasses); + for (int j = 0; j < permutatedClasses.size() - 1; j++) { List newPair = new ArrayList(); - newPair.add(classesArray[j]); - newPair.add(classesArray[j + 1]); - if (listOfPairs.contains(newPair)) { - throw new Exception("new"); + newPair.add(permutatedClasses.get(j)); + newPair.add(permutatedClasses.get(j + 1)); + if (!allPairs.contains(newPair)) { + throw new Exception("Class pair is not covered"); } - listOfPairs.add(newPair); + visitedPairs.add(newPair); } + finalPairs.addAll(allPairs); } - int count = listOfPairs.size(); + int count = finalPairs.size(); Assert.assertEquals(count, n * (n - 1)); } -} \ No newline at end of file +} diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java index 850ba752..8f6297d3 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -3,7 +3,6 @@ import java.util.*; import java.util.stream.IntStream; -import org.checkerframework.checker.units.qual.A; import org.junit.Assert; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; @@ -14,7 +13,6 @@ @RunWith(Theories.class) public class TuscanTest { - // private static int[][] matrix; @DataPoints public static int[] integers() { @@ -24,7 +22,6 @@ public static int[] integers() { @Theory public void test(int n) throws Exception { - int count; int[][] matrix = Tuscan.generateTuscanPermutations(n); Set> finalPairs = new LinkedHashSet>(); Set> visitedPairs = new LinkedHashSet>(); @@ -59,4 +56,4 @@ private static List> generateAllPairs (int[] row) { } return allPairs; } -} \ No newline at end of file +} From 9c505cd8b5fe2443b2d0a84f264a399f5f4d5cd2 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 17 Aug 2022 10:58:34 +0300 Subject: [PATCH 28/40] fixed whitespaced --- .../java/edu/illinois/cs/dt/tools/utility/Tuscan.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index a3a3ced6..f5c24104 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -3,13 +3,21 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { if (arg == 1) { + generateOne(); + } else if (arg == 3) { + generateThree(); + } else if (arg == 5) { + generateFive(); + } else { + generateTuscanSquare(arg); + } return r; } From 4087f5e2c1266d187f65f3f0f3f207953badf714 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 17 Aug 2022 16:28:22 +0300 Subject: [PATCH 29/40] added alphabetical-class-method --- .../cs/dt/tools/detection/TestShuffler.java | 17 +++++++++++++++++ .../detectors/AlphabeticalDetector.java | 2 +- .../detection/detectors/DetectorFactory.java | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index d6fbc6db..640a8e99 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -202,6 +202,23 @@ private int permutations(final int accum, final Iterator> iterator, } } + public List alphabeticalOrderSelector(int round) { + if (this.type.equals("alphabetical-class-method")) { + return alphabeticalClassMethodOrder(); + } else { + return alphabeticalAndTuscanOrder(round, false); + } + } + + private List alphabeticalClassMethodOrder() { + final List fullTestOrder = new ArrayList<>(); + for (String className : classToMethods.keySet()) { + fullTestOrder.addAll(classToMethods.get(className)); + } + Collections.sort(fullTestOrder); + return fullTestOrder; + } + public List alphabeticalAndTuscanOrder(int count, boolean isTuscan) { List classes = new ArrayList<>(classToMethods.keySet()); Collections.sort(classes); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index 5a859362..2fd94cbe 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -33,7 +33,7 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r @Override public DetectionRound results() throws Exception { - return makeDts(origResult, runList(testShuffler.alphabeticalAndTuscanOrder(absoluteRound.get(), false))); + return makeDts(origResult, runList(testShuffler.alphabeticalOrderSelector(absoluteRound.get()))); } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 3a3ba305..1035bdcc 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -27,7 +27,7 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); } else if (detectorType().equals("tuscan")){ return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); - } else if (detectorType().equals("alphabetical")) { + } else if (detectorType().startsWith("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("tuscan-intra-class")) { return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); From 1b40aea5d14c4c5a5ea8b5f266bb2498545581de Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 17 Aug 2022 18:50:01 +0300 Subject: [PATCH 30/40] fixed empty line --- .../cs/dt/tools/detection/TestShuffler.java | 19 ++++++++++--------- .../illinois/cs/dt/tools/utility/Tuscan.java | 9 +-------- .../test/java/edu/illinois/TuscanTest.java | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index 640a8e99..53a0d789 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -249,15 +249,16 @@ public List tuscanIntraClassOrder(int round) { int n = classes.size(); // n is number of classes int[][] classOrdering = Tuscan.generateTuscanPermutations(n); for (String className : classes) { - if (classToMethods.get(className).size() == 1) { - int[][] methodPermuation = { - { 0, 0 } - }; - classToPermutations.put(className, methodPermuation); - } else { - int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); - classToPermutations.put(className, methodPermuation); - } + // This condition may be needed for the tests + // if (classToMethods.get(className).size() == 1) { + // int[][] methodPermuation = { + // { 0, 0 } + // }; + // classToPermutations.put(className, methodPermuation); + // } else { + int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); + classToPermutations.put(className, methodPermuation); + // } } HashMap> newClassToMethods = new HashMap>(); List permClasses = new ArrayList(); diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index f5c24104..c0dffa1a 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -3,24 +3,17 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { if (arg == 1) { - generateOne(); - } else if (arg == 3) { - generateThree(); - } else if (arg == 5) { - generateFive(); - } else { - generateTuscanSquare(arg); - } return r; } + private static int[][] r; private static void helper(int[] a, int i) { diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java index 8f6297d3..0e60af59 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -16,7 +16,7 @@ public class TuscanTest { @DataPoints public static int[] integers() { - int[] range = IntStream.rangeClosed(2, 20).toArray(); + int[] range = IntStream.rangeClosed(1, 20).toArray(); return range; } From 9a0dafdeeaebc8fb674d63078840eb1a5d7e93ad Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 20 Aug 2022 15:41:12 +0300 Subject: [PATCH 31/40] reflected PR #48 changes --- .../cs/dt/tools/detection/detectors/AlphabeticalDetector.java | 1 - .../dt/tools/detection/detectors/TuscanOnlyClassDetector.java | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java index 2fd94cbe..27f805d0 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/AlphabeticalDetector.java @@ -35,5 +35,4 @@ public AlphabeticalDetector(final Runner runner, final File baseDir, final int r public DetectionRound results() throws Exception { return makeDts(origResult, runList(testShuffler.alphabeticalOrderSelector(absoluteRound.get()))); } - } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java index e0033d39..1506596c 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanOnlyClassDetector.java @@ -36,7 +36,7 @@ public TuscanOnlyClassDetector(final Runner runner, final File baseDir, final in if (n == 3 || n == 5) { // We need one more round than the number of classes if n is 3 or 5. if (this.rounds > n) { - this.rounds = n + 1; + this.rounds = n + 1; } } else { if (this.rounds > n) { @@ -58,5 +58,4 @@ public TuscanOnlyClassDetector(final Runner runner, final File baseDir, final in public DetectionRound results() throws Exception { return makeDts(origResult, runList(testShuffler.alphabeticalAndTuscanOrder(absoluteRound.get(), true))); } - } From 6e3a51118a4166fa7a49e762c104f56824e02e84 Mon Sep 17 00:00:00 2001 From: mmk Date: Sun, 21 Aug 2022 11:39:34 +0300 Subject: [PATCH 32/40] fixed assertion error --- .../dt/tools/detection/detectors/DetectorFactory.java | 1 - .../java/edu/illinois/cs/dt/tools/utility/Tuscan.java | 11 ++++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 1035bdcc..8201cb9d 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,7 +1,6 @@ package edu.illinois.cs.dt.tools.detection.detectors; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; -import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 131f865d..0ce926c5 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -2,7 +2,9 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { - if (arg == 3) { + if (arg == 1) { + generateOne(); + } else if (arg == 3) { generateThree(); } else if (arg == 5) { generateFive(); @@ -113,6 +115,13 @@ private static void generateTuscanSquare(int n) { } } + private static void generateOne() { + int[][] t = { + { 0, 0 } + }; + r = t; + } + private static void generateThree() { int[][] t = { { 0, 1, 2, 0 }, From 24e0e51b00d1c6fbc3655c67b629e0e359e730d8 Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 27 Aug 2022 20:20:11 +0300 Subject: [PATCH 33/40] moved tuscan-inter-class to another branch --- .../cs/dt/tools/detection/TestShuffler.java | 108 ---------------- .../detection/detectors/DetectorFactory.java | 2 - .../detectors/TuscanInterClassDetector.java | 92 ------------- .../edu/illinois/TuscanInterClassTest.java | 121 ------------------ .../edu/illinois/TuscanIntraClassTest.java | 19 ++- .../edu/illinois/TuscanOnlyClassTest.java | 17 ++- 6 files changed, 33 insertions(+), 326 deletions(-) delete mode 100644 idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java delete mode 100644 idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index a093802a..ad31ada1 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -38,13 +38,6 @@ public static String className(final String testName) { private final List tests; private final Set alreadySeenOrders = new HashSet<>(); private final File baseDir; - // For tuscanInterClass - private static int interClassRound = 0; // which class permutation to choose - private static int interCurrentMethodRound = 0; // first class of pair - private static int interNextMethodRound = 0; // second class of pair - private static int i1 = 0; // current class - private static int i2 = 1; // next class - private static boolean isNewOrdering = false; // To change the permutation of classes private final Random random; @@ -288,105 +281,4 @@ public List tuscanIntraClassOrder(int round) { } return fullTestOrder; } - - public List tuscanInterClass(int round) { - List classes = new ArrayList<>(classToMethods.keySet()); - HashMap classToPermutations = new HashMap(); - Collections.sort(classes); - final List fullTestOrder = new ArrayList<>(); - int n = classes.size(); // n is number of classes - int[][] classOrdering = Tuscan.generateTuscanPermutations(n); - - for (String className : classes) { - int methodSize = classToMethods.get(className).size(); - int[][] result; - if (methodSize == 3) { - - int[][] methodPermuation = { - { 0, 1, 2, 0 }, - { 1, 2, 0, 0 }, - { 2, 0, 1, 0 }, - }; - result = methodPermuation; - - } else if (methodSize == 5) { - - int[][] methodPermuation = { - { 0, 1, 2, 3, 4, 0 }, - { 1, 0, 2, 4, 3, 0 }, - { 2, 4, 0, 3, 1, 0 }, - { 3, 1, 0, 4, 2, 0 }, - { 4, 1, 2, 3, 0, 0 }, - }; - result = methodPermuation; - - } else { - - int[][] methodPermuation = Tuscan.generateTuscanPermutations(methodSize); - result = methodPermuation; - - } - classToPermutations.put(className, result); - } - HashMap> newClassToMethods = new HashMap>(); // class to permutated methods - List permClasses = new ArrayList(); - if (isNewOrdering) { - // When we reach end of a permutation for classes only - i1 = 0; - i2 = 1; - interNextMethodRound = 0; - interCurrentMethodRound = 0; - interClassRound++; - isNewOrdering = false; - } - for (int i = 0; i < classOrdering[interClassRound].length - 1; i++) { - permClasses.add(classes.get(classOrdering[interClassRound][i])); - } - String currentClass = permClasses.get(i1), nextClass = permClasses.get(i2); - int currentClassMethodSize = classToMethods.get(currentClass).size(); - int nextClassMethodSize = classToMethods.get(nextClass).size(); - if (currentClassMethodSize == interCurrentMethodRound && nextClassMethodSize == (interNextMethodRound + 1)) { - // To change the pair so we change i1 & i2 - i1++; - i2++; - interNextMethodRound = 0; - interCurrentMethodRound = 0; - } - else if (currentClassMethodSize == (interCurrentMethodRound)) { - // To change the *next* class methods - interNextMethodRound++; - interCurrentMethodRound = 0; - } - int[] currentClassTuscan = classToPermutations.get(currentClass)[interCurrentMethodRound]; - int[] nextClassTuscan = classToPermutations.get(nextClass)[interNextMethodRound]; - for (String className : permClasses) { - List methods = classToMethods.get(className); - List permMethods = new ArrayList(); - if (className == currentClass) { - for (int i = 0; i < currentClassTuscan.length - 1; i++) { - permMethods.add(methods.get(currentClassTuscan[i])); - } - } - else if (className == nextClass) { - for (int i = 0; i < nextClassTuscan.length - 1; i++) { - permMethods.add(methods.get(nextClassTuscan[i])); - } - } else { - // We don't care about this classes permutations yet - for (int i = 0; i < nextClassTuscan.length; i++) { - permMethods = methods; - } - } - newClassToMethods.put(className, permMethods); - } - for (String className : permClasses) { - fullTestOrder.addAll(newClassToMethods.get(className)); - } - interCurrentMethodRound++; - if (nextClass == permClasses.get(permClasses.size() - 1) && currentClassMethodSize == interCurrentMethodRound && nextClassMethodSize == (interNextMethodRound + 1)) { - // if the *next class* is our last class then there is no pair so change to the next order - isNewOrdering = true; - } - return fullTestOrder; - } } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 8201cb9d..936edd18 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -30,8 +30,6 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("tuscan-intra-class")) { return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); - } else if (detectorType().equals("tuscan-inter-class")) { - return new TuscanInterClassDetector(runner, baseDir, rounds, detectorType(), tests); } return new RandomDetector("random", baseDir, runner, rounds, tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java deleted file mode 100644 index 46bb9e72..00000000 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanInterClassDetector.java +++ /dev/null @@ -1,92 +0,0 @@ -package edu.illinois.cs.dt.tools.detection.detectors; - -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import edu.emory.mathcs.backport.java.util.Collections; -import edu.illinois.cs.dt.tools.detection.DetectionRound; -import edu.illinois.cs.dt.tools.detection.DetectorUtil; -import edu.illinois.cs.dt.tools.detection.TestShuffler; -import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; -import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; -import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; -import edu.illinois.cs.dt.tools.utility.Tuscan; -import edu.illinois.cs.testrunner.data.results.TestRunResult; -import edu.illinois.cs.testrunner.runner.Runner; - -public class TuscanInterClassDetector extends ExecutingDetector { - private final List tests; - private TestRunResult origResult; - - private final HashMap> classToMethods; - private final TestShuffler testShuffler; - - public static int getClassesSize(List tests) { - List classes = new ArrayList(); - for (final String test : tests) { - final String className = TestShuffler.className(test); - if (!classes.contains(className)) { - classes.add(className); - } - } - return classes.size(); - } - - public static int findNumberOfRounds (HashMap> classToMethods) { - int classSize = classToMethods.keySet().size(); - List classes = new ArrayList<>(classToMethods.keySet()); - Collections.sort(classes); - int[][] classPermutations = Tuscan.generateTuscanPermutations(classSize); - HashMap classToSize = new HashMap<>(); - for (String className : classToMethods.keySet()) { - classToSize.put(className, classToMethods.get(className).size()); - } - int tempRounds = 0; - for (int i = 0; i < classPermutations.length; i++) { - int methodSize = 0; - for (int j = 0; j < classPermutations[i].length - 2; j++) { - String current = classes.get(classPermutations[i][j]); - String next = classes.get(classPermutations[i][j + 1]); - int size1 = classToMethods.get(current).size(); - int size2 = classToMethods.get(next).size(); - methodSize += (size1 * size2); - } - tempRounds += methodSize; - } - return tempRounds; - } - - public TuscanInterClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List tests) { - super(runner, baseDir, rounds, type); - classToMethods = new HashMap<>(); - for (final String test : tests) { - final String className = TestShuffler.className(test); - if (!classToMethods.containsKey(className)) { - classToMethods.put(className, new ArrayList<>()); - } - classToMethods.get(className).add(test); - } - int tempRounds = findNumberOfRounds(classToMethods); - if (rounds > tempRounds) { - this.rounds = tempRounds; - } else { - this.rounds = rounds; - } - this.tests = tests; - this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); - this.origResult = DetectorUtil.originalResults(tests, runner); - if (runner instanceof InstrumentingSmartRunner) { - addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); - } else { - addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); - } - addFilter(new UniqueFilter()); - } - - @Override - public DetectionRound results() throws Exception { - return makeDts(origResult, runList(testShuffler.tuscanInterClass(absoluteRound.get()))); - } -} diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java deleted file mode 100644 index 389c6727..00000000 --- a/idflakies-core/src/test/java/edu/illinois/TuscanInterClassTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package edu.illinois; - -import java.util.*; - -import org.junit.Assert; -import org.junit.Test; - -import edu.emory.mathcs.backport.java.util.Arrays; -import edu.illinois.cs.dt.tools.detection.TestShuffler; -import edu.illinois.cs.dt.tools.detection.detectors.TuscanInterClassDetector; - -public class TuscanInterClassTest { - @Test - public void test() throws Exception { - String[] testArray = { - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey1", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", - "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMock1", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" - }; - List tests = Arrays.asList(testArray); - HashMap> tempClassToMethods = TuscanIntraClassTest.generateClassToMethods(tests); - int rounds = TuscanInterClassDetector.findNumberOfRounds(tempClassToMethods); - TestShuffler testShuffler = new TestShuffler("", 0, tests, null); - List classes = new ArrayList(); - Set> finalPairs = new LinkedHashSet>(); - Set> visitedClassPairs = new LinkedHashSet>(); - Set> visitedMethodPairs = new LinkedHashSet>(); - Set> finalPairsMethods= new LinkedHashSet>(); - for (int i = 0; i < rounds; i++) { - List currentRoundPermutation = testShuffler.tuscanInterClass(i); - List permutatedClasses = new ArrayList(); - HashMap> classToPermutations = new HashMap>(); - for (String testName : currentRoundPermutation) { - String className = TestShuffler.className(testName); - if (!permutatedClasses.contains(className)) { - permutatedClasses.add(className); - } - if (!classes.contains(className)) { - classes.add(className); - } - if (!classToPermutations.containsKey(className)) { - classToPermutations.put(className, new ArrayList<>()); - } - classToPermutations.get(className).add(testName); - } - List> allClassPairs = generateAllPairs(classes); - for (int j = 0; j < permutatedClasses.size() - 1; j++) { - List newPair = new ArrayList(); - newPair.add(permutatedClasses.get(j)); - newPair.add(permutatedClasses.get(j + 1)); - // System.out.println(newPair); - if (!(allClassPairs.contains(newPair))) { - throw new Exception("Not included pair"); - } - visitedClassPairs.add(newPair); - } - finalPairs.addAll(allClassPairs); - // Now we will explore the inter-class method pairs - for (int j = 0; j < permutatedClasses.size() - 1; j++) { - String currentClass = permutatedClasses.get(j); - List currentMethods = classToPermutations.get(currentClass); - String lastMethod = currentMethods.get(currentMethods.size() - 1); - String nextClass = permutatedClasses.get(j + 1); - List nextMethods = classToPermutations.get(nextClass); - String firstMethod = nextMethods.get(0); - - List> allMethodPairs = generateAllMethodPairs(currentMethods, nextMethods); - - List newPair = new ArrayList(); - newPair.add(lastMethod); - newPair.add(firstMethod); - if (!allMethodPairs.contains(newPair)) { - System.out.println(newPair); - throw new Exception("Doesn't contain all method pairs"); - } - if (!visitedMethodPairs.contains(newPair)) { - visitedMethodPairs.add(newPair); - } - finalPairsMethods.addAll(allMethodPairs); - } - } - Assert.assertEquals(finalPairs.size(), visitedClassPairs.size()); - Assert.assertEquals(finalPairsMethods.size(), visitedMethodPairs.size()); - } - - public static List> generateAllPairs(List tests) { - List> allPairs = new ArrayList<>(); - for (int i = 0; i < tests.size(); i++) { - for (int j = 0; j < tests.size(); j++) { - if (tests.get(i) != tests.get(j)) { - List newPair = new ArrayList(); - newPair.add(tests.get(i)); - newPair.add(tests.get(j)); - allPairs.add(newPair); - } - } - } - return allPairs; - } - - public static List> generateAllMethodPairs(List currentMethods, List nextMethods) { - List> allPairs = new ArrayList<>(); - for (int i = 0; i < currentMethods.size(); i++) { - for (int j = 0; j < nextMethods.size(); j++) { - List newPair = new ArrayList(); - newPair.add(currentMethods.get(i)); - newPair.add(nextMethods.get(j)); - allPairs.add(newPair); - } - } - return allPairs; - } -} diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index 4870057b..1e55472f 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -60,7 +60,7 @@ public void test() throws Exception { } classToMethods.get(className).add(test); } - List> currentClassPairs = TuscanInterClassTest.generateAllPairs(classes); + List> currentClassPairs = generateAllPairs(classes); for (int j = 0; j < classes.size() - 1; j++) { // Check if class pairs are covered List newPair = new ArrayList(); @@ -72,7 +72,7 @@ public void test() throws Exception { } for (String className : classes) { List currentMethodOrdering = classToMethods.get(className); - List> currentMethodPairs = TuscanInterClassTest.generateAllPairs(currentMethodOrdering); + List> currentMethodPairs = generateAllPairs(currentMethodOrdering); allMethodPairs.addAll(currentMethodPairs); for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { List newPair = new ArrayList(); @@ -103,4 +103,19 @@ public static HashMap> generateClassToMethods (List } return classToMethods; } + + public static List> generateAllPairs(List tests) { + List> allPairs = new ArrayList<>(); + for (int i = 0; i < tests.size(); i++) { + for (int j = 0; j < tests.size(); j++) { + if (tests.get(i) != tests.get(j)) { + List newPair = new ArrayList(); + newPair.add(tests.get(i)); + newPair.add(tests.get(j)); + allPairs.add(newPair); + } + } + } + return allPairs; + } } diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index 982ad9e8..6ec70c5d 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -47,7 +47,7 @@ public void test() throws Exception { permutatedClasses.add(className); } } - List> allPairs = TuscanInterClassTest.generateAllPairs(permutatedClasses); + List> allPairs = generateAllPairs(permutatedClasses); for (int j = 0; j < permutatedClasses.size() - 1; j++) { List newPair = new ArrayList(); newPair.add(permutatedClasses.get(j)); @@ -62,4 +62,19 @@ public void test() throws Exception { int count = finalPairs.size(); Assert.assertEquals(count, n * (n - 1)); } + + public static List> generateAllPairs(List tests) { + List> allPairs = new ArrayList<>(); + for (int i = 0; i < tests.size(); i++) { + for (int j = 0; j < tests.size(); j++) { + if (tests.get(i) != tests.get(j)) { + List newPair = new ArrayList(); + newPair.add(tests.get(i)); + newPair.add(tests.get(j)); + allPairs.add(newPair); + } + } + } + return allPairs; + } } From 0db2f7d627658c8015c1c4ba249912af0eeec901 Mon Sep 17 00:00:00 2001 From: "M. Mahdi Khosravi" Date: Sat, 27 Aug 2022 23:14:51 +0300 Subject: [PATCH 34/40] Revert "fixed assertion error" This reverts commit 6e3a51118a4166fa7a49e762c104f56824e02e84. --- .../dt/tools/detection/detectors/DetectorFactory.java | 1 + .../java/edu/illinois/cs/dt/tools/utility/Tuscan.java | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 936edd18..62cf9242 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -1,6 +1,7 @@ package edu.illinois.cs.dt.tools.detection.detectors; import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; +import edu.illinois.cs.dt.tools.utility.Tuscan; import edu.illinois.cs.testrunner.configuration.Configuration; import java.io.File; diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 0ce926c5..131f865d 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -2,9 +2,7 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { - if (arg == 1) { - generateOne(); - } else if (arg == 3) { + if (arg == 3) { generateThree(); } else if (arg == 5) { generateFive(); @@ -115,13 +113,6 @@ private static void generateTuscanSquare(int n) { } } - private static void generateOne() { - int[][] t = { - { 0, 0 } - }; - r = t; - } - private static void generateThree() { int[][] t = { { 0, 1, 2, 0 }, From c635c0b81c8680b4646baeaf81b64858cf397a3a Mon Sep 17 00:00:00 2001 From: mmk Date: Sat, 27 Aug 2022 23:30:17 +0300 Subject: [PATCH 35/40] fixed tuscan assert error --- .../java/edu/illinois/cs/dt/tools/utility/Tuscan.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java index 131f865d..0ce926c5 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/utility/Tuscan.java @@ -2,7 +2,9 @@ public class Tuscan { public static int[][] generateTuscanPermutations(int arg) { - if (arg == 3) { + if (arg == 1) { + generateOne(); + } else if (arg == 3) { generateThree(); } else if (arg == 5) { generateFive(); @@ -113,6 +115,13 @@ private static void generateTuscanSquare(int n) { } } + private static void generateOne() { + int[][] t = { + { 0, 0 } + }; + r = t; + } + private static void generateThree() { int[][] t = { { 0, 1, 2, 0 }, From dd81e59ceb2d620cff90c2cc71da3f18acd33097 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 7 Sep 2022 12:13:19 +0300 Subject: [PATCH 36/40] fixed PR #49 commented issues --- .../cs/dt/tools/detection/TestShuffler.java | 10 ++------- .../detection/detectors/DetectorFactory.java | 4 ++-- .../detectors/TuscanIntraClassDetector.java | 14 ++++++------- .../edu/illinois/TuscanIntraClassTest.java | 21 +++++++++---------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java index ad31ada1..7de17441 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/TestShuffler.java @@ -242,21 +242,15 @@ public List tuscanIntraClassOrder(int round) { int n = classes.size(); // n is number of classes int[][] classOrdering = Tuscan.generateTuscanPermutations(n); for (String className : classes) { - // This condition may be needed for the tests - // if (classToMethods.get(className).size() == 1) { - // int[][] methodPermuation = { - // { 0, 0 } - // }; - // classToPermutations.put(className, methodPermuation); - // } else { int[][] methodPermuation = Tuscan.generateTuscanPermutations(classToMethods.get(className).size()); classToPermutations.put(className, methodPermuation); - // } } HashMap> newClassToMethods = new HashMap>(); List permClasses = new ArrayList(); int classRound = round; while ((classOrdering.length - 1) < classRound) { + // When a intra-class method ordering has covered all pairs but other classes not, + // it will start to loop through the intra-class method ordering again until all rounds are done. classRound -= classOrdering.length; } for (int i = 0; i < classOrdering[classRound].length - 1; i++) { diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java index 62cf9242..b99a2452 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/DetectorFactory.java @@ -25,10 +25,10 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final return new OriginalDetector(runner, baseDir, rounds, tests); } else if (detectorType().equals("smart-shuffle")) { return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); - } else if (detectorType().equals("tuscan")){ - return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().startsWith("alphabetical")) { return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); + } else if (detectorType().equals("tuscan")) { + return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); } else if (detectorType().equals("tuscan-intra-class")) { return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); } diff --git a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java index 4e237715..46a4705b 100644 --- a/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java +++ b/idflakies-core/src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java @@ -36,7 +36,7 @@ public static int findMaxMethodSize(HashMap> classToMethods int maxMethodSize = 0; for (String className : classToMethods.keySet()) { int nn = classToMethods.get(className).size(); - if(maxMethodSize < nn) { + if (maxMethodSize < nn) { maxMethodSize = nn; } } @@ -54,13 +54,13 @@ public TuscanIntraClassDetector(final Runner runner, final File baseDir, final i classToMethods.get(className).add(test); } int classSize = classToMethods.keySet().size(); - // if (classSize == 3 || classSize == 5) { - // classSize++; - // } + if (classSize == 3 || classSize == 5) { + classSize++; + } int maxMethodSize = findMaxMethodSize(classToMethods); - // if (maxMethodSize == 3 || maxMethodSize == 5) { - // maxMethodSize++; - // } + if (maxMethodSize == 3 || maxMethodSize == 5) { + maxMethodSize++; + } this.rounds = rounds; if (classSize > maxMethodSize) { if (this.rounds > classSize) { diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index 1e55472f..a844a6de 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -16,19 +16,18 @@ public class TuscanIntraClassTest { @Test public void test() throws Exception { String[] testArray = { - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", - "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" }; List tests = Arrays.asList(testArray); TestShuffler testShuffler = new TestShuffler("", 0, tests, null); - // int n = TuscanOnlyClassDetector.getClassesSize(tests); HashMap> tempClassToMethods = generateClassToMethods(tests); int maxMethodSize = TuscanIntraClassDetector.findMaxMethodSize(tempClassToMethods); if (maxMethodSize == 3 || maxMethodSize == 5) { @@ -92,7 +91,7 @@ public void test() throws Exception { Assert.assertEquals(allMethodPairs.size(), visitedMethodPairs.size()); } - public static HashMap> generateClassToMethods (List tests) { + public static HashMap> generateClassToMethods(List tests) { HashMap> classToMethods = new HashMap<>(); for (final String test : tests) { final String className = TestShuffler.className(test); From f2dade2cb128e007e2a4e00423e9c43f22a9f821 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 7 Sep 2022 12:38:50 +0300 Subject: [PATCH 37/40] indentation --- .../edu/illinois/TuscanOnlyClassTest.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index 6ec70c5d..a5e92aef 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -16,18 +16,17 @@ public class TuscanOnlyClassTest { @Test public void test() throws Exception { String[] testArray = { - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", - "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", - "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", - "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", - "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", - "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", + "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", + "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", + "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", + "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", + "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" }; List tests = Arrays.asList(testArray); - // System.out.println(tests); TestShuffler testShuffler = new TestShuffler("", 0, tests, null); int n = TuscanOnlyClassDetector.getClassesSize(tests); int rounds = n; From 702a3fd4f3000e731eb31ba6b98126e06fa0e695 Mon Sep 17 00:00:00 2001 From: mmk Date: Wed, 7 Sep 2022 14:29:21 +0300 Subject: [PATCH 38/40] spacing --- idflakies-core/src/test/java/edu/illinois/TuscanTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java index 0e60af59..a80d0ea4 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -42,7 +42,7 @@ public void test(int n) throws Exception { Assert.assertEquals(finalPairs.size(), visitedPairs.size()); } - private static List> generateAllPairs (int[] row) { + private static List> generateAllPairs(int[] row) { List> allPairs = new ArrayList<>(); for (int i = 0; i < row.length - 1; i++) { for (int j = 0; j < row.length - 1; j++) { From b558112524b71ecc8e7eda9416ce646930d565b7 Mon Sep 17 00:00:00 2001 From: mmk Date: Sun, 11 Sep 2022 12:55:57 +0300 Subject: [PATCH 39/40] refactored tuscan tests --- .../edu/illinois/TuscanIntraClassTest.java | 136 ++++++++++-------- .../edu/illinois/TuscanOnlyClassTest.java | 63 ++++---- 2 files changed, 111 insertions(+), 88 deletions(-) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java index a844a6de..2fb88f43 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java @@ -1,9 +1,5 @@ package edu.illinois; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; import java.util.*; import org.junit.Test; @@ -28,13 +24,14 @@ public void test() throws Exception { }; List tests = Arrays.asList(testArray); TestShuffler testShuffler = new TestShuffler("", 0, tests, null); - HashMap> tempClassToMethods = generateClassToMethods(tests); - int maxMethodSize = TuscanIntraClassDetector.findMaxMethodSize(tempClassToMethods); + HashMap> classToMethods = generateClassToMethods(tests); + + int maxMethodSize = TuscanIntraClassDetector.findMaxMethodSize(classToMethods); if (maxMethodSize == 3 || maxMethodSize == 5) { maxMethodSize++; } int rounds; - int classSize = tempClassToMethods.keySet().size(); + int classSize = classToMethods.keySet().size(); if (classSize == 3 || classSize == 5) { classSize++; } @@ -43,52 +40,17 @@ public void test() throws Exception { } else { rounds = maxMethodSize; } - List classes = new ArrayList(); - LinkedHashMap> classToMethods = new LinkedHashMap>(); - List> visitedMethodPairs = new ArrayList>(); - Set> allMethodPairs = new HashSet>(); - for (int i = 0; i < rounds; i++) { - List currentOrder = testShuffler.tuscanIntraClassOrder(i); - for (String test : currentOrder) { - String className = TestShuffler.className(test); - if (!classes.contains(className)) { - classes.add(className); - } - if (!classToMethods.containsKey(className)) { - classToMethods.put(className, new ArrayList()); - } - classToMethods.get(className).add(test); - } - List> currentClassPairs = generateAllPairs(classes); - for (int j = 0; j < classes.size() - 1; j++) { - // Check if class pairs are covered - List newPair = new ArrayList(); - newPair.add(classes.get(j)); - newPair.add(classes.get(j + 1)); - if (!currentClassPairs.contains(newPair)) { - throw new Exception("Not included Classes"); - } - } - for (String className : classes) { - List currentMethodOrdering = classToMethods.get(className); - List> currentMethodPairs = generateAllPairs(currentMethodOrdering); - allMethodPairs.addAll(currentMethodPairs); - for (int j = 0; j < currentMethodOrdering.size() - 1; j++) { - List newPair = new ArrayList(); - newPair.add(currentMethodOrdering.get(j)); - newPair.add(currentMethodOrdering.get(j + 1)); - if(!currentMethodPairs.contains(newPair)) { - System.out.println(newPair); - throw new Exception("Not included Method Pairs"); - } - if (!visitedMethodPairs.contains(newPair)) { - visitedMethodPairs.add(newPair); - } - } - currentMethodOrdering.clear(); - } - } - Assert.assertEquals(allMethodPairs.size(), visitedMethodPairs.size()); + + // Each List inside a set is basically a pair + Set> allClassPairs = generateAllPairs(tests, false); + Set> tuscanCoveredClassPairs = tuscanClassPairs(rounds, tests, testShuffler); + + Assert.assertEquals(allClassPairs, tuscanCoveredClassPairs); + + Set> allMethodPairs = generateAllPairs(tests, true); + Set> tuscanCoveredMethodPairs = tuscanMethodPairs(rounds, tests, testShuffler); + + Assert.assertEquals(allMethodPairs, tuscanCoveredMethodPairs); } public static HashMap> generateClassToMethods(List tests) { @@ -103,11 +65,11 @@ public static HashMap> generateClassToMethods(List return classToMethods; } - public static List> generateAllPairs(List tests) { - List> allPairs = new ArrayList<>(); + public static Set> generateAllPairs(List tests) { + Set> allPairs = new LinkedHashSet>(); for (int i = 0; i < tests.size(); i++) { for (int j = 0; j < tests.size(); j++) { - if (tests.get(i) != tests.get(j)) { + if (!tests.get(i).equals(tests.get(j))) { List newPair = new ArrayList(); newPair.add(tests.get(i)); newPair.add(tests.get(j)); @@ -117,4 +79,64 @@ public static List> generateAllPairs(List tests) { } return allPairs; } -} + + private static Set> generateAllPairs(List tests, boolean isMethods) { + // Generates all pairs with a naive algorithm for comparison with tuscan-intra-class method + Set> allPairs = new LinkedHashSet>(); + for (int i = 0; i < tests.size(); i++) { + for (int j = 0; j < tests.size(); j++) { + String className1 = TestShuffler.className(tests.get(i)); + String className2 = TestShuffler.className(tests.get(j)); + List newPair = new ArrayList(); + if (!isMethods && !className1.equals(className2)) { + newPair.add(className1); + newPair.add(className2); + allPairs.add(newPair); + } else if (isMethods && className1.equals(className2) && !tests.get(i).equals(tests.get(j))) { + newPair.add(tests.get(i)); + newPair.add(tests.get(j)); + allPairs.add(newPair); + } + } + } + return allPairs; + } + + private static Set> tuscanClassPairs(int rounds, List tests, TestShuffler testShuffler) { + // Generates the class pairs using tuscan-intra-class algorithm + Set> visitedClassPairs = new LinkedHashSet>(); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.tuscanIntraClassOrder(i); + for (int j = 0; j < currentOrder.size() - 1; j++) { + String className1 = TestShuffler.className(currentOrder.get(j)); + String className2 = TestShuffler.className(currentOrder.get(j + 1)); + List newPair = new ArrayList(); + if (!className1.equals(className2)) { + newPair.add(className1); + newPair.add(className2); + visitedClassPairs.add(newPair); + } + } + } + return visitedClassPairs; + } + + private static Set> tuscanMethodPairs(int rounds, List tests, TestShuffler testShuffler) { + // Generates the intra-class method pairs using tuscan-intra-class algorithm + Set> visitedMethodPairs = new LinkedHashSet>(); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.tuscanIntraClassOrder(i); + for (int j = 0; j < currentOrder.size() - 1; j++) { + String class1 = TestShuffler.className(currentOrder.get(j)); + String class2 = TestShuffler.className(currentOrder.get(j + 1)); + if (class1.equals(class2)) { + List newPair = new ArrayList(); + newPair.add(currentOrder.get(j)); + newPair.add(currentOrder.get(j + 1)); + visitedMethodPairs.add(newPair); + } + } + } + return visitedMethodPairs; + } +} \ No newline at end of file diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java index a5e92aef..87ef60fa 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanOnlyClassTest.java @@ -33,47 +33,48 @@ public void test() throws Exception { if (n == 3 || n == 5) { rounds++; } - Set> finalPairs = new LinkedHashSet>(); - Set> visitedPairs = new LinkedHashSet>(); - for (int i = 0; i < rounds; i++) { - List currentRoundPermutation = testShuffler.alphabeticalAndTuscanOrder(i, true); - List permutatedClasses = new ArrayList(); - for (String test : currentRoundPermutation) { - String className = TestShuffler.className(test); - // classes.add(TestShuffler.className(currentOrder.get(j))); - if (!permutatedClasses.contains(className)) { - permutatedClasses.add(className); - } - } - List> allPairs = generateAllPairs(permutatedClasses); - for (int j = 0; j < permutatedClasses.size() - 1; j++) { - List newPair = new ArrayList(); - newPair.add(permutatedClasses.get(j)); - newPair.add(permutatedClasses.get(j + 1)); - if (!allPairs.contains(newPair)) { - throw new Exception("Class pair is not covered"); - } - visitedPairs.add(newPair); - } - finalPairs.addAll(allPairs); - } - int count = finalPairs.size(); - Assert.assertEquals(count, n * (n - 1)); + // Each List inside a set is basically a pair + Set> allClassPairs = generateAllPairs(tests); + Set> tuscanCoveredClassPairs = tuscanOnlyClassPairs(rounds, tests, testShuffler); + + Assert.assertEquals(allClassPairs, tuscanCoveredClassPairs); } - public static List> generateAllPairs(List tests) { - List> allPairs = new ArrayList<>(); + public static Set> generateAllPairs(List tests) { + // Generates all pairs using a naive algorithm for comparison with tuscan-only-class method + Set> allPairs = new LinkedHashSet>(); for (int i = 0; i < tests.size(); i++) { for (int j = 0; j < tests.size(); j++) { - if (tests.get(i) != tests.get(j)) { + String className1 = TestShuffler.className(tests.get(i)); + String className2 = TestShuffler.className(tests.get(j)); + if (!className1.equals(className2)) { List newPair = new ArrayList(); - newPair.add(tests.get(i)); - newPair.add(tests.get(j)); + newPair.add(className1); + newPair.add(className2); allPairs.add(newPair); } } } return allPairs; } + + private static Set> tuscanOnlyClassPairs(int rounds, List tests, TestShuffler testShuffler) { + // Generates all class pairs using tuscan-only-class method + Set> visitedClassPairs = new LinkedHashSet>(); + for (int i = 0; i < rounds; i++) { + List currentOrder = testShuffler.alphabeticalAndTuscanOrder(i, true); + for (int j = 0; j < currentOrder.size() - 1; j++) { + String className1 = TestShuffler.className(currentOrder.get(j)); + String className2 = TestShuffler.className(currentOrder.get(j + 1)); + List newPair = new ArrayList(); + if (!className1.equals(className2)) { + newPair.add(className1); + newPair.add(className2); + visitedClassPairs.add(newPair); + } + } + } + return visitedClassPairs; + } } From add67927e9b0bee919679cd5378f9485cddd3818 Mon Sep 17 00:00:00 2001 From: mmk Date: Sun, 11 Sep 2022 13:13:30 +0300 Subject: [PATCH 40/40] refactored another tuscan test --- .../test/java/edu/illinois/TuscanTest.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java index a80d0ea4..59183799 100644 --- a/idflakies-core/src/test/java/edu/illinois/TuscanTest.java +++ b/idflakies-core/src/test/java/edu/illinois/TuscanTest.java @@ -22,38 +22,44 @@ public static int[] integers() { @Theory public void test(int n) throws Exception { - int[][] matrix = Tuscan.generateTuscanPermutations(n); - Set> finalPairs = new LinkedHashSet>(); - Set> visitedPairs = new LinkedHashSet>(); - for (int i = 0; i < matrix.length; i++) { - List> allPairs = generateAllPairs(matrix[i]); - for (int j = 0; j < matrix[i].length - 2; j++) { - // All rows will have an extra 0 at the end hence we have -2 - List newPair = new ArrayList(); - newPair.add(matrix[i][j]); - newPair.add(matrix[i][j + 1]); - if (!allPairs.contains(newPair)) { - throw new Exception("Does not contain pair"); - } - visitedPairs.add(newPair); - } - finalPairs.addAll(allPairs); - } - Assert.assertEquals(finalPairs.size(), visitedPairs.size()); + Set> allPairs = generateAllPairs(n); + Set> tuscanCoveredPairs = tuscanPairs(n); + + Assert.assertEquals(allPairs, tuscanCoveredPairs); } - private static List> generateAllPairs(int[] row) { - List> allPairs = new ArrayList<>(); - for (int i = 0; i < row.length - 1; i++) { - for (int j = 0; j < row.length - 1; j++) { - if (row[i] != row[j]) { - List newPair = new ArrayList(); - newPair.add(row[i]); - newPair.add(row[j]); + private static Set> generateAllPairs(int n) { + // Generates all pairs with a naive algorithm to compare with Tuscan Squares + Set> allPairs = new LinkedHashSet>(); + int[] numbersArray = IntStream.range(0, n).toArray(); + for (int i = 0; i < numbersArray.length; i++) { + for (int j = 0; j < numbersArray.length; j++) { + if (numbersArray[i] != numbersArray[j]) { + List newPair = new ArrayList<>(); + newPair.add(numbersArray[i]); + newPair.add(numbersArray[j]); allPairs.add(newPair); } } } return allPairs; } + + private static Set> tuscanPairs(int n) { + // Finding all number pairs generated by Tuscan Squares + Set> visitedPairs = new LinkedHashSet>(); + int[][] matrix = Tuscan.generateTuscanPermutations(n); + int rows = matrix.length; + for (int i = 0; i < rows; i++) { + int[] currentRow = matrix[i]; + for (int j = 0; j < currentRow.length - 2; j++) { + // All rows will have an extra 0 at the end hence we have -2 + List newPair = new ArrayList(); + newPair.add(currentRow[j]); + newPair.add(currentRow[j + 1]); + visitedPairs.add(newPair); + } + } + return visitedPairs; + } }