Skip to content

Commit

Permalink
jqwik update.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimY4 committed Sep 2, 2023
1 parent 9eb6335 commit 5b93229
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 56 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ lazy val jqwik = (project in file("jqwik"))
description := "JQwik bindings for coregex library.",
headerEndYear := Some(2023),
libraryDependencies ++= Seq(
"net.jqwik" % "jqwik-api" % "1.7.4" % Provided,
"net.jqwik" % "jqwik-engine" % "1.7.4" % Test,
"net.jqwik" % "jqwik-testing" % "1.7.4" % Test,
"net.jqwik" % "jqwik-api" % "1.8.0" % Provided,
"net.jqwik" % "jqwik-engine" % "1.8.0" % Test,
"net.jqwik" % "jqwik-testing" % "1.8.0" % Test,
"net.aichler" % "jupiter-interface" % "0.11.1" % Test
),
Test / parallelExecution := false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import net.jqwik.api.Arbitraries;
import net.jqwik.api.Arbitrary;
import net.jqwik.api.EdgeCases;
import net.jqwik.api.RandomGenerator;
import net.jqwik.api.Shrinkable;
import net.jqwik.api.arbitraries.ArbitraryDecorator;

public class CoregexArbitrary extends ArbitraryDecorator<String> {
Expand All @@ -51,7 +47,14 @@ public CoregexArbitrary(Pattern pattern) {

@Override
protected Arbitrary<String> arbitrary() {
return new SizedArbitrary(pattern, edgeCases, sized);
Arbitrary<String> arbitrary =
-1 == sized
? Arbitraries.fromGeneratorWithSize(size -> new CoregexGenerator(pattern, size))
: Arbitraries.fromGenerator(new CoregexGenerator(pattern, sized));
if (!edgeCases.isEmpty()) {
arbitrary = arbitrary.edgeCases(config -> config.add(edgeCases.toArray(new String[0])));
}
return arbitrary;
}

public CoregexArbitrary withSize(int size) {
Expand Down Expand Up @@ -89,50 +92,3 @@ public int hashCode() {
return Objects.hash(pattern.flags(), pattern.pattern(), edgeCases, sized);
}
}

final class SizedArbitrary implements Arbitrary<String> {
private final Pattern pattern;
private final Set<String> edgeCases;
private final int size;

SizedArbitrary(Pattern pattern, Set<String> edgeCases, int size) {
this.pattern = pattern;
this.edgeCases = edgeCases;
this.size = size;
}

@Override
public RandomGenerator<String> generator(int genSize) {
int size = this.size;
size = -1 == size ? genSize : size;
return new CoregexGenerator(pattern, size);
}

@Override
public EdgeCases<String> edgeCases(int maxEdgeCases) {
return EdgeCases.fromSuppliers(
edgeCases.stream()
.<Supplier<Shrinkable<String>>>map(edgeCase -> () -> Shrinkable.unshrinkable(edgeCase))
.collect(Collectors.toList()));
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SizedArbitrary that = (SizedArbitrary) o;
return size == that.size
&& pattern.flags() == that.pattern.flags()
&& pattern.pattern().equals(that.pattern.pattern())
&& edgeCases.equals(that.edgeCases);
}

@Override
public int hashCode() {
return Objects.hash(pattern.flags(), pattern.pattern(), edgeCases, size);
}
}

0 comments on commit 5b93229

Please sign in to comment.