Introduce DoubleListProvider

This commit is contained in:
2021-08-29 22:22:52 +02:00
parent 9a23fc4b27
commit 4600194a9f
3 changed files with 30 additions and 10 deletions

View File

@ -0,0 +1,19 @@
package aud.exam.prep;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import java.util.stream.Stream;
public class DoubleListProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream
.generate(() ->
Arguments.of(Tests.randomList(), Tests.randomList()))
.limit(Tests.STEAM_SIZE);
}
}

View File

@ -4,8 +4,6 @@ import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class ListProvider implements ArgumentsProvider {
@ -13,16 +11,9 @@ public class ListProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext extensionContext) {
return Stream
.generate(this::randomList)
.generate(Tests::randomList)
.map(Arguments::of)
.limit(Tests.STEAM_SIZE);
}
private List<Integer> randomList() {
var size = Tests.RANDOM.nextInt(50);
return Tests.RANDOM
.ints(size, 0, 100)
.boxed()
.collect(Collectors.toList());
}
}

View File

@ -1,10 +1,20 @@
package aud.exam.prep;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
public class Tests {
public static final int STEAM_SIZE = 50;
public static final Random RANDOM = new Random();
static List<Integer> randomList() {
var size = RANDOM.nextInt(50);
return RANDOM
.ints(size, 0, 100)
.boxed()
.collect(Collectors.toList());
}
}