diff --git a/jgalgo-bench/src/main/java/com/jgalgo/bench/util/TestUtils.java b/jgalgo-bench/src/main/java/com/jgalgo/bench/util/TestUtils.java index 8ccb596c73..c8339a9d37 100644 --- a/jgalgo-bench/src/main/java/com/jgalgo/bench/util/TestUtils.java +++ b/jgalgo-bench/src/main/java/com/jgalgo/bench/util/TestUtils.java @@ -16,92 +16,12 @@ package com.jgalgo.bench.util; -import java.util.Collection; import java.util.Iterator; import java.util.Random; - import it.unimi.dsi.fastutil.ints.IntArrays; -@SuppressWarnings("boxing") public class TestUtils { - public static class Phase { - private final int repeat; - private final int[] args; - - private Phase(int repeat, int[] args) { - if (repeat < 0) - throw new IllegalArgumentException(); - this.repeat = repeat; - this.args = args; - } - - static Phase of(int repeat, int... args) { - return new Phase(repeat, args); - } - } - - public static Phase phase(int repeat, int... args) { - return Phase.of(repeat, args); - } - - @FunctionalInterface - public static interface TestRunnable { - public void run(TestIterIdx testIter, int[] args); - } - - public static void runTestMultiple(Collection phases, TestRunnable test) { - int phaseIdx = 0; - for (Phase phase : phases) { - for (int iter = 0; iter < phase.repeat; iter++) { - try { - test.run(new TestIterIdx(phaseIdx, iter), phase.args); - } catch (Throwable e) { - System.err.println("Failed at phase " + phaseIdx + " iter " + iter); - throw e; - } - } - phaseIdx++; - } - } - - public static class TestIterIdx { - public final int phase, iter; - - private TestIterIdx(int phase, int iter) { - this.phase = phase; - this.iter = iter; - } - - @Override - public String toString() { - return "P" + phase + " I" + iter; - } - } - - static boolean doubleEql(double a, double b, double precise) { - if (a < b) - return b - a < precise; - if (a > b) - return a - b < precise; - return true; - } - - static void printArr(int a[]) { - printArr(a, true); - } - - static void printArr(int a[], boolean printIndicies) { - for (int i = 0; i < a.length; i++) - System.out.print("" + String.format("%03d", a[i]) + ", "); - System.out.println(); - if (printIndicies) { - for (int i = 0; i < a.length; i++) - System.out.print("" + String.format("%03d", i) + ", "); - System.out.println(); - } - } - public static int[] randArray(int n, long seed) { return randArray(n, 0, Integer.MAX_VALUE, seed); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/AStarTest.java b/jgalgo-core/src/test/java/com/jgalgo/AStarTest.java index 80b69c962e..f72daa0cb3 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/AStarTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/AStarTest.java @@ -16,7 +16,6 @@ package com.jgalgo; -import java.util.List; import java.util.Random; import java.util.function.Function; import java.util.function.IntToDoubleFunction; @@ -31,7 +30,13 @@ public class AStarTest extends TestBase { - private static List SsspPhases = List.of(phase(64, 16, 32), phase(32, 64, 256), phase(4, 300, 900)); + private static PhasedTester SsspPhases; + static { + SsspPhases = new PhasedTester(); + SsspPhases.addPhase().withArgs(16, 32).repeat(64); + SsspPhases.addPhase().withArgs(64, 256).repeat(32); + SsspPhases.addPhase().withArgs(300, 900).repeat(4); + } @Test public void testRandGraphDirectedNoHeuristic() { diff --git a/jgalgo-core/src/test/java/com/jgalgo/ArraysUtilsTest.java b/jgalgo-core/src/test/java/com/jgalgo/ArraysUtilsTest.java index de4cdb1f96..3a3d5b1363 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ArraysUtilsTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ArraysUtilsTest.java @@ -18,11 +18,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.Arrays; -import java.util.List; import java.util.Random; - import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; @@ -33,10 +30,14 @@ public class ArraysUtilsTest extends TestBase { public void testIntGetKthElementRandArrayUnique() { final long seed = 0xedf92ed1b59ae1e1L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { int[] a = randPermutation(n, seedGen.nextSeed()); testGetKthElement(a, seedGen.nextSeed()); }); @@ -46,10 +47,14 @@ public void testIntGetKthElementRandArrayUnique() { public void testObjGetKthElementRandArrayUnique() { final long seed = 0x7f7871365f84b52eL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { Integer[] a = toIntegerArr(randPermutation(n, seedGen.nextSeed())); testGetKthElement(a, seedGen.nextSeed()); }); @@ -59,10 +64,14 @@ public void testObjGetKthElementRandArrayUnique() { public void testIntGetKthElementRandArrayNonUnique() { final long seed = 0x97e45458f8daefd2L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { int[] a = randArray(n, 0, n / 4, seedGen.nextSeed()); testGetKthElement(a, seedGen.nextSeed()); }); @@ -72,10 +81,14 @@ public void testIntGetKthElementRandArrayNonUnique() { public void testObjGetKthElementRandArrayNonUnique() { final long seed = 0x6ee2228e9064ab3eL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { Integer[] a = toIntegerArr(randArray(n, 0, n / 4, seedGen.nextSeed())); testGetKthElement(a, seedGen.nextSeed()); }); @@ -85,10 +98,14 @@ public void testObjGetKthElementRandArrayNonUnique() { public void testIntGetKthElementRandArraySameElm() { final long seed = 0x77b8bdd802380333L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(1, 8), phase(1, 32), phase(1, 128), phase(1, 256), phase(1, 1024), phase(1, 3849)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(1); + tester.addPhase().withArgs(32).repeat(1); + tester.addPhase().withArgs(128).repeat(1); + tester.addPhase().withArgs(256).repeat(1); + tester.addPhase().withArgs(1024).repeat(1); + tester.addPhase().withArgs(3849).repeat(1); + tester.run(n -> { int[] a = new int[n]; Arrays.fill(a, 6); testGetKthElement(a, seedGen.nextSeed()); @@ -99,10 +116,14 @@ public void testIntGetKthElementRandArraySameElm() { public void testObjGetKthElementRandArraySameElm() { final long seed = 0x656f2a7fcad2e9e8L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(1, 8), phase(1, 32), phase(1, 128), phase(1, 256), phase(1, 1024), phase(1, 3849)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(1); + tester.addPhase().withArgs(32).repeat(1); + tester.addPhase().withArgs(128).repeat(1); + tester.addPhase().withArgs(256).repeat(1); + tester.addPhase().withArgs(1024).repeat(1); + tester.addPhase().withArgs(3849).repeat(1); + tester.run(n -> { int[] a = new int[n]; Arrays.fill(a, 6); testGetKthElement(toIntegerArr(a), seedGen.nextSeed()); @@ -129,10 +150,14 @@ private static void testGetKthElement(Integer[] a, long seed) { public void testIntBucketPartition() { final SeedGenerator seedGen = new SeedGenerator(0x90fc97e52265ff44L); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { int[] a = randArray(n, 0, n / 4, seedGen.nextSeed()); int bucketSize = rand.nextInt(n / 2) + 1; ArraysUtils.bucketPartition(a, 0, n, null, bucketSize); @@ -154,10 +179,14 @@ public void testIntBucketPartition() { public void testObjBucketPartition() { final SeedGenerator seedGen = new SeedGenerator(0x275079aa6f2fc7d7L); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { Integer[] a = toIntegerArr(randArray(n, 0, n / 4, seedGen.nextSeed())); int bucketSize = rand.nextInt(n / 2) + 1; ArraysUtils.bucketPartition(a, 0, n, null, bucketSize); @@ -179,10 +208,14 @@ public void testObjBucketPartition() { public void testIntPivotPartition() { final SeedGenerator seedGen = new SeedGenerator(0x92f173634ff49309L); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { int[] a = randArray(n, 0, n / 4, seedGen.nextSeed()); int pivot = a[rand.nextInt(a.length)]; ArraysUtils.pivotPartition(a, 0, a.length, pivot, null); @@ -205,10 +238,14 @@ public void testIntPivotPartition() { public void testObjPivotPartition() { final SeedGenerator seedGen = new SeedGenerator(0xd693bcfe6327104L); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 1024), phase(2, 4567)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(1024).repeat(8); + tester.addPhase().withArgs(4567).repeat(2); + tester.run(n -> { Integer[] a = toIntegerArr(randArray(n, 0, n / 4, seedGen.nextSeed())); int pivot = a[rand.nextInt(a.length)]; ArraysUtils.pivotPartition(a, 0, a.length, pivot, null); diff --git a/jgalgo-core/src/test/java/com/jgalgo/BFSIterTest.java b/jgalgo-core/src/test/java/com/jgalgo/BFSIterTest.java index 4cf466dd0b..cc4eeda677 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/BFSIterTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/BFSIterTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; @@ -35,9 +34,11 @@ public void testBfsConnected() { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16, 8), phase(128, 32, 64), phase(4, 2048, 8192)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(2048, 8192).repeat(4); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/BiConnectedComponentsAlgoHopcroftTarjanTest.java b/jgalgo-core/src/test/java/com/jgalgo/BiConnectedComponentsAlgoHopcroftTarjanTest.java index 95382de8b3..24d80a8a4c 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/BiConnectedComponentsAlgoHopcroftTarjanTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/BiConnectedComponentsAlgoHopcroftTarjanTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; import com.jgalgo.graph.Weights; @@ -37,9 +36,12 @@ public class BiConnectedComponentsAlgoHopcroftTarjanTest extends TestBase { public void randGraphUndirected() { final long seed = 0xda9272921794ecfaL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 5, 6), phase(64, 16, 32), phase(32, 64, 256), phase(1, 165, 666)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(5, 6).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 256).repeat(32); + tester.addPhase().withArgs(165, 666).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); testUGraph(BiConnectedComponentsAlgo.newBuilder().build(), g); diff --git a/jgalgo-core/src/test/java/com/jgalgo/ColoringTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/ColoringTestUtils.java index 26f97e297c..31dabf4c0e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ColoringTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ColoringTestUtils.java @@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.List; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphFactory; import com.jgalgo.internal.util.RandomGraphBuilder; @@ -33,9 +32,12 @@ class ColoringTestUtils extends TestUtils { static void testRandGraphs(Coloring algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16, 8), phase(128, 32, 64), phase(32, 200, 1000), phase(4, 2048, 8192)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(200, 1000).repeat(32); + tester.addPhase().withArgs(2048, 8192).repeat(4); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(false).cycles(true).connected(false).build(); Coloring.Result coloring = algo.computeColoring(g); diff --git a/jgalgo-core/src/test/java/com/jgalgo/ConnectedComponentsAlgoTest.java b/jgalgo-core/src/test/java/com/jgalgo/ConnectedComponentsAlgoTest.java index d38f1ce807..410ca8b535 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ConnectedComponentsAlgoTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ConnectedComponentsAlgoTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.BitSet; -import java.util.List; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphBuilder; @@ -40,9 +39,11 @@ public class ConnectedComponentsAlgoTest extends TestBase { public void strongCCUGraph() { final long seed = 0xb3f19acd0e1041deL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); ConnectedComponentsAlgo.Result actual = @@ -74,9 +75,11 @@ public void strongCCsDiGraph() { final long seed = 0xd21f8ca761bc1aaeL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); @@ -119,9 +122,11 @@ public void weakCCsDiGraph() { final long seed = 0x715a81d58dcf65deL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/CoreAlgoTest.java b/jgalgo-core/src/test/java/com/jgalgo/CoreAlgoTest.java index 76bc81c294..fe29f3df87 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/CoreAlgoTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/CoreAlgoTest.java @@ -16,7 +16,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -66,9 +65,12 @@ public void testRandUGraphOutAndInDegree() { private static void testCoreAlgo(CoreAlgo.DegreeType degreeType, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), phase(8, 1024, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(1024, 4096).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/CyclesFinderTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/CyclesFinderTestUtils.java index 793dd5ce16..8580d70a20 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/CyclesFinderTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/CyclesFinderTestUtils.java @@ -25,9 +25,9 @@ import com.jgalgo.graph.Graph; import com.jgalgo.graph.IndexGraph; import com.jgalgo.graph.IndexGraphFactory; +import com.jgalgo.internal.util.JGAlgoUtils; import com.jgalgo.internal.util.RandomGraphBuilder; import com.jgalgo.internal.util.TestUtils; -import com.jgalgo.internal.util.JGAlgoUtils; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrays; import it.unimi.dsi.fastutil.ints.IntList; @@ -56,10 +56,13 @@ static void testSimpleGraph(CyclesFinder cyclesFinder) { static void testRandGraphs(CyclesFinder cyclesFinder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16, 8), phase(256, 16, 16), phase(128, 32, 32), phase(128, 32, 64), - phase(64, 64, 64)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(32, 32).repeat(128); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(64, 64).repeat(64); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); testGraph(g, cyclesFinder); diff --git a/jgalgo-core/src/test/java/com/jgalgo/DFSIterTest.java b/jgalgo-core/src/test/java/com/jgalgo/DFSIterTest.java index 6d7b351187..526cea061c 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/DFSIterTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/DFSIterTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; @@ -35,9 +34,11 @@ public void testDfsConnected() { final long seed = 0x77678e2ce068199cL; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16, 8), phase(128, 32, 64), phase(4, 2048, 8192)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(2048, 8192).repeat(4); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); int[] vs = g.vertices().toIntArray(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/EulerianTourTest.java b/jgalgo-core/src/test/java/com/jgalgo/EulerianTourTest.java index f8d00409cb..9b46d7060e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/EulerianTourTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/EulerianTourTest.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; @@ -59,9 +58,11 @@ public void testRandGraphDirectedOneExtraInDegreeOneExtraOutDegree() { private static void testRandGraphUndirected(boolean allEvenVertices, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(8); + tester.run((n, m) -> { Graph g = randUGraph(n, m, allEvenVertices, seedGen.nextSeed()); Path tour = EulerianTourAlgo.newBuilder().build().computeEulerianTour(g); validateEulerianTour(g, tour); @@ -70,9 +71,11 @@ private static void testRandGraphUndirected(boolean allEvenVertices, long seed) private static void testRandGraphDirected(boolean allEqualInOutDegree, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(8); + tester.run((n, m) -> { Graph g = randDiGraph(n, m, allEqualInOutDegree, seedGen.nextSeed()); Path tour = EulerianTourAlgo.newBuilder().build().computeEulerianTour(g); validateEulerianTour(g, tour); diff --git a/jgalgo-core/src/test/java/com/jgalgo/FlowCirculationTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/FlowCirculationTestUtils.java index 816b66f313..511848775b 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/FlowCirculationTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/FlowCirculationTestUtils.java @@ -16,7 +16,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Random; import com.jgalgo.graph.Graph; import com.jgalgo.graph.WeightFunction; @@ -41,9 +40,12 @@ static void testRandCirculationInt(FlowCirculation algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -69,9 +71,12 @@ static void testRandCirculation(FlowCirculation algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorDynamicTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorDynamicTestUtils.java index 119b3b8b85..1a4ea647ee 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorDynamicTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorDynamicTestUtils.java @@ -31,10 +31,15 @@ private LowestCommonAncestorDynamicTestUtils() {} static void fullBinaryTreesRandOps(LowestCommonAncestorDynamic.Builder builder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 16, 16), phase(64, 16, 32), phase(32, 64, 64), phase(32, 64, 128), - phase(4, 512, 512), phase(4, 512, 2048), phase(1, 1000, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(32); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 2048).repeat(4); + tester.addPhase().withArgs(1000, 4096).repeat(1); + tester.run((n, m) -> { Collection ops = generateRandOpsOnFullBinaryTree(n, m, seedGen.nextSeed()); testLCA(builder, n, ops); }); @@ -42,10 +47,16 @@ static void fullBinaryTreesRandOps(LowestCommonAncestorDynamic.Builder builder, static void randTrees(LowestCommonAncestorDynamic.Builder builder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 16), phase(128, 16, 32), phase(64, 64, 64), phase(64, 64, 128), - phase(4, 512, 512), phase(4, 512, 2048), phase(1, 1000, 4096), phase(1, 4100, 8000)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 64).repeat(64); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 2048).repeat(4); + tester.addPhase().withArgs(1000, 4096).repeat(1); + tester.addPhase().withArgs(4100, 8000).repeat(1); + tester.run((n, m) -> { Collection ops = generateRandOps(n, m, seedGen.nextSeed()); testLCA(builder, n, ops); }); diff --git a/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorStaticRMQTest.java b/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorStaticRMQTest.java index a98c211926..b8a2505228 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorStaticRMQTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/LowestCommonAncestorStaticRMQTest.java @@ -17,7 +17,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Random; import java.util.function.Supplier; import org.junit.jupiter.api.Test; @@ -98,10 +97,13 @@ private static void testLCA(Graph g, Supplier phases = List.of(phase(128, 16, 16), phase(64, 64, 64), phase(16, 512, 512), phase(4, 4096, 4096), - phase(1, 16384, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(64, 64).repeat(64); + tester.addPhase().withArgs(512, 512).repeat(16); + tester.addPhase().withArgs(4096, 4096).repeat(4); + tester.addPhase().withArgs(16384, 16384).repeat(1); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randTree(n, seedGen.nextSeed()); int root = g.vertices().iterator().nextInt(); int[][] queries = randLCAQueries(g, root, m, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MatchingBipartiteTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MatchingBipartiteTestUtils.java index 2296f4a963..ce5b70f514 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MatchingBipartiteTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MatchingBipartiteTestUtils.java @@ -17,7 +17,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Objects; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -44,12 +43,13 @@ static void randBipartiteGraphs(MatchingAlgorithm algo, long seed) { public static void randBipartiteGraphs(MatchingAlgorithm algo, Boolean2ObjectFunction graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 4, 4, 4), phase(64, 16, 16, 64), phase(8, 128, 128, 128), - phase(8, 128, 128, 512), phase(1, 300, 300, 1100)); - runTestMultiple(phases, (testIter, args) -> { - int sn = args[0]; - int tn = args[1]; - int m = args[2]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(4, 4, 4).repeat(128); + tester.addPhase().withArgs(16, 16, 64).repeat(64); + tester.addPhase().withArgs(128, 128, 128).repeat(8); + tester.addPhase().withArgs(128, 128, 512).repeat(8); + tester.addPhase().withArgs(300, 300, 1100).repeat(1); + tester.run((sn, tn, m) -> { Graph g = randGraphBipartite(sn, tn, m, graphImpl, seedGen.nextSeed()); int expected = calcExpectedMaxMatching(g); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MatchingUnweightedTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MatchingUnweightedTestUtils.java index 6a221e6992..4b9b7895c7 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MatchingUnweightedTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MatchingUnweightedTestUtils.java @@ -35,10 +35,17 @@ private MatchingUnweightedTestUtils() {} static void randGraphs(MatchingAlgorithm algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 8), phase(128, 16, 16), phase(64, 32, 32), phase(32, 32, 64), - phase(16, 64, 64), phase(12, 64, 128), phase(4, 256, 256), phase(4, 256, 512), phase(1, 1000, 2500)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(128); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(32, 32).repeat(64); + tester.addPhase().withArgs(32, 64).repeat(32); + tester.addPhase().withArgs(64, 64).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(12); + tester.addPhase().withArgs(256, 256).repeat(4); + tester.addPhase().withArgs(256, 512).repeat(4); + tester.addPhase().withArgs(1000, 2500).repeat(1); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, seedGen.nextSeed()); int expeced = calcExpectedMaxMatching(g); testAlgo(algo, g, expeced); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MatchingWeightedTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MatchingWeightedTestUtils.java index 7c21d93d2b..f77f2564fc 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MatchingWeightedTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MatchingWeightedTestUtils.java @@ -17,7 +17,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Random; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; @@ -40,13 +39,12 @@ static void randGraphsBipartiteWeighted(MatchingAlgorithm algo, long seed) { public static void randGraphsBipartiteWeighted(MatchingAlgorithm algo, Boolean2ObjectFunction graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8, 8, 8), phase(128, 16, 16, 64), phase(12, 128, 128, 128), - phase(2, 256, 256, 1200)); - runTestMultiple(phases, (testIter, args) -> { - int sn = args[0]; - int tn = args[1]; - int m = args[2]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 8, 8).repeat(256); + tester.addPhase().withArgs(16, 16, 64).repeat(128); + tester.addPhase().withArgs(128, 128, 128).repeat(12); + tester.addPhase().withArgs(256, 256, 1200).repeat(2); + tester.run((sn, tn, m) -> { Graph g = MatchingBipartiteTestUtils.randGraphBipartite(sn, tn, m, graphImpl, seedGen.nextSeed()); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntNeg(g, seedGen.nextSeed()); @@ -59,13 +57,13 @@ public static void randGraphsBipartiteWeighted(MatchingAlgorithm algo, Boolean2O static void randBipartiteGraphsWeightedPerfect(MatchingAlgorithm algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 8, 8, 8), phase(32, 16, 16, 64), phase(8, 128, 128, 128), - phase(4, 128, 128, 512), phase(1, 1024, 1024, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int sn = args[0]; - int tn = args[1]; - int m = args[2]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 8, 8).repeat(64); + tester.addPhase().withArgs(16, 16, 64).repeat(32); + tester.addPhase().withArgs(128, 128, 128).repeat(8); + tester.addPhase().withArgs(128, 128, 512).repeat(4); + tester.addPhase().withArgs(1024, 1024, 1024).repeat(1); + tester.run((sn, tn, m) -> { Graph g = MatchingBipartiteTestUtils.randGraphBipartite(sn, tn, m, GraphsTestUtils.defaultGraphImpl(), seedGen.nextSeed()); Weights.Bool partition = g.getVerticesWeights(Weights.DefaultBipartiteWeightKey); @@ -99,11 +97,13 @@ static void randBipartiteGraphsWeightedPerfect(MatchingAlgorithm algo, long seed static void randGraphsWeighted(MatchingAlgorithm algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8, 8, 8), phase(128, 16, 16, 64), phase(12, 128, 128, 128), - phase(6, 128, 128, 512), phase(1, 1024, 1024, 2300)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 8).repeat(256); + tester.addPhase().withArgs(16, 64).repeat(128); + tester.addPhase().withArgs(128, 128).repeat(12); + tester.addPhase().withArgs(128, 512).repeat(6); + tester.addPhase().withArgs(1024, 2300).repeat(1); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, seedGen.nextSeed()); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntNeg(g, seedGen.nextSeed()); @@ -134,11 +134,13 @@ private static void testGraphWeighted(MatchingAlgorithm algo, Graph g, WeightFun static void randGraphsWeightedPerfect(MatchingAlgorithm algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8, 8, 8), phase(128, 16, 16, 64), phase(12, 128, 128, 128), - phase(8, 128, 128, 512), phase(2, 1024, 1024, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 8).repeat(256); + tester.addPhase().withArgs(16, 64).repeat(128); + tester.addPhase().withArgs(128, 128).repeat(12); + tester.addPhase().withArgs(128, 512).repeat(8); + tester.addPhase().withArgs(1024, 1024).repeat(2); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, seedGen.nextSeed()); if (g.vertices().size() % 2 != 0) throw new IllegalArgumentException("there is no perfect matching"); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MaximumFlowTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MaximumFlowTestUtils.java index fab6023718..0c9bf9b46d 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MaximumFlowTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MaximumFlowTestUtils.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedList; -import java.util.List; import java.util.NavigableSet; import java.util.Random; import java.util.TreeSet; @@ -102,10 +101,16 @@ public static void testRandGraphs(MaximumFlow algo, Boolean2ObjectFunction phases = List.of(phase(256, 6, 6), phase(64, 16, 16), phase(64, 16, 32), phase(32, 64, 64), - phase(32, 64, 128), phase(4, 512, 512), phase(2, 512, 1324), phase(1, 1025, 2016)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(32); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 1324).repeat(2); + tester.addPhase().withArgs(1025, 2016).repeat(1); + tester.run((n, m) -> { Graph g = randGraph(n, m, graphImpl, seedGen.nextSeed(), directed); FlowNetwork net = randNetwork(g, seedGen.nextSeed()); @@ -117,10 +122,16 @@ public static void testRandGraphs(MaximumFlow algo, Boolean2ObjectFunction phases = List.of(phase(256, 6, 6), phase(64, 16, 16), phase(64, 16, 32), phase(32, 64, 64), - phase(32, 64, 128), phase(4, 512, 512), phase(2, 512, 1324), phase(1, 1025, 2016)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(32); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 1324).repeat(2); + tester.addPhase().withArgs(1025, 2016).repeat(1); + tester.run((n, m) -> { Graph g = randGraph(n, m, GraphsTestUtils.defaultGraphImpl(), seedGen.nextSeed(), directed); FlowNetwork net = randNetwork(g, seedGen.nextSeed()); @@ -152,10 +163,16 @@ static void testRandGraphsInt(MaximumFlow algo, Boolean2ObjectFunction gr boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 3, 3), phase(256, 6, 6), phase(64, 16, 16), phase(64, 16, 32), - phase(32, 64, 64), phase(16, 64, 128), phase(2, 512, 512), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(3, 3).repeat(256); + tester.addPhase().withArgs(6, 6).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 512).repeat(2); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = randGraph(n, m, graphImpl, seedGen.nextSeed(), directed); FlowNetwork.Int net = randNetworkInt(g, seedGen.nextSeed()); @@ -167,10 +184,16 @@ static void testRandGraphsInt(MaximumFlow algo, Boolean2ObjectFunction gr public static void testRandGraphsMultiSourceMultiSinkInt(MaximumFlow algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 6, 6), phase(64, 16, 16), phase(64, 16, 32), phase(32, 64, 64), - phase(32, 64, 128), phase(4, 512, 512), phase(2, 512, 1324), phase(1, 1025, 2016)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(32); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 1324).repeat(2); + tester.addPhase().withArgs(1025, 2016).repeat(1); + tester.run((n, m) -> { Graph g = randGraph(n, m, GraphsTestUtils.defaultGraphImpl(), seedGen.nextSeed(), directed); FlowNetwork.Int net = randNetworkInt(g, seedGen.nextSeed()); @@ -201,9 +224,12 @@ public static void testRandGraphsMultiSourceMultiSinkInt(MaximumFlow algo, long static void testRandGraphsWithALotOfParallelEdges(MaximumFlow algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 3, 30), phase(256, 6, 150), phase(64, 10, 450), phase(64, 18, 1530)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(3, 30).repeat(256); + tester.addPhase().withArgs(6, 150).repeat(256); + tester.addPhase().withArgs(10, 450).repeat(64); + tester.addPhase().withArgs(18, 1530).repeat(64); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seed).n(n).m(m).directed(directed).parallelEdges(true).selfEdges(true) .cycles(true).connected(false).build(); FlowNetwork.Int net = randNetworkInt(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsDouble.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsDouble.java index 8f17d8de27..5f3169d901 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsDouble.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsDouble.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -49,9 +48,12 @@ static void testMinCostMaxFlowWithSourceSink(MinimumCostFlow algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -67,9 +69,12 @@ static void testMinCostMaxFlowWithSourceSinkLowerBound(MinimumCostFlow algo, lon final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -88,9 +93,12 @@ static void testMinCostMaxFlowWithSourcesSinks(MinimumCostFlow algo, long seed) final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -106,9 +114,12 @@ static void testMinCostMaxFlowWithSourcesSinksLowerBound(MinimumCostFlow algo, l final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -127,9 +138,12 @@ static void testMinCostFlowWithSupply(MinimumCostFlow algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -145,9 +159,12 @@ static void testMinCostFlowWithSupplyLowerBound(MinimumCostFlow algo, long seed) final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsInt.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsInt.java index cae07ad763..9f74927afc 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsInt.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumCostFlowTestUtilsInt.java @@ -17,7 +17,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -48,9 +47,12 @@ static void testMinCostMaxFlowWithSourceSink(MinimumCostFlow algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -66,9 +68,12 @@ static void testMinCostMaxFlowWithSourceSinkLowerBound(MinimumCostFlow algo, lon final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -87,9 +92,12 @@ static void testMinCostMaxFlowWithSourcesSinks(MinimumCostFlow algo, long seed) final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -105,9 +113,12 @@ static void testMinCostMaxFlowWithSourcesSinksLowerBound(MinimumCostFlow algo, l final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -126,9 +137,12 @@ static void testMinCostFlowWithSupply(MinimumCostFlow algo, long seed) { final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -144,9 +158,12 @@ static void testMinCostFlowWithSupplyLowerBound(MinimumCostFlow algo, long seed) final boolean directed = true; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumCutGlobalStoerWagnerTest.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumCutGlobalStoerWagnerTest.java index 93a20c07b8..8343cafee2 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumCutGlobalStoerWagnerTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumCutGlobalStoerWagnerTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; @@ -43,10 +42,14 @@ public void testMinimumCutRandUGraphs() { static void testRandGraphs(MinimumCutGlobal algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 6, 6), phase(16, 16, 16), phase(16, 16, 32), phase(16, 64, 64), - phase(16, 64, 128), phase(2, 200, 800)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(256); + tester.addPhase().withArgs(16, 16).repeat(16); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 64).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(200, 800).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumCutSTTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumCutSTTestUtils.java index 0270dcff9d..4a77167cc8 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumCutSTTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumCutSTTestUtils.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -39,9 +38,12 @@ class MinimumCutSTTestUtils extends TestUtils { static void testRandGraphs(MinimumCutST algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -57,9 +59,12 @@ static void testRandGraphs(MinimumCutST algo, long seed, boolean directed) { static void testRandGraphsInt(MinimumCutST algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -85,9 +90,12 @@ static IntIntPair chooseSourceSink(Graph g, Random rand) { static void testRandGraphsMultiSourceMultiSink(MinimumCutST algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); @@ -103,9 +111,12 @@ static void testRandGraphsMultiSourceMultiSink(MinimumCutST algo, long seed, boo static void testRandGraphsMultiSourceMultiSinkInt(MinimumCutST algo, long seed, boolean directed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(32, 6, 6), phase(16, 16, 32), phase(16, 64, 128), phase(1, 512, 1324)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 1324).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumDirectedSpanningTreeTarjanTest.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumDirectedSpanningTreeTarjanTest.java index cec1786033..d327e3043e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumDirectedSpanningTreeTarjanTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumDirectedSpanningTreeTarjanTest.java @@ -16,7 +16,6 @@ package com.jgalgo; -import java.util.List; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; @@ -91,11 +90,14 @@ public void testRandGraphDirected() { public static void testRandGraph(MinimumDirectedSpanningTree algo, Boolean2ObjectFunction graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 6, 5), phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), - phase(8, 1024, 4096), phase(2, 4096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 5).repeat(256); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(1024, 4096).repeat(8); + tester.addPhase().withArgs(4096, 16384).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).graphImpl(graphImpl).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumMeanCycleTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumMeanCycleTestUtils.java index 3057c8b986..4e64ea958c 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumMeanCycleTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumMeanCycleTestUtils.java @@ -20,30 +20,28 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; - import java.util.Iterator; -import java.util.List; import java.util.Random; - import com.jgalgo.graph.EdgeIter; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.graph.WeightFunction; import com.jgalgo.graph.Weights; +import com.jgalgo.internal.util.JGAlgoUtils; import com.jgalgo.internal.util.RandomGraphBuilder; import com.jgalgo.internal.util.TestBase; - import it.unimi.dsi.fastutil.ints.IntArrayList; -import com.jgalgo.internal.util.JGAlgoUtils; - public class MinimumMeanCycleTestUtils extends TestBase { static void testRandGraphs(MinimumMeanCycle algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 3, 2), phase(128, 16, 32), phase(64, 64, 128), phase(8, 500, 2010)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(3, 2).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(500, 2010).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); @@ -54,9 +52,12 @@ static void testRandGraphs(MinimumMeanCycle algo, long seed) { static void testRandGraphsSimilarWeights(MinimumMeanCycle algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 3, 2), phase(128, 16, 32), phase(64, 64, 128), phase(8, 500, 2010)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(3, 2).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(500, 2010).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction w = GraphsTestUtils.assignRandWeights(g, -10, 10, seedGen.nextSeed()); @@ -68,9 +69,12 @@ static void testRandGraphsSimilarWeights(MinimumMeanCycle algo, long seed) { static void testRandGraphsEqualWeightCycles(MinimumMeanCycle algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(128, 3, 2), phase(128, 16, 32), phase(64, 64, 128), phase(8, 500, 2010)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(3, 2).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(500, 2010).repeat(8); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(false) .selfEdges(true).cycles(true).connected(false).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/MinimumSpanningTreeTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/MinimumSpanningTreeTestUtils.java index a94e2906a1..c274f7d0d1 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/MinimumSpanningTreeTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/MinimumSpanningTreeTestUtils.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.graph.WeightFunction; @@ -38,11 +37,13 @@ static void testRandGraph(MinimumSpanningTree algo, long seed) { public static void testRandGraph(MinimumSpanningTree algo, Boolean2ObjectFunction graphImpl, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), phase(8, 1024, 4096), - phase(2, 4096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(1024, 4096).repeat(8); + tester.addPhase().withArgs(4096, 16384).repeat(2); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, graphImpl, seedGen.nextSeed()); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/PageRankTest.java b/jgalgo-core/src/test/java/com/jgalgo/PageRankTest.java index dd158d8f28..abc615729b 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/PageRankTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/PageRankTest.java @@ -16,7 +16,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; @@ -29,11 +28,13 @@ class PageRankTest extends TestBase { public void testRandGraph() { final long seed = 0xe573594a68dac687L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), phase(8, 1024, 4096), - phase(2, 4096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(1024, 4096).repeat(8); + tester.addPhase().withArgs(4096, 16384).repeat(2); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, seedGen.nextSeed()); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); testPageRank(g, w); diff --git a/jgalgo-core/src/test/java/com/jgalgo/PathTest.java b/jgalgo-core/src/test/java/com/jgalgo/PathTest.java index 26816fb6bd..230055b474 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/PathTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/PathTest.java @@ -19,10 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; - -import java.util.List; import java.util.Random; - import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; import com.jgalgo.internal.util.RandomGraphBuilder; @@ -36,9 +33,11 @@ public void testFindPath() { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); ShortestPathSingleSource validationAlgo = new ShortestPathSingleSourceDijkstra(); - List phases = List.of(phase(256, 16, 8), phase(128, 32, 64), phase(4, 2048, 8192)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 8).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(2048, 8192).repeat(4); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); int[] vs = g.vertices().toIntArray(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathAllPairsTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathAllPairsTestUtils.java index c10ba648a8..41e4bb098e 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathAllPairsTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathAllPairsTestUtils.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; import com.jgalgo.graph.WeightFunction; @@ -40,9 +39,11 @@ static void testAPSPUndirectedPositiveInt(ShortestPathAllPairs algo, long seed) private static void testAPSPPositiveInt(ShortestPathAllPairs algo, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 6, 20), phase(128, 16, 32), phase(64, 64, 256)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 20).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); @@ -52,9 +53,11 @@ private static void testAPSPPositiveInt(ShortestPathAllPairs algo, boolean direc static void testAPSPCardinality(ShortestPathAllPairs algo, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 6, 20), phase(128, 16, 32), phase(64, 64, 256)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 20).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); testAPSP(g, null, algo, new ShortestPathSingleSourceDijkstra()); @@ -63,9 +66,11 @@ static void testAPSPCardinality(ShortestPathAllPairs algo, boolean directed, lon static void testAPSPDirectedNegativeInt(ShortestPathAllPairs algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 6, 20), phase(64, 16, 32), phase(10, 64, 256)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 20).repeat(128); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 256).repeat(10); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntNeg(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceDagTest.java b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceDagTest.java index f22bf45635..1583089d60 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceDagTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceDagTest.java @@ -16,8 +16,6 @@ package com.jgalgo; -import java.util.List; - import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; @@ -42,9 +40,11 @@ public void testDistancesDAGConnected() { private static void distancesDAG(boolean connected, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); ShortestPathSingleSource ssspAlgo = new ShortestPathSingleSourceDag(); - List phases = List.of(phase(256, 16, 16), phase(128, 32, 64), phase(16, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(512, 1024).repeat(16); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(false).cycles(false).connected(connected).build(); WeightFunction w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); @@ -69,9 +69,11 @@ public void testDistancesDAGConnectedCardinality() { private static void distancesDAGCardinality(boolean connected, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); ShortestPathSingleSource ssspAlgo = new ShortestPathSingleSourceDag(); - List phases = List.of(phase(256, 16, 16), phase(128, 32, 64), phase(16, 512, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(512, 1024).repeat(16); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(false).cycles(false).connected(connected).build(); int source = g.vertices().iterator().nextInt(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceTestUtils.java index 597b026f08..87b400a891 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/ShortestPathSingleSourceTestUtils.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphsTestUtils; @@ -40,17 +39,19 @@ public static void testSSSPUndirectedPositiveInt(ShortestPathSingleSource algo, } private static void testSSSPPositiveInt(ShortestPathSingleSource algo, boolean directed, long seed) { - List phases = - List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 4096), phase(1, 4096, 16384)); - testSSSPPositiveInt(algo, directed, seed, phases); + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 4096).repeat(8); + tester.addPhase().withArgs(4096, 16384).repeat(1); + testSSSPPositiveInt(algo, directed, seed, tester); } - static void testSSSPPositiveInt(ShortestPathSingleSource algo, boolean directed, long seed, List phases) { + static void testSSSPPositiveInt(ShortestPathSingleSource algo, boolean directed, long seed, PhasedTester tester) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); @@ -67,10 +68,12 @@ static void testSSSPPositiveInt(ShortestPathSingleSource algo, boolean directed, static void testSSSPPositive(ShortestPathSingleSource algo, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 4096), phase(1, 3542, 25436)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 4096).repeat(8); + tester.addPhase().withArgs(3542, 25436).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); WeightFunction w = GraphsTestUtils.assignRandWeights(g, seedGen.nextSeed()); @@ -85,10 +88,12 @@ static void testSSSPPositive(ShortestPathSingleSource algo, boolean directed, lo static void testSSSPCardinality(ShortestPathSingleSource algo, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = - List.of(phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 4096), phase(1, 4096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 4096).repeat(8); + tester.addPhase().withArgs(4096, 16384).repeat(1); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(directed).parallelEdges(true) .selfEdges(true).cycles(true).connected(false).build(); int[] vs = g.vertices().toIntArray(); @@ -103,10 +108,13 @@ static void testSSSPCardinality(ShortestPathSingleSource algo, boolean directed, static void testSSSPDirectedNegativeInt(ShortestPathSingleSource algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(512, 4, 4), phase(128, 16, 32), phase(64, 64, 256), phase(8, 512, 4096), - phase(2, 1024, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(4, 4).repeat(512); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(512, 4096).repeat(8); + tester.addPhase().withArgs(1024, 4096).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntNeg(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/TSPMetricTest.java b/jgalgo-core/src/test/java/com/jgalgo/TSPMetricTest.java index d726c7d484..5f5e359d89 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/TSPMetricTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/TSPMetricTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.BitSet; -import java.util.List; import java.util.Random; import java.util.function.Predicate; import org.junit.jupiter.api.Test; @@ -33,10 +32,14 @@ public class TSPMetricTest extends TestBase { public void testMstAppxAndMatchingAppxRandGraphs() { final long seed = 0x6c019c0fba54c10fL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(512, 4), phase(64, 15), phase(32, 32), phase(8, 59), phase(4, 128), phase(3, 256)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(4).repeat(512); + tester.addPhase().withArgs(15).repeat(64); + tester.addPhase().withArgs(32).repeat(32); + tester.addPhase().withArgs(59).repeat(8); + tester.addPhase().withArgs(128).repeat(4); + tester.addPhase().withArgs(256).repeat(3); + tester.run(n -> { testMstAppxAndMatchingAppxRandGraph(n, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/TopologicalOrderTest.java b/jgalgo-core/src/test/java/com/jgalgo/TopologicalOrderTest.java index c0f2982ec0..ba81d42b15 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/TopologicalOrderTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/TopologicalOrderTest.java @@ -17,7 +17,6 @@ package com.jgalgo; import static org.junit.jupiter.api.Assertions.assertFalse; -import java.util.List; import java.util.Set; import org.junit.jupiter.api.Test; import com.jgalgo.graph.EdgeIter; @@ -43,9 +42,11 @@ public void testTopologicalSortConnected() { private static void topologicalSort(boolean connected, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16, 16), phase(128, 32, 64), phase(2, 1024, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(32, 64).repeat(128); + tester.addPhase().withArgs(1024, 2048).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(true).parallelEdges(true) .selfEdges(false).cycles(false).connected(connected).build(); diff --git a/jgalgo-core/src/test/java/com/jgalgo/TreePathMaximaTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/TreePathMaximaTestUtils.java index 19e5b677bc..fb3ca2edba 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/TreePathMaximaTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/TreePathMaximaTestUtils.java @@ -19,7 +19,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import com.jgalgo.graph.Graph; import com.jgalgo.graph.GraphFactory; @@ -96,10 +95,15 @@ static void compareActualToExpectedResults(TreePathMaxima.Queries queries, TreeP static void testTPM(TreePathMaxima algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 16), phase(32, 32), phase(16, 64), phase(8, 128), phase(4, 256), - phase(2, 512), phase(1, 1234)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(64); + tester.addPhase().withArgs(32).repeat(32); + tester.addPhase().withArgs(64).repeat(16); + tester.addPhase().withArgs(128).repeat(8); + tester.addPhase().withArgs(256).repeat(4); + tester.addPhase().withArgs(512).repeat(2); + tester.addPhase().withArgs(1234).repeat(1); + tester.run(n -> { testTPM(algo, n, seedGen.nextSeed()); }); } @@ -118,10 +122,14 @@ private static void testTPM(TreePathMaxima algo, int n, long seed) { static void verifyMSTPositive(TreePathMaxima algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8, 16), phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), - phase(8, 2048, 4096), phase(2, 8192, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 16).repeat(256); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(2048, 4096).repeat(8); + tester.addPhase().withArgs(8192, 16384).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); @@ -134,11 +142,14 @@ static void verifyMSTPositive(TreePathMaxima algo, long seed) { static void verifyMSTNegative(TreePathMaxima algo, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8, 16), phase(128, 16, 32), phase(64, 64, 128), phase(32, 128, 256), - phase(8, 2048, 4096), phase(2, 8192, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 16).repeat(256); + tester.addPhase().withArgs(16, 32).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(128, 256).repeat(32); + tester.addPhase().withArgs(2048, 4096).repeat(8); + tester.addPhase().withArgs(8192, 16384).repeat(2); + tester.run((n, m) -> { Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(true) .selfEdges(true).cycles(true).connected(true).build(); WeightFunction.Int w = GraphsTestUtils.assignRandWeightsIntPos(g, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/TreesTest.java b/jgalgo-core/src/test/java/com/jgalgo/TreesTest.java index aa317789d7..d0ca88e5c0 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/TreesTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/TreesTest.java @@ -18,7 +18,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; @@ -31,9 +30,12 @@ public class TreesTest extends TestBase { public void testIsTreeUnrootedPositive() { final long seed = 0xb83f3ebfa35ba7a8L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); @@ -46,9 +48,12 @@ public void testIsTreeUnrootedNegativeUnconnected() { final long seed = 0x77ec2f837d2f095bL; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); int[] edges = g.edges().toIntArray(); @@ -64,9 +69,12 @@ public void testIsTreeUnrootedNegativeCycle() { final long seed = 0x2545a2e6fdbf259cL; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); int u, v; @@ -86,9 +94,12 @@ public void testIsTreeRootedPositive() { final long seed = 0x15d7bb062a63d066L; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); int[] vs = g.vertices().toIntArray(); @@ -103,9 +114,12 @@ public void testIsTreeRootedNegativeUnconnected() { final long seed = 0xa06f15857aeff09dL; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); int[] vs = g.vertices().toIntArray(); @@ -123,9 +137,12 @@ public void testIsTreeRootedNegativeCycle() { final long seed = 0xad27b6b0cb625eb3L; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); int[] vs = g.vertices().toIntArray(); @@ -146,9 +163,12 @@ public void testIsForestPositive() { final long seed = 0xb63ccfd25f531281L; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); // remove a few edges @@ -166,9 +186,12 @@ public void testIsForestNegative() { final long seed = 0xe1a9a20ecb9e816bL; final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); - List phases = List.of(phase(256, 16), phase(128, 32), phase(4, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n - 1; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(2048).repeat(4); + tester.run(n -> { + int m = n - 1; Graph g = new RandomGraphBuilder(seedGen.nextSeed()).n(n).m(m).directed(false).parallelEdges(false) .selfEdges(false).cycles(false).connected(true).build(); // remove a few edges diff --git a/jgalgo-core/src/test/java/com/jgalgo/VertexCoverBarYehudaTest.java b/jgalgo-core/src/test/java/com/jgalgo/VertexCoverBarYehudaTest.java index 90d1b80e38..cf3ec110ee 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/VertexCoverBarYehudaTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/VertexCoverBarYehudaTest.java @@ -17,7 +17,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.function.ToDoubleFunction; import org.junit.jupiter.api.Test; import com.jgalgo.graph.Graph; @@ -40,10 +39,12 @@ public void testRandGraphs() { final long seed = 0x3c94d9694bd37614L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8, 16), phase(64, 64, 256), phase(16, 1024, 2048), phase(2, 8096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 16).repeat(256); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(1024, 2048).repeat(16); + tester.addPhase().withArgs(8096, 16384).repeat(2); + tester.run((n, m) -> { Graph g = GraphsTestUtils.randGraph(n, m, seedGen.nextSeed()); RandomIntUnique rand = new RandomIntUnique(0, 163454, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java index a843fcf713..33be4a0724 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/graph/GraphImplTestUtils.java @@ -789,10 +789,16 @@ static void testUndirectedBipartiteMatchingWeighted(Boolean2ObjectFunction graphImpl, boolean directed, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(2056, 6, 6), phase(32, 16, 16), phase(32, 16, 32), phase(16, 64, 64), - phase(16, 64, 128), phase(4, 512, 512), phase(2, 512, 1324), phase(1, 1025, 2016)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(6, 6).repeat(2056); + tester.addPhase().withArgs(16, 16).repeat(32); + tester.addPhase().withArgs(16, 32).repeat(32); + tester.addPhase().withArgs(64, 64).repeat(16); + tester.addPhase().withArgs(64, 128).repeat(16); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 1324).repeat(2); + tester.addPhase().withArgs(1025, 2016).repeat(1); + tester.run((n, m) -> { testRandOps(graphImpl, directed, n, m, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/BinarySearchTreeTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/BinarySearchTreeTestUtils.java index c8b0449184..16e1839a2f 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/BinarySearchTreeTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/BinarySearchTreeTestUtils.java @@ -42,10 +42,13 @@ static void testExtractMax(BinarySearchTree.Builder treeBuilder, final SeedGenerator seedGen = new SeedGenerator(seed); Random rand = new Random(seedGen.nextSeed()); IntComparator compare = null; - List phases = List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.run(n -> { BSTTracker tracker = new BSTTracker(treeBuilder.build(compare), 0, compare, seedGen.nextSeed()); HeapReferenceableTestUtils.testHeap(tracker, n, TestMode.InsertFirst, randArray(n / 2, 0, Integer.MAX_VALUE, seedGen.nextSeed()), compare, seedGen.nextSeed()); @@ -77,9 +80,13 @@ static void testFindSmallerCustomCompare(BinarySearchTree.Builder private static void testFindSmaller(BinarySearchTree.Builder treeBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.run(n -> { testFindSmallerGreater(treeBuilder, compare, seedGen.nextSeed(), n, true); }); } @@ -95,9 +102,13 @@ static void testFindGreaterCustomCompare(BinarySearchTree.Builder private static void testFindGreater(BinarySearchTree.Builder treeBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.run(n -> { testFindSmallerGreater(treeBuilder, compare, seedGen.nextSeed(), n, false); }); } @@ -154,9 +165,13 @@ static void testGetPredecessorsCustomCompare(BinarySearchTree.Builder treeBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.run(n -> { testGetPredecessorSuccessor(treeBuilder, n, compare, seedGen.nextSeed(), true); }); } @@ -173,9 +188,13 @@ private static void testGetSuccessors(BinarySearchTree.Builder tr long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 8), phase(128, 32), phase(32, 128), phase(16, 256), phase(8, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(256); + tester.addPhase().withArgs(32).repeat(128); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(256).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.run(n -> { testGetPredecessorSuccessor(treeBuilder, n, compare, seedGen.nextSeed(), false); }); } @@ -233,9 +252,13 @@ static void testSplitCustomCompare(BinarySearchTree.Builder treeB private static void testSplit(BinarySearchTree.Builder treeBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 8), phase(64, 32), phase(16, 128), phase(8, 256), phase(4, 1024)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8).repeat(128); + tester.addPhase().withArgs(32).repeat(64); + tester.addPhase().withArgs(128).repeat(16); + tester.addPhase().withArgs(256).repeat(8); + tester.addPhase().withArgs(1024).repeat(4); + tester.run(n -> { BinarySearchTreeTestUtils.testSplit(treeBuilder, n, compare, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/DynamicTreeSplayTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/DynamicTreeSplayTest.java index bb5fa4e0a8..4f4e1c899b 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/DynamicTreeSplayTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/DynamicTreeSplayTest.java @@ -54,10 +54,16 @@ static void testRandOps(DoubleFunction builder, List static void testRandOps(DoubleFunction builder, List ops, ToIntFunction sizeFunc, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16), phase(64, 32), phase(64, 64), phase(32, 128), phase(16, 512), - phase(16, 2048), phase(8, 4096), phase(4, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int m = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(32).repeat(64); + tester.addPhase().withArgs(64).repeat(64); + tester.addPhase().withArgs(128).repeat(32); + tester.addPhase().withArgs(512).repeat(16); + tester.addPhase().withArgs(2048).repeat(16); + tester.addPhase().withArgs(4096).repeat(8); + tester.addPhase().withArgs(16384).repeat(4); + tester.run(m -> { testRandOps(builder, m, ops, sizeFunc, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapReferenceableTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapReferenceableTestUtils.java index 32b54bce1d..06ed9740ae 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapReferenceableTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapReferenceableTestUtils.java @@ -47,10 +47,13 @@ static void testRandOpsCustomCompare(HeapReferenceable.Builder he private static void testRandOps(HeapReferenceable.Builder heapBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 16), phase(64, 64, 128), phase(32, 512, 1024), phase(8, 4096, 8096), - phase(4, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(32); + tester.addPhase().withArgs(4096, 8096).repeat(8); + tester.addPhase().withArgs(16384, 32768).repeat(4); + tester.run((n, m) -> { HeapReferenceable heap = heapBuilder.build(compare); testHeap(heap, n, m, TestMode.Normal, compare, seedGen.nextSeed()); }); @@ -59,12 +62,15 @@ private static void testRandOps(HeapReferenceable.Builder heapBui static void testRandOpsAfterManyInserts(HeapReferenceable.Builder heapBuilder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final IntComparator compare = null; - List phases = List.of(phase(256, 16, 16), phase(128, 64, 128), phase(64, 512, 1024), - phase(16, 4096, 8096), phase(8, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(64, 128).repeat(128); + tester.addPhase().withArgs(512, 1024).repeat(64); + tester.addPhase().withArgs(4096, 8096).repeat(16); + tester.addPhase().withArgs(16384, 32768).repeat(8); + tester.run(n -> { + int m = n; HeapReferenceable heap = heapBuilder.build(compare); - testHeap(heap, n, m, TestMode.InsertFirst, compare, seedGen.nextSeed()); }); } @@ -90,9 +96,12 @@ static void testMeldWithOrderedValuesCustomCompare(HeapReferenceable.Builder heapBuilder, boolean orderedValues, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 16), phase(64, 32), phase(8, 256), phase(1, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int hCount = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(64); + tester.addPhase().withArgs(32).repeat(64); + tester.addPhase().withArgs(256).repeat(8); + tester.addPhase().withArgs(2048).repeat(1); + tester.run(hCount -> { testMeld(heapBuilder, orderedValues, hCount, compare, seedGen.nextSeed()); }); } @@ -154,9 +163,13 @@ static void testDecreaseKeyCustomCompare(HeapReferenceable.Builder heapBuilder, IntComparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(256, 16), phase(128, 64), phase(64, 512), phase(16, 4096), phase(2, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(64).repeat(128); + tester.addPhase().withArgs(512).repeat(64); + tester.addPhase().withArgs(4096).repeat(16); + tester.addPhase().withArgs(16384).repeat(2); + tester.run(n -> { int m = n; HeapReferenceable heap = heapBuilder.build(compare); testHeap(heap, n, m, TestMode.DecreaseKey, compare, seedGen.nextSeed()); diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapTestUtils.java index cf46fc5a15..c56108c63a 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/HeapTestUtils.java @@ -45,10 +45,13 @@ static void testRandOpsCustomCompare(Heap.Builder heapBuilder, long see private static void testRandOps(Heap.Builder heapBuilder, Comparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 16), phase(64, 64, 128), phase(32, 512, 1024), phase(8, 4096, 8096), - phase(4, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(32); + tester.addPhase().withArgs(4096, 8096).repeat(8); + tester.addPhase().withArgs(16384, 32768).repeat(4); + tester.run((n, m) -> { Heap heap = heapBuilder.build(compare); testHeap(heap, n, m, TestMode.Normal, compare, seedGen.nextSeed()); }); @@ -57,12 +60,15 @@ private static void testRandOps(Heap.Builder heapBuilder, Comparator heapBuilder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); final Comparator compare = null; - List phases = List.of(phase(256, 16, 16), phase(128, 64, 128), phase(64, 512, 1024), - phase(16, 4096, 8096), phase(8, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = n; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(256); + tester.addPhase().withArgs(64).repeat(128); + tester.addPhase().withArgs(512).repeat(64); + tester.addPhase().withArgs(4096).repeat(16); + tester.addPhase().withArgs(16384).repeat(8); + tester.run(n -> { + int m = n; Heap heap = heapBuilder.build(compare); - testHeap(heap, n, m, TestMode.InsertFirst, compare, seedGen.nextSeed()); }); } @@ -86,9 +92,12 @@ static void testMeldWithOrderedValuesCustomCompare(Heap.Builder heapBui private static void testMeld(Heap.Builder heapBuilder, boolean orderedValues, Comparator compare, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 16), phase(64, 32), phase(8, 256), phase(1, 2048)); - runTestMultiple(phases, (testIter, args) -> { - int hCount = args[0]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16).repeat(64); + tester.addPhase().withArgs(32).repeat(64); + tester.addPhase().withArgs(256).repeat(8); + tester.addPhase().withArgs(2048).repeat(1); + tester.run(hCount -> { testMeld(heapBuilder, orderedValues, hCount, compare, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/RedBlackTreeExtendedTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/RedBlackTreeExtendedTest.java index b1434d1537..37ea7e1677 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/RedBlackTreeExtendedTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/RedBlackTreeExtendedTest.java @@ -32,11 +32,13 @@ public void testExtensionSizeRandOps() { final long seed = 0xe5136a0085e719d1L; final SeedGenerator seedGen = new SeedGenerator(seed); final IntComparator compare = null; - List phases = List.of(phase(256, 16, 16), phase(128, 64, 128), phase(64, 512, 1024), - phase(16, 4096, 8096), phase(8, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(256); + tester.addPhase().withArgs(64, 128).repeat(128); + tester.addPhase().withArgs(512, 1024).repeat(64); + tester.addPhase().withArgs(4096, 8096).repeat(16); + tester.addPhase().withArgs(16384, 32768).repeat(8); + tester.run((n, m) -> { RedBlackTreeExtension.Size sizeExt = new RedBlackTreeExtension.Size<>(); RedBlackTree tree = new RedBlackTreeExtended<>(compare, List.of(sizeExt)); @@ -60,11 +62,13 @@ public void testExtensionMinRandOps() { final long seed = 0xe5136a0085e719d1L; final SeedGenerator seedGen = new SeedGenerator(seed); final IntComparator compare = null; - List phases = List.of(phase(64, 16, 16), phase(64, 64, 128), phase(32, 512, 1024), phase(8, 4096, 8096), - phase(4, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(32); + tester.addPhase().withArgs(4096, 8096).repeat(8); + tester.addPhase().withArgs(16384, 32768).repeat(4); + tester.run((n, m) -> { RedBlackTreeExtension.Min minExt = new RedBlackTreeExtension.Min<>(); RedBlackTree tree = new RedBlackTreeExtended<>(compare, List.of(minExt)); @@ -86,11 +90,13 @@ public void testExtensionMaxRandOps() { final long seed = 0x7674bddef0a0863bL; final SeedGenerator seedGen = new SeedGenerator(seed); final IntComparator compare = null; - List phases = List.of(phase(64, 16, 16), phase(64, 64, 128), phase(32, 512, 1024), phase(8, 4096, 8096), - phase(4, 16384, 32768)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; - + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(64, 128).repeat(64); + tester.addPhase().withArgs(512, 1024).repeat(32); + tester.addPhase().withArgs(4096, 8096).repeat(8); + tester.addPhase().withArgs(16384, 32768).repeat(4); + tester.run((n, m) -> { RedBlackTreeExtension.Max maxExt = new RedBlackTreeExtension.Max<>(); RedBlackTree tree = new RedBlackTreeExtended<>(compare, List.of(maxExt)); diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/SplitFindMinArrayTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/SplitFindMinArrayTest.java index 3daaf0c324..6456963a7a 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/SplitFindMinArrayTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/SplitFindMinArrayTest.java @@ -29,10 +29,13 @@ public class SplitFindMinArrayTest extends TestBase { private static void testSplitFind(Supplier builder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 16), phase(64, 64, 64), phase(32, 512, 512), phase(8, 4096, 4096), - phase(2, 16384, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(64, 64).repeat(64); + tester.addPhase().withArgs(512, 512).repeat(32); + tester.addPhase().withArgs(4096, 4096).repeat(8); + tester.addPhase().withArgs(16384, 16384).repeat(2); + tester.run((n, m) -> { testSplitFind(builder, n, m, seedGen.nextSeed()); }); } @@ -77,9 +80,12 @@ private static void testSplitFind(Supplier builder, int n, private static void testSplitFindMin(Supplier> builder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(128, 16, 16), phase(64, 64, 64), phase(8, 512, 512), phase(1, 4096, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(128); + tester.addPhase().withArgs(64, 64).repeat(64); + tester.addPhase().withArgs(512, 512).repeat(8); + tester.addPhase().withArgs(4096, 4096).repeat(1); + tester.run((n, m) -> { testSplitFindMin(builder, n, m, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/SubtreeMergeFindminTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/SubtreeMergeFindminTest.java index 8017ea13db..36ac566560 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/SubtreeMergeFindminTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/SubtreeMergeFindminTest.java @@ -36,10 +36,15 @@ public class SubtreeMergeFindminTest extends TestBase { public void testRandOps() { final long seed = 0x08f45606b1a84c66L; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = List.of(phase(64, 16, 16), phase(64, 16, 32), phase(32, 64, 64), phase(32, 64, 128), - phase(4, 512, 512), phase(4, 512, 2048), phase(1, 1000, 4096)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(16, 16).repeat(64); + tester.addPhase().withArgs(16, 32).repeat(64); + tester.addPhase().withArgs(64, 64).repeat(32); + tester.addPhase().withArgs(64, 128).repeat(32); + tester.addPhase().withArgs(512, 512).repeat(4); + tester.addPhase().withArgs(512, 2048).repeat(4); + tester.addPhase().withArgs(1000, 4096).repeat(1); + tester.run((n, m) -> { testRandOps(SubtreeMergeFindMinImpl::new, n, m, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindTestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindTestUtils.java index df7efbd447..45175fdcf7 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindTestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindTestUtils.java @@ -17,7 +17,6 @@ package com.jgalgo.internal.data; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Random; import java.util.function.Supplier; import com.jgalgo.internal.util.TestUtils; @@ -26,10 +25,12 @@ class UnionFindTestUtils extends TestUtils { static void randOps(Supplier builder, long seed) { final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8, 16), phase(64, 64, 256), phase(16, 1024, 2048), phase(2, 8096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 16).repeat(256); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(1024, 2048).repeat(16); + tester.addPhase().withArgs(8096, 16384).repeat(2); + tester.run((n, m) -> { randOps(builder, n, m, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindValueArrayTest.java b/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindValueArrayTest.java index 44dadfb353..eb1f213dc0 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindValueArrayTest.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/data/UnionFindValueArrayTest.java @@ -17,7 +17,6 @@ package com.jgalgo.internal.data; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.List; import java.util.Random; import org.junit.jupiter.api.Test; import com.jgalgo.internal.util.TestBase; @@ -34,10 +33,12 @@ public void testRandRegularUFOps() { public void testRandOps() { final long seed = 0x8c06f8977b257d8cL; final SeedGenerator seedGen = new SeedGenerator(seed); - List phases = - List.of(phase(256, 8, 16), phase(64, 64, 256), phase(16, 1024, 2048), phase(2, 8096, 16384)); - runTestMultiple(phases, (testIter, args) -> { - int n = args[0], m = args[1]; + PhasedTester tester = new PhasedTester(); + tester.addPhase().withArgs(8, 16).repeat(256); + tester.addPhase().withArgs(64, 256).repeat(64); + tester.addPhase().withArgs(1024, 2048).repeat(16); + tester.addPhase().withArgs(8096, 16384).repeat(2); + tester.run((n, m) -> { randOps(n, m, seedGen.nextSeed()); }); } diff --git a/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java b/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java index 61c0526f16..e51aed6449 100644 --- a/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java +++ b/jgalgo-core/src/test/java/com/jgalgo/internal/util/TestUtils.java @@ -16,90 +16,91 @@ package com.jgalgo.internal.util; -import java.util.Collection; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import java.util.Random; - import it.unimi.dsi.fastutil.ints.IntArrays; -@SuppressWarnings("boxing") public class TestUtils { - public static class Phase { - private final int repeat; - private final int[] args; + public static class PhasedTester { - private Phase(int repeat, int[] args) { - if (repeat < 0) - throw new IllegalArgumentException(); - this.repeat = repeat; - this.args = args; - } + public static class Phase { + + int repeat; + int[] args; + + Phase() {} + + public Phase repeat(int r) { + if (r <= 0) + throw new IllegalArgumentException(); + this.repeat = r; + return this; + } - static Phase of(int repeat, int... args) { - return new Phase(repeat, args); + public Phase withArgs(int... args) { + if (args.length == 0) + throw new IllegalArgumentException(); + this.args = args; + return this; + } } - } - public static Phase phase(int repeat, int... args) { - return Phase.of(repeat, args); - } + private final List phases = new ArrayList<>(); - @FunctionalInterface - public static interface TestRunnable { - public void run(TestIterIdx testIter, int[] args); - } + public Phase addPhase() { + Phase phase = new Phase(); + phases.add(phase); + return phase; + } - public static void runTestMultiple(Collection phases, TestRunnable test) { - int phaseIdx = 0; - for (Phase phase : phases) { - for (int iter = 0; iter < phase.repeat; iter++) { - try { - test.run(new TestIterIdx(phaseIdx, iter), phase.args); - } catch (Throwable e) { - System.err.println("Failed at phase " + phaseIdx + " iter " + iter); - throw e; - } + public void run(RunnableTestWith1Args test) { + for (Phase phase : phases) { + assertArgsNum(phase, 1); + for (int repeat = phase.repeat; repeat > 0; repeat--) + test.run(phase.args[0]); } - phaseIdx++; } - } - public static class TestIterIdx { - public final int phase, iter; + public void run(RunnableTestWith2Args test) { + for (Phase phase : phases) { + assertArgsNum(phase, 2); + for (int repeat = phase.repeat; repeat > 0; repeat--) + test.run(phase.args[0], phase.args[1]); + } + } - private TestIterIdx(int phase, int iter) { - this.phase = phase; - this.iter = iter; + public void run(RunnableTestWith3Args test) { + for (Phase phase : phases) { + assertArgsNum(phase, 3); + for (int repeat = phase.repeat; repeat > 0; repeat--) + test.run(phase.args[0], phase.args[1], phase.args[2]); + } } - @Override - public String toString() { - return "P" + phase + " I" + iter; + private static void assertArgsNum(Phase phase, int runnableArgs) { + if (phase.args.length != runnableArgs) + throw new IllegalArgumentException( + "Phase had " + phase.args.length + " arguments, but runnable accept " + runnableArgs); } - } - public static boolean doubleEql(double a, double b, double precise) { - if (a < b) - return b - a < precise; - if (a > b) - return a - b < precise; - return true; - } + @FunctionalInterface + public static interface RunnableTestWith1Args { + public void run(int arg1); + } - public static void printArr(int a[]) { - printArr(a, true); - } + @FunctionalInterface + public static interface RunnableTestWith2Args { + public void run(int arg1, int arg2); + } - public static void printArr(int a[], boolean printIndicies) { - for (int i = 0; i < a.length; i++) - System.out.print("" + String.format("%03d", a[i]) + ", "); - System.out.println(); - if (printIndicies) { - for (int i = 0; i < a.length; i++) - System.out.print("" + String.format("%03d", i) + ", "); - System.out.println(); + @FunctionalInterface + public static interface RunnableTestWith3Args { + public void run(int arg1, int arg2, int arg3); } + } public static int[] randArray(int n, long seed) {