Skip to content

Commit

Permalink
Merge pull request #10 from mihxil/fixing-for-new-jqwik
Browse files Browse the repository at this point in the history
Fixing for new jqwik
  • Loading branch information
mihxil authored Oct 19, 2024
2 parents 8cc0e04 + 32347d1 commit 779dc11
Show file tree
Hide file tree
Showing 26 changed files with 192 additions and 131 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: build pull request
run-name: build pull request ${{ github.ref_name }}
on:
pull_request:
branches: [main]
workflow_dispatch:


jobs:
build:
runs-on: ubuntu-latest
env:
MAVEN_OPTS: -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
steps:
- name: Cancel previous Action
uses: styfle/[email protected]
continue-on-error: true # for act
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
cache: 'maven'
- name: Build with Maven
run: |
mvn -B -Dchangelist=.${GITHUB_HEAD_REF##*/}-SNAPSHOT -P"npm" -U -fae package
- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
if: (success() || failure())
with:
junit_files: "**/target/surefire-reports/*.xml"
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void conjugateOfProductIsProductOfConjugates(@ForAll(ELEMENTS) Quaternion
}

@Property
public void elementClass(@ForAll(ELEMENT) Quaternion<RationalNumber> e) {
public void elementClass(@ForAll(ELEMENTS) Quaternion<RationalNumber> e) {
assertThat(e.getStructure().getElementStructure()).isEqualTo(e.getA().getStructure());
assertThat(e.getStructure().getElementStructure()).isEqualTo(e.getB().getStructure());
assertThat(e.getStructure().getElementStructure()).isEqualTo(e.getC().getStructure());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void determinant2() {
public void errorPropagation(
@ForAll("bigdecimals") final BigDecimal r1,
@ForAll("bigdecimals") final BigDecimal r2,
@ForAll("operators") final BasicAlgebraicBinaryOperator operator) {
@ForAll("operators") final AlgebraicBinaryOperator operator) {

withAspect(UncertaintyConfiguration.class,
(nc) -> nc.withConsiderRoundingErrorFactor(0), () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public class TrivialRingTest implements RingTheory<TrivialRingElement> {
@Override
public Arbitrary<? extends TrivialRingElement> elements() {
public Arbitrary<TrivialRingElement> elements() {
return Arbitraries.of(TrivialRingElement.e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class UncertainNumberTest implements ElementTheory<UncertainNumberTest.A> {


@Override
public boolean equals(UncertainNumberTest.A e1, UncertainNumberTest.A e2) {
return e1.eq(e2, 1);
public boolean equals(Object e1, Object e2) {
return ((UncertainNumberTest.A) e1).eq((UncertainNumberTest.A) e2, 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public int compareTo(A o) {
}

@Override
public Arbitrary<? extends A> datapoints() {
public Arbitrary<Object> datapoints() {
return Arbitraries.integers().map(A::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.*;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -245,7 +246,7 @@ public void infiniteStreamSplit(int dim) {
() -> Stream.iterate(1, i -> i + 2).spliterator();
CartesianSpliterator<Integer> cartesianSpliterator =
new CartesianSpliterator<>(iterate, dim);
final List<Integer[]> result = new ArrayList<>();
final List<Integer[]> result = new CopyOnWriteArrayList<>();
assertThat(cartesianSpliterator.estimateSize()).isEqualTo(Long.MAX_VALUE);
StreamSupport.stream(cartesianSpliterator, true).limit(100).forEach(a -> {
log.info("{} ({})", Arrays.asList(a), Thread.currentThread().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
class UnitExponentTest implements ComparableTheory<UnitExponent> {

@Override
public Arbitrary<? extends UnitExponent> datapoints() {
public Arbitrary<Object> datapoints() {
IntegerArbitrary unit = Arbitraries.integers()
.between(0, SIUnit.values().length - 1);
IntegerArbitrary exponent = Arbitraries.integers()
.between(-5, 5);
return Combinators.combine(
unit, exponent
).as((u, e) -> new UnitExponent(SIUnit.values()[u], e))
.injectDuplicates(0.2);
.injectDuplicates(0.2).asGeneric();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.jqwik.api.*;
import org.junit.jupiter.api.Test;

import org.meeuw.math.abstractalgebra.AlgebraicElement;
import org.meeuw.theories.abstractalgebra.CompleteScalarFieldTheory;
import org.meeuw.theories.abstractalgebra.UncertainDoubleTheory;
import org.meeuw.math.exceptions.DivisionByZeroException;
Expand Down Expand Up @@ -134,8 +135,9 @@ public void reset() {
}

@Property
public void testString(@ForAll(ELEMENTS) StatisticalDoubleImpl e) {
log.info("{} {}", e.getCount(), e);
public void testString(@ForAll(ELEMENTS) AlgebraicElement<?> e) {
StatisticalDoubleImpl casted = (StatisticalDoubleImpl) e;
log.info("{} {}", casted.getCount(), e);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public interface BasicObjectTheory<E> {
*/
@SuppressWarnings("EqualsWithItself")
@Property
default void equalsIsReflexive(@ForAll(DATAPOINTS) E x) {
default void equalsIsReflexive(@ForAll(DATAPOINTS) Object x) {
//System.out.println("reflexive " + x);
assertThat(x.equals(x)).isTrue();
}
Expand All @@ -43,7 +43,7 @@ default void equalsIsReflexive(@ForAll(DATAPOINTS) E x) {
* should return true if and only if y.equals(x) returns true.
*/
@Property
default void equalsIsSymmetric(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS) E y) {
default void equalsIsSymmetric(@ForAll(DATAPOINTS) Object x, @ForAll(DATAPOINTS) Object y) {
//System.out.println("symetric = " + x + " " + y);
assertThat(x.equals(y)).isEqualTo(y.equals(x));
}
Expand All @@ -55,8 +55,8 @@ default void equalsIsSymmetric(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS) E y)
*/
@Property
default void equalsIsTransitive(
@ForAll(EQUAL_DATAPOINTS) Tuple2<E, E> p1,
@ForAll(EQUAL_DATAPOINTS) Tuple2<E, E> p2) {
@ForAll(EQUAL_DATAPOINTS) Tuple2<Object, Object> p1,
@ForAll(EQUAL_DATAPOINTS) Tuple2<Object, Object> p2) {
//System.out.println("transitive = " + p1 + " " + p2);
assertThat(p1.get1().equals(p2.get2())).isEqualTo(p1.get2().equals(p2.get1()));
}
Expand All @@ -68,7 +68,7 @@ default void equalsIsTransitive(
* the objects is modified.
*/
@Property
default void equalsIsConsistent(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS_OR_NULL) E y) {
default void equalsIsConsistent(@ForAll(DATAPOINTS) Object x, @ForAll(DATAPOINTS_OR_NULL) Object y) {
boolean alwaysTheSame = x.equals(y);

for (int i = 0; i < 30; i++) {
Expand All @@ -82,7 +82,7 @@ default void equalsIsConsistent(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS_OR_N
*/
@SuppressWarnings("ConstantConditions")
@Property
default void equalsReturnFalseOnNull(@ForAll(DATAPOINTS) E x) {
default void equalsReturnFalseOnNull(@ForAll(DATAPOINTS) Object x) {
assertThat(x.equals(null)).isFalse();
}

Expand All @@ -92,7 +92,7 @@ default void equalsReturnFalseOnNull(@ForAll(DATAPOINTS) E x) {
*/
@SuppressWarnings("ConstantConditions")
@Property
default void equalsReturnFalseOnOtherObject(@ForAll(DATAPOINTS) E x) {
default void equalsReturnFalseOnOtherObject(@ForAll(DATAPOINTS) Object x) {
assertThat(x.equals(new Object())).isFalse();
}

Expand All @@ -102,7 +102,7 @@ default void equalsReturnFalseOnOtherObject(@ForAll(DATAPOINTS) E x) {
* integer.
*/
@Property
default void hashCodeIsSelfConsistent(@ForAll(DATAPOINTS) E x) {
default void hashCodeIsSelfConsistent(@ForAll(DATAPOINTS) Object x) {
int alwaysTheSame = x.hashCode();

for (int i = 0; i < 30; i++) {
Expand All @@ -116,7 +116,7 @@ default void hashCodeIsSelfConsistent(@ForAll(DATAPOINTS) E x) {
* must produce the same integer result.
*/
@Property
default void hashCodeIsConsistentWithEquals(@ForAll(EQUAL_DATAPOINTS) Tuple2<E, E> pair) {
default void hashCodeIsConsistentWithEquals(@ForAll(EQUAL_DATAPOINTS) Tuple2<Object, Object> pair) {
//System.out.println("hashCode consistent = " + pair + " " + pair.get1().hashCode());
assertThat(pair.get1().hashCode()).isEqualTo(pair.get2().hashCode());
}
Expand All @@ -126,7 +126,7 @@ default void hashCodeIsConsistentWithEquals(@ForAll(EQUAL_DATAPOINTS) Tuple2<E,
*/
@SuppressWarnings("ResultOfMethodCallIgnored")
@Property
default void toString(@ForAll(DATAPOINTS) E object) {
default void toString(@ForAll(DATAPOINTS) Object object) {
assertThatNoException().isThrownBy(object::toString);
}

Expand All @@ -135,27 +135,27 @@ default void toString(@ForAll(DATAPOINTS) E object) {
* Provide non-{@code null} datapoints
*/
@Provide
Arbitrary<@NonNull ? extends E> datapoints();
Arbitrary<@NonNull Object> datapoints();


/**
* The implementation for equals datapoints (see {@link #equalDatapoints()}.
* Defaults to {@link Objects#equals(Object, Object)}.
*/
default boolean equals(E e1, E e2) {
default boolean equals(Object e1, Object e2) {
return Objects.equals(e1, e2);
}

@Provide
default Arbitrary<@NonNull? extends Tuple2<@NonNull? extends E, @NonNull? extends E>> equalDatapoints() {
List<? extends E> samples = datapoints()
default Arbitrary<@NonNull? extends Tuple2<@NonNull Object, @NonNull Object>> equalDatapoints() {
List<Object> samples = datapoints()
.injectDuplicates(0.5)
.sampleStream()
.limit(1000)
.collect(Collectors.toList());
final java.util.Set<Tuple2<? extends E, ? extends E>> setToReturn = new HashSet<>();
final List<E> check = new ArrayList<>();
for (E e : samples) {
final java.util.Set<Tuple2<Object, Object>> setToReturn = new HashSet<>();
final List<Object> check = new ArrayList<>();
for (Object e : samples) {
int i = -1;
for (int j = 0; j < check.size(); j++) {
if (equals(check.get(j), e)) {
Expand All @@ -173,7 +173,7 @@ default boolean equals(E e1, E e2) {
}

@Provide
default Arbitrary<@Nullable ? extends E> datapointsOrNull() {
default Arbitrary<@Nullable Object> datapointsOrNull() {
return datapoints()
.injectNull(0.1);
}
Expand Down
Loading

0 comments on commit 779dc11

Please sign in to comment.