From 05e488ee85371f1da02629f6258ffabb2e077301 Mon Sep 17 00:00:00 2001 From: Hyunseok Seo Date: Fri, 7 Jun 2024 23:51:21 +0900 Subject: [PATCH] update parameterized test --- .../search/TestParallelSearcher.java | 50 +++++------ .../search/TestVectorRangeSearcher.java | 51 +++++------ .../TestFixedWidthOutOfPlaceVectorSorter.java | 53 ++++++----- .../algorithm/sort/TestFixedWidthSorting.java | 87 ++++++++----------- .../sort/TestOutOfPlaceVectorSorter.java | 23 ++--- ...stVariableWidthOutOfPlaceVectorSorter.java | 18 ++-- .../sort/TestVariableWidthSorting.java | 49 ++++------- 7 files changed, 146 insertions(+), 185 deletions(-) diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java index 3cd9c8bdcd48e..504c35cfd12e6 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestParallelSearcher.java @@ -21,11 +21,11 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.stream.Stream; import org.apache.arrow.algorithm.sort.DefaultVectorComparators; import org.apache.arrow.algorithm.sort.VectorValueComparator; @@ -35,64 +35,57 @@ import org.apache.arrow.vector.VarCharVector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test cases for {@link ParallelSearcher}. */ -@RunWith(Parameterized.class) public class TestParallelSearcher { - private enum ComparatorType { + public enum ComparatorType { EqualityComparator, OrderingComparator; } private static final int VECTOR_LENGTH = 10000; - private final int threadCount; - private BufferAllocator allocator; private ExecutorService threadPool; - private final ComparatorType comparatorType; - - public TestParallelSearcher(ComparatorType comparatorType, int threadCount) { - this.comparatorType = comparatorType; - this.threadCount = threadCount; - } - - @Parameterized.Parameters(name = "comparator type = {0}, thread count = {1}") - public static Collection getComparatorName() { - List params = new ArrayList<>(); + static Stream getComparatorName() { + List params = new ArrayList<>(); int[] threadCounts = {1, 2, 5, 10, 20, 50}; for (ComparatorType type : ComparatorType.values()) { for (int count : threadCounts) { - params.add(new Object[] {type, count}); + params.add(Arguments.of(type, count)); } } - return params; + return params.stream(); } @BeforeEach public void prepare() { allocator = new RootAllocator(1024 * 1024); - threadPool = Executors.newFixedThreadPool(threadCount); } @AfterEach public void shutdown() { allocator.close(); - threadPool.shutdown(); + if (threadPool != null) { + threadPool.shutdown(); + } } - @Test - public void testParallelIntSearch() throws ExecutionException, InterruptedException { + @ParameterizedTest(name = "comparator type = {0}, thread count = {1}") + @MethodSource("getComparatorName") + public void testParallelIntSearch(ComparatorType comparatorType, int threadCount) + throws ExecutionException, InterruptedException { + threadPool = Executors.newFixedThreadPool(threadCount); try (IntVector targetVector = new IntVector("targetVector", allocator); - IntVector keyVector = new IntVector("keyVector", allocator)) { + IntVector keyVector = new IntVector("keyVector", allocator)) { targetVector.allocateNew(VECTOR_LENGTH); keyVector.allocateNew(VECTOR_LENGTH); @@ -119,8 +112,11 @@ public void testParallelIntSearch() throws ExecutionException, InterruptedExcept } } - @Test - public void testParallelStringSearch() throws ExecutionException, InterruptedException { + @ParameterizedTest(name = "comparator type = {0}, thread count = {1}") + @MethodSource("getComparatorName") + public void testParallelStringSearch(ComparatorType comparatorType, int threadCount) + throws ExecutionException, InterruptedException { + threadPool = Executors.newFixedThreadPool(threadCount); try (VarCharVector targetVector = new VarCharVector("targetVector", allocator); VarCharVector keyVector = new VarCharVector("keyVector", allocator)) { targetVector.allocateNew(VECTOR_LENGTH); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java index 1ab7958dae0a9..2a3f703aee72b 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/search/TestVectorRangeSearcher.java @@ -19,8 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.Arrays; -import java.util.Collection; +import java.util.stream.Stream; import org.apache.arrow.algorithm.sort.DefaultVectorComparators; import org.apache.arrow.algorithm.sort.VectorValueComparator; @@ -29,24 +28,17 @@ import org.apache.arrow.vector.IntVector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test cases for {@link VectorRangeSearcher}. */ -@RunWith(Parameterized.class) public class TestVectorRangeSearcher { private BufferAllocator allocator; - private int repeat; - - public TestVectorRangeSearcher(int repeat) { - this.repeat = repeat; - } - @BeforeEach public void prepare() { allocator = new RootAllocator(1024 * 1024); @@ -57,8 +49,9 @@ public void shutdown() { allocator.close(); } - @Test - public void testGetLowerBounds() { + @ParameterizedTest(name = "repeat = {0}") + @MethodSource("getRepeat") + public void testGetLowerBounds(int repeat) { final int maxValue = 100; try (IntVector intVector = new IntVector("int vec", allocator)) { // allocate vector @@ -86,11 +79,12 @@ public void testGetLowerBounds() { } } - @Test - public void testGetLowerBoundsNegative() { + @ParameterizedTest(name = "repeat = {0}") + @MethodSource("getRepeat") + public void testGetLowerBoundsNegative(int repeat) { final int maxValue = 100; try (IntVector intVector = new IntVector("int vec", allocator); - IntVector negVector = new IntVector("neg vec", allocator)) { + IntVector negVector = new IntVector("neg vec", allocator)) { // allocate vector intVector.allocateNew(maxValue * repeat); intVector.setValueCount(maxValue * repeat); @@ -120,8 +114,9 @@ public void testGetLowerBoundsNegative() { } } - @Test - public void testGetUpperBounds() { + @ParameterizedTest(name = "repeat = {0}") + @MethodSource("getRepeat") + public void testGetUpperBounds(int repeat) { final int maxValue = 100; try (IntVector intVector = new IntVector("int vec", allocator)) { // allocate vector @@ -149,8 +144,9 @@ public void testGetUpperBounds() { } } - @Test - public void testGetUpperBoundsNegative() { + @ParameterizedTest(name = "repeat = {0}") + @MethodSource("getRepeat") + public void testGetUpperBoundsNegative(int repeat) { final int maxValue = 100; try (IntVector intVector = new IntVector("int vec", allocator); IntVector negVector = new IntVector("neg vec", allocator)) { @@ -183,13 +179,12 @@ public void testGetUpperBoundsNegative() { } } - @Parameterized.Parameters(name = "repeat = {0}") - public static Collection getRepeat() { - return Arrays.asList( - new Object[]{1}, - new Object[]{2}, - new Object[]{5}, - new Object[]{10} + static Stream getRepeat() { + return Stream.of( + Arguments.of(1), + Arguments.of(2), + Arguments.of(5), + Arguments.of(10) ); } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthOutOfPlaceVectorSorter.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthOutOfPlaceVectorSorter.java index 95a5441a9e60e..b363af3f0de06 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthOutOfPlaceVectorSorter.java @@ -35,7 +35,8 @@ import org.apache.arrow.vector.testing.ValueVectorDataPopulator; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test cases for {@link FixedWidthOutOfPlaceVectorSorter}. @@ -44,10 +45,6 @@ public class TestFixedWidthOutOfPlaceVectorSorter extends TestOutOfPlaceVectorSo private BufferAllocator allocator; - public TestFixedWidthOutOfPlaceVectorSorter(boolean generalSorter) { - super(generalSorter); - } - OutOfPlaceVectorSorter getSorter() { return generalSorter ? new GeneralOutOfPlaceVectorSorter<>() : new FixedWidthOutOfPlaceVectorSorter<>(); } @@ -62,8 +59,10 @@ public void shutdown() { allocator.close(); } - @Test - public void testSortByte() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortByte(boolean generalSorter) { + setup(generalSorter); try (TinyIntVector vec = new TinyIntVector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -85,7 +84,7 @@ public void testSortByte() { VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vec); TinyIntVector sortedVec = - (TinyIntVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); + (TinyIntVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); sortedVec.allocateNew(vec.getValueCount()); sortedVec.setValueCount(vec.getValueCount()); @@ -109,8 +108,10 @@ public void testSortByte() { } } - @Test - public void testSortShort() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortShort(boolean generalSorter) { + setup(generalSorter); try (SmallIntVector vec = new SmallIntVector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -132,7 +133,7 @@ public void testSortShort() { VectorValueComparator comparator = DefaultVectorComparators.createDefaultComparator(vec); SmallIntVector sortedVec = - (SmallIntVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); + (SmallIntVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); sortedVec.allocateNew(vec.getValueCount()); sortedVec.setValueCount(vec.getValueCount()); @@ -156,8 +157,10 @@ public void testSortShort() { } } - @Test - public void testSortInt() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortInt(boolean generalSorter) { + setup(generalSorter); try (IntVector vec = new IntVector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -202,8 +205,10 @@ public void testSortInt() { } } - @Test - public void testSortLong() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortLong(boolean generalSorter) { + setup(generalSorter); try (BigIntVector vec = new BigIntVector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -248,8 +253,10 @@ public void testSortLong() { } } - @Test - public void testSortFloat() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortFloat(boolean generalSorter) { + setup(generalSorter); try (Float4Vector vec = new Float4Vector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -294,8 +301,10 @@ public void testSortFloat() { } } - @Test - public void testSortDouble() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortDouble(boolean generalSorter) { + setup(generalSorter); try (Float8Vector vec = new Float8Vector("", allocator)) { vec.allocateNew(10); vec.setValueCount(10); @@ -340,8 +349,10 @@ public void testSortDouble() { } } - @Test - public void testSortInt2() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortInt2(boolean generalSorter) { + setup(generalSorter); try (IntVector vec = new IntVector("", allocator)) { ValueVectorDataPopulator.setVector(vec, 0, 1, 2, 3, 4, 5, 30, 31, 32, 33, diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java index c9cb1f09a74b3..88f4090de8527 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestFixedWidthSorting.java @@ -18,9 +18,9 @@ package org.apache.arrow.algorithm.sort; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.function.Function; +import java.util.stream.Stream; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -33,30 +33,19 @@ import org.apache.arrow.vector.TinyIntVector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test sorting fixed width vectors with random data. */ -@RunWith(Parameterized.class) public class TestFixedWidthSorting> { static final int[] VECTOR_LENGTHS = new int[] {2, 5, 10, 50, 100, 1000, 3000}; static final double[] NULL_FRACTIONS = {0, 0.1, 0.3, 0.5, 0.7, 0.9, 1}; - private final int length; - - private final double nullFraction; - - private final boolean inPlace; - - private final Function vectorGenerator; - - private final TestSortingUtil.DataGenerator dataGenerator; - private BufferAllocator allocator; @BeforeEach @@ -69,26 +58,20 @@ public void shutdown() { allocator.close(); } - public TestFixedWidthSorting( - int length, double nullFraction, boolean inPlace, String desc, + @ParameterizedTest(name = "in place = {0}, length = {1}, null fraction = {2}, desc = {3}, vector = {4}") + @MethodSource("getParameters") + public void testSort( + boolean inPlace, int length, double nullFraction, String desc, Function vectorGenerator, TestSortingUtil.DataGenerator dataGenerator) { - this.length = length; - this.nullFraction = nullFraction; - this.inPlace = inPlace; - this.vectorGenerator = vectorGenerator; - this.dataGenerator = dataGenerator; - } - - @Test - public void testSort() { if (inPlace) { - sortInPlace(); + sortInPlace(length, nullFraction, vectorGenerator, dataGenerator); } else { - sortOutOfPlace(); + sortOutOfPlace(length, nullFraction, vectorGenerator, dataGenerator); } } - void sortInPlace() { + void sortInPlace(int length, double nullFraction, Function vectorGenerator, + TestSortingUtil.DataGenerator dataGenerator) { try (V vector = vectorGenerator.apply(allocator)) { U[] array = dataGenerator.populate(vector, length, nullFraction); TestSortingUtil.sortArray(array); @@ -102,7 +85,8 @@ void sortInPlace() { } } - void sortOutOfPlace() { + void sortOutOfPlace(int length, double nullFraction, Function vectorGenerator, + TestSortingUtil.DataGenerator dataGenerator) { try (V vector = vectorGenerator.apply(allocator)) { U[] array = dataGenerator.populate(vector, length, nullFraction); TestSortingUtil.sortArray(array); @@ -123,50 +107,49 @@ void sortOutOfPlace() { } } - @Parameterized.Parameters(name = "length = {0}, null fraction = {1}, in place = {2}, vector = {3}") - public static Collection getParameters() { - List params = new ArrayList<>(); + static Stream getParameters() { + List params = new ArrayList<>(); for (int length : VECTOR_LENGTHS) { for (double nullFrac : NULL_FRACTIONS) { for (boolean inPlace : new boolean[] {true, false}) { - params.add(new Object[] { - length, nullFrac, inPlace, "TinyIntVector", + params.add(Arguments.of( + inPlace, length, nullFrac, "TinyIntVector", (Function) allocator -> new TinyIntVector("vector", allocator), TestSortingUtil.TINY_INT_GENERATOR - }); + )); - params.add(new Object[] { - length, nullFrac, inPlace, "SmallIntVector", + params.add(Arguments.of( + inPlace, length, nullFrac, "SmallIntVector", (Function) allocator -> new SmallIntVector("vector", allocator), TestSortingUtil.SMALL_INT_GENERATOR - }); + )); - params.add(new Object[] { - length, nullFrac, inPlace, "IntVector", + params.add(Arguments.of( + inPlace, length, nullFrac, "IntVector", (Function) allocator -> new IntVector("vector", allocator), TestSortingUtil.INT_GENERATOR - }); + )); - params.add(new Object[] { - length, nullFrac, inPlace, "BigIntVector", + params.add(Arguments.of( + inPlace, length, nullFrac, "BigIntVector", (Function) allocator -> new BigIntVector("vector", allocator), TestSortingUtil.LONG_GENERATOR - }); + )); - params.add(new Object[] { - length, nullFrac, inPlace, "Float4Vector", + params.add(Arguments.of( + inPlace, length, nullFrac, "Float4Vector", (Function) allocator -> new Float4Vector("vector", allocator), TestSortingUtil.FLOAT_GENERATOR - }); + )); - params.add(new Object[] { - length, nullFrac, inPlace, "Float8Vector", + params.add(Arguments.of( + inPlace, length, nullFrac, "Float8Vector", (Function) allocator -> new Float8Vector("vector", allocator), TestSortingUtil.DOUBLE_GENERATOR - }); + )); } } } - return params; + return params.stream(); } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestOutOfPlaceVectorSorter.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestOutOfPlaceVectorSorter.java index 66b75cbccac3e..09aeb9300c2a3 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestOutOfPlaceVectorSorter.java @@ -17,30 +17,25 @@ package org.apache.arrow.algorithm.sort; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.stream.Stream; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.provider.Arguments; /** * Test cases for out-of-place sorters. */ -@RunWith(Parameterized.class) public abstract class TestOutOfPlaceVectorSorter { - protected final boolean generalSorter; + protected boolean generalSorter; - public TestOutOfPlaceVectorSorter(boolean generalSorter) { + protected void setup(boolean generalSorter) { this.generalSorter = generalSorter; } - @Parameterized.Parameters(name = "general sorter = {0}") - public static Collection getParameter() { - List params = new ArrayList<>(); - params.add(new Object[] {true}); - params.add(new Object[] {false}); - return params; + static Stream getParameters() { + return Stream.of( + Arguments.of(true), + Arguments.of(false) + ); } } diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java index 34ac09d2369c8..1cb54678a265b 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthOutOfPlaceVectorSorter.java @@ -29,7 +29,8 @@ import org.apache.arrow.vector.VarCharVector; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; /** * Test cases for {@link VariableWidthOutOfPlaceVectorSorter}. @@ -38,15 +39,10 @@ public class TestVariableWidthOutOfPlaceVectorSorter extends TestOutOfPlaceVecto private BufferAllocator allocator; - public TestVariableWidthOutOfPlaceVectorSorter(boolean generalSorter) { - super(generalSorter); - } - OutOfPlaceVectorSorter getSorter() { return generalSorter ? new GeneralOutOfPlaceVectorSorter<>() : new VariableWidthOutOfPlaceVectorSorter(); } - @BeforeEach public void prepare() { allocator = new RootAllocator(1024 * 1024); @@ -57,8 +53,10 @@ public void shutdown() { allocator.close(); } - @Test - public void testSortString() { + @ParameterizedTest + @MethodSource("getParameters") + public void testSortString(boolean generalSorter) { + setup(generalSorter); try (VarCharVector vec = new VarCharVector("", allocator)) { vec.allocateNew(100, 10); vec.setValueCount(10); @@ -78,10 +76,10 @@ public void testSortString() { // sort the vector OutOfPlaceVectorSorter sorter = getSorter(); VectorValueComparator comparator = - DefaultVectorComparators.createDefaultComparator(vec); + DefaultVectorComparators.createDefaultComparator(vec); VarCharVector sortedVec = - (VarCharVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); + (VarCharVector) vec.getField().getFieldType().createNewSingleVector("", allocator, null); sortedVec.allocateNew(vec.getByteCapacity(), vec.getValueCount()); sortedVec.setLastSet(vec.getValueCount() - 1); sortedVec.setValueCount(vec.getValueCount()); diff --git a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java index 8ab8c2bd5b135..0047e47ad1f48 100644 --- a/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java +++ b/java/algorithm/src/test/java/org/apache/arrow/algorithm/sort/TestVariableWidthSorting.java @@ -24,10 +24,10 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.Comparator; import java.util.List; import java.util.function.Function; +import java.util.stream.Stream; import org.apache.arrow.memory.BufferAllocator; import org.apache.arrow.memory.RootAllocator; @@ -37,28 +37,19 @@ import org.apache.arrow.vector.util.Text; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test sorting variable width vectors with random data. */ -@RunWith(Parameterized.class) public class TestVariableWidthSorting> { static final int[] VECTOR_LENGTHS = new int[] {2, 5, 10, 50, 100, 1000, 3000}; static final double[] NULL_FRACTIONS = {0, 0.1, 0.3, 0.5, 0.7, 0.9, 1}; - private final int length; - - private final double nullFraction; - - private final Function vectorGenerator; - - private final TestSortingUtil.DataGenerator dataGenerator; - private BufferAllocator allocator; @BeforeEach @@ -71,21 +62,15 @@ public void shutdown() { allocator.close(); } - public TestVariableWidthSorting( - int length, double nullFraction, String desc, - Function vectorGenerator, TestSortingUtil.DataGenerator dataGenerator) { - this.length = length; - this.nullFraction = nullFraction; - this.vectorGenerator = vectorGenerator; - this.dataGenerator = dataGenerator; - } - - @Test - public void testSort() { - sortOutOfPlace(); + @ParameterizedTest(name = "length = {0}, null fraction = {1}, desc = {2}, vector = {3}") + @MethodSource("getParameters") + public void testSort(int length, double nullFraction, String desc, Function vectorGenerator, + TestSortingUtil.DataGenerator dataGenerator) { + sortOutOfPlace(length, nullFraction, vectorGenerator, dataGenerator); } - void sortOutOfPlace() { + void sortOutOfPlace(int length, double nullFraction, Function vectorGenerator, + TestSortingUtil.DataGenerator dataGenerator) { try (V vector = vectorGenerator.apply(allocator)) { U[] array = dataGenerator.populate(vector, length, nullFraction); Arrays.sort(array, (Comparator) new StringComparator()); @@ -107,19 +92,17 @@ void sortOutOfPlace() { } } - @Parameterized.Parameters(name = "length = {0}, null fraction = {1}, vector = {2}") - public static Collection getParameters() { - List params = new ArrayList<>(); + public static Stream getParameters() { + List params = new ArrayList<>(); for (int length : VECTOR_LENGTHS) { for (double nullFrac : NULL_FRACTIONS) { - params.add(new Object[]{ + params.add(Arguments.of( length, nullFrac, "VarCharVector", (Function) allocator -> new VarCharVector("vector", allocator), - TestSortingUtil.STRING_GENERATOR - }); + TestSortingUtil.STRING_GENERATOR)); } } - return params; + return params.stream(); } /**