
smallcheck.generators.ListGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-smallcheck Show documentation
Show all versions of java-smallcheck Show documentation
An implementation of SmallCheck for Java as a JUnit extension.
The newest version!
package smallcheck.generators;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*
*/
public class ListGen extends SeriesGen> {
private SeriesGen elementGen;
public ListGen(SeriesGen elementGen) {
super();
this.elementGen = elementGen;
}
@Override
public Stream> generate(int depth) {
if (depth == 0) {
return Stream.of(Collections.emptyList());
}
return generate(depth - 1).flatMap(l -> {
return Stream.concat(
Stream.of(l),
elementGen.generate(depth - 1).map(e -> {
List res = new ArrayList<>(depth);
res.add(e);
for (T t : l) {
res.add(elementGen.copy(t));
}
return res;
})
);
});
}
@Override
public List copy(List obj) {
return obj.stream()
.map(elementGen::copy)
.collect(Collectors.toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy