diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..9848929e --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -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/cancel-workflow-action@0.12.1 + 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/publish-unit-test-result-action@v2.12.0 + if: (success() || failure()) + with: + junit_files: "**/target/surefire-reports/*.xml" diff --git a/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/quaternions/QuaternionTest.java b/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/quaternions/QuaternionTest.java index e95b9bfa..b28ef6e5 100644 --- a/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/quaternions/QuaternionTest.java +++ b/mihxil-algebra/src/test/java/org/meeuw/test/math/abstractalgebra/quaternions/QuaternionTest.java @@ -76,7 +76,7 @@ public void conjugateOfProductIsProductOfConjugates(@ForAll(ELEMENTS) Quaternion } @Property - public void elementClass(@ForAll(ELEMENT) Quaternion e) { + public void elementClass(@ForAll(ELEMENTS) Quaternion 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()); diff --git a/mihxil-algebra/src/test/java/org/meeuw/test/math/uncertainnumbers/UncertainRealFieldFieldTest.java b/mihxil-algebra/src/test/java/org/meeuw/test/math/uncertainnumbers/UncertainRealFieldFieldTest.java index d587030f..f0940c05 100644 --- a/mihxil-algebra/src/test/java/org/meeuw/test/math/uncertainnumbers/UncertainRealFieldFieldTest.java +++ b/mihxil-algebra/src/test/java/org/meeuw/test/math/uncertainnumbers/UncertainRealFieldFieldTest.java @@ -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), () -> { diff --git a/mihxil-math-test/src/test/java/org/meeuw/math/abstractalgebra/TrivialRingTest.java b/mihxil-math-test/src/test/java/org/meeuw/math/abstractalgebra/TrivialRingTest.java index 19dfafa6..6f8b3716 100644 --- a/mihxil-math-test/src/test/java/org/meeuw/math/abstractalgebra/TrivialRingTest.java +++ b/mihxil-math-test/src/test/java/org/meeuw/math/abstractalgebra/TrivialRingTest.java @@ -22,7 +22,7 @@ public class TrivialRingTest implements RingTheory { @Override - public Arbitrary elements() { + public Arbitrary elements() { return Arbitraries.of(TrivialRingElement.e); } } diff --git a/mihxil-math-test/src/test/java/org/meeuw/math/uncertainnumbers/UncertainNumberTest.java b/mihxil-math-test/src/test/java/org/meeuw/math/uncertainnumbers/UncertainNumberTest.java index 882ae702..9c8ad5a1 100644 --- a/mihxil-math-test/src/test/java/org/meeuw/math/uncertainnumbers/UncertainNumberTest.java +++ b/mihxil-math-test/src/test/java/org/meeuw/math/uncertainnumbers/UncertainNumberTest.java @@ -38,8 +38,8 @@ class UncertainNumberTest implements ElementTheory { @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 diff --git a/mihxil-math-test/src/test/java/org/meeuw/util/test/test/BasicObjectTheoryTest.java b/mihxil-math-test/src/test/java/org/meeuw/util/test/test/BasicObjectTheoryTest.java index c63b5ee7..ced03e5a 100644 --- a/mihxil-math-test/src/test/java/org/meeuw/util/test/test/BasicObjectTheoryTest.java +++ b/mihxil-math-test/src/test/java/org/meeuw/util/test/test/BasicObjectTheoryTest.java @@ -32,7 +32,7 @@ public int compareTo(A o) { } @Override - public Arbitrary datapoints() { + public Arbitrary datapoints() { return Arbitraries.integers().map(A::new); } diff --git a/mihxil-math/src/test/java/org/meeuw/test/math/streams/CartesianSpliteratorTest.java b/mihxil-math/src/test/java/org/meeuw/test/math/streams/CartesianSpliteratorTest.java index fc9bb11a..01c76147 100644 --- a/mihxil-math/src/test/java/org/meeuw/test/math/streams/CartesianSpliteratorTest.java +++ b/mihxil-math/src/test/java/org/meeuw/test/math/streams/CartesianSpliteratorTest.java @@ -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; @@ -245,7 +246,7 @@ public void infiniteStreamSplit(int dim) { () -> Stream.iterate(1, i -> i + 2).spliterator(); CartesianSpliterator cartesianSpliterator = new CartesianSpliterator<>(iterate, dim); - final List result = new ArrayList<>(); + final List 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()); diff --git a/mihxil-physics/src/test/java/org/meeuw/physics/UnitExponentTest.java b/mihxil-physics/src/test/java/org/meeuw/physics/UnitExponentTest.java index e8a5e0c5..cb297d3f 100644 --- a/mihxil-physics/src/test/java/org/meeuw/physics/UnitExponentTest.java +++ b/mihxil-physics/src/test/java/org/meeuw/physics/UnitExponentTest.java @@ -30,7 +30,7 @@ class UnitExponentTest implements ComparableTheory { @Override - public Arbitrary datapoints() { + public Arbitrary datapoints() { IntegerArbitrary unit = Arbitraries.integers() .between(0, SIUnit.values().length - 1); IntegerArbitrary exponent = Arbitraries.integers() @@ -38,7 +38,7 @@ public Arbitrary datapoints() { return Combinators.combine( unit, exponent ).as((u, e) -> new UnitExponent(SIUnit.values()[u], e)) - .injectDuplicates(0.2); + .injectDuplicates(0.2).asGeneric(); } @Test diff --git a/mihxil-statistics/src/test/java/org/meeuw/math/statistics/StatisticalDoubleTest.java b/mihxil-statistics/src/test/java/org/meeuw/math/statistics/StatisticalDoubleTest.java index f7a24ba7..ec1b870d 100644 --- a/mihxil-statistics/src/test/java/org/meeuw/math/statistics/StatisticalDoubleTest.java +++ b/mihxil-statistics/src/test/java/org/meeuw/math/statistics/StatisticalDoubleTest.java @@ -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; @@ -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 diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/BasicObjectTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/BasicObjectTheory.java index 74e70007..fdc0cc10 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/BasicObjectTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/BasicObjectTheory.java @@ -33,7 +33,7 @@ public interface BasicObjectTheory { */ @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(); } @@ -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)); } @@ -55,8 +55,8 @@ default void equalsIsSymmetric(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS) E y) */ @Property default void equalsIsTransitive( - @ForAll(EQUAL_DATAPOINTS) Tuple2 p1, - @ForAll(EQUAL_DATAPOINTS) Tuple2 p2) { + @ForAll(EQUAL_DATAPOINTS) Tuple2 p1, + @ForAll(EQUAL_DATAPOINTS) Tuple2 p2) { //System.out.println("transitive = " + p1 + " " + p2); assertThat(p1.get1().equals(p2.get2())).isEqualTo(p1.get2().equals(p2.get1())); } @@ -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++) { @@ -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(); } @@ -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(); } @@ -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++) { @@ -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 pair) { + default void hashCodeIsConsistentWithEquals(@ForAll(EQUAL_DATAPOINTS) Tuple2 pair) { //System.out.println("hashCode consistent = " + pair + " " + pair.get1().hashCode()); assertThat(pair.get1().hashCode()).isEqualTo(pair.get2().hashCode()); } @@ -126,7 +126,7 @@ default void hashCodeIsConsistentWithEquals(@ForAll(EQUAL_DATAPOINTS) Tuple2 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 samples = datapoints() + default Arbitrary<@NonNull? extends Tuple2<@NonNull Object, @NonNull Object>> equalDatapoints() { + List samples = datapoints() .injectDuplicates(0.5) .sampleStream() .limit(1000) .collect(Collectors.toList()); - final java.util.Set> setToReturn = new HashSet<>(); - final List check = new ArrayList<>(); - for (E e : samples) { + final java.util.Set> setToReturn = new HashSet<>(); + final List check = new ArrayList<>(); + for (Object e : samples) { int i = -1; for (int j = 0; j < check.size(); j++) { if (equals(check.get(j), e)) { @@ -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); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/ComparableTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/ComparableTheory.java index 69596c0a..229ea4b3 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/ComparableTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/ComparableTheory.java @@ -1,5 +1,7 @@ package org.meeuw.theories; +import lombok.NonNull; + import java.util.*; import java.util.stream.Collectors; @@ -7,7 +9,6 @@ import net.jqwik.api.Tuple.Tuple2; import net.jqwik.api.Tuple.Tuple3; -import org.checkerframework.checker.nullness.qual.NonNull; import org.meeuw.math.exceptions.NotComparableException; import org.opentest4j.TestAbortedException; @@ -19,7 +20,7 @@ * Tests basic properties for {@link Comparable} objects. *
    *
  • Normally, {@link #equalsConsistentWithComparable(Tuple2) equals must be consistent with comparable}
  • - *
  • {@link #compareToNull(Comparable) comparing to null should raise NullPointerException}
  • + *
  • {@link #compareToNull(Object) comparing to null should raise NullPointerException}
  • *
  • {@link #compareToIsAntiCommutative(Comparable, Comparable) compare to is anti-commutative}
  • *
  • {@code compareTo} is also transitive ({@link #compareToIsTransitiveBigger}, {@link #compareToIsTransitiveSmaller}, {@link #compareToIsTransitiveEquals})
  • * @author Michiel Meeuwissen @@ -32,9 +33,11 @@ public interface ComparableTheory> extends BasicObjectTh * TODO: This is not an absolute requirement, in some cases you may want to compareTo to zero even if two objects are not exactly equal. */ @Property(maxDiscardRatio = 10000) - default void equalsConsistentWithComparable(@ForAll(EQUAL_DATAPOINTS) Tuple2 pair) { + default void equalsConsistentWithComparable(@ForAll(EQUAL_DATAPOINTS) Tuple2 pair) { try { - assertThat(pair.get1().compareTo(pair.get2())).isEqualTo(0); + E e1 = (E) pair.get1(); + E e2 = (E) pair.get2(); + assertThat(e1.compareTo(e2)).isEqualTo(0); } catch (ClassCastException | NotComparableException exception) { throw new TestAbortedException(); } @@ -42,7 +45,8 @@ default void equalsConsistentWithComparable(@ForAll(EQUAL_DATAPOINTS) Tuple2 x = (Comparable) o; assertThatThrownBy(() -> x.compareTo(null)).isInstanceOf(NullPointerException.class); } @@ -50,7 +54,9 @@ default void compareToNull(@ForAll(DATAPOINTS) E x) { * The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. */ @Property - default void compareToIsAntiCommutative(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOINTS) E y) { + default void compareToIsAntiCommutative(@ForAll(DATAPOINTS) Object ox, @ForAll(DATAPOINTS) Object oy) { + E x = (E) ox; + E y = (E) oy; try { assertThat(signum(x.compareTo(y))).isEqualTo(-1 * signum(y.compareTo(x))); } catch (ClassCastException | NotComparableException exception) { @@ -63,9 +69,12 @@ default void compareToIsAntiCommutative(@ForAll(DATAPOINTS) E x, @ForAll(DATAPOI */ @Property(maxDiscardRatio = 1000) default void compareToIsTransitiveBigger( - @ForAll(DATAPOINTS) E x, - @ForAll(DATAPOINTS) E y, - @ForAll(DATAPOINTS) E z) { + @ForAll(DATAPOINTS) Object ox, + @ForAll(DATAPOINTS) Object oy, + @ForAll(DATAPOINTS) Object oz) { + E x = (E) ox; + E y = (E) oy; + E z = (E) oz; try { Assume.that(x.compareTo(y) > 0); @@ -83,10 +92,15 @@ default void compareToIsTransitiveBigger( */ @Property(maxDiscardRatio = 1000) default void compareToIsTransitiveSmaller( - @ForAll(DATAPOINTS) E x, - @ForAll(DATAPOINTS) E y, - @ForAll(DATAPOINTS) E z) { + @ForAll(DATAPOINTS) Object ox, + @ForAll(DATAPOINTS) Object oy, + @ForAll(DATAPOINTS) Object oz) { + E x = (E) ox; + E y = (E) oy; + E z = (E) oz; try { + + Assume.that(x.compareTo(y) < 0); Assume.that(y.compareTo(z) < 0); @@ -101,28 +115,32 @@ default void compareToIsTransitiveSmaller( */ @Property default void compareToIsTransitiveEquals( - @ForAll("compareToEqualsDatapoints3") Tuple3 tuple) { - assertThat(tuple.get1().compareTo(tuple.get2())).isEqualTo(0); - assertThat(tuple.get2().compareTo(tuple.get3())).isEqualTo(0); - assertThat(tuple.get1().compareTo(tuple.get3())).isEqualTo(0); + @ForAll("compareToEqualsDatapoints3") Tuple3 tuple) { + E t1 = (E) tuple.get1(); + E t2 = (E) tuple.get2(); + E t3 = (E) tuple.get3(); + assertThat(t1.compareTo(t2)).isEqualTo(0); + assertThat(t2.compareTo(t3)).isEqualTo(0); + assertThat(t1.compareTo(t3)).isEqualTo(0); } @Provide - default Arbitrary<@NonNull ? extends Tuple3<@NonNull ? extends E, @NonNull ? extends E, @NonNull ? extends E>> compareToEqualsDatapoints3() { - List samples = datapoints() + default Arbitrary<@NonNull Tuple3<@NonNull Object, @NonNull Object, @NonNull Object>> compareToEqualsDatapoints3() { + List samples = datapoints() .injectDuplicates(0.5) .sampleStream() .limit(5000) .collect(Collectors.toList()); - final List check = new ArrayList<>(); + final List check = new ArrayList<>(); final List> set2ToReturn = new ArrayList<>(); - final List> setToReturn = new ArrayList<>(); + final List> setToReturn = new ArrayList<>(); SAMPLES: - for (E sample : samples) { - Iterator i = check.iterator(); + for (Object sampleObject : samples) { + E sample = (E) sampleObject; + Iterator i = check.iterator(); while (i.hasNext()) { - E toCheck = i.next(); + E toCheck = (E) i.next(); try { if (toCheck.compareTo(sample) == 0) { @@ -154,7 +172,9 @@ default void compareToIsTransitiveEquals( check.add(sample); } - return Arbitraries.of(setToReturn); + return Arbitraries.of( setToReturn); } + + } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveAbelianSemiGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveAbelianSemiGroupTheory.java index 9eddbaa8..7247e9c6 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveAbelianSemiGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveAbelianSemiGroupTheory.java @@ -18,8 +18,7 @@ import net.jqwik.api.ForAll; import net.jqwik.api.Property; -import org.meeuw.math.abstractalgebra.AdditiveAbelianSemiGroup; -import org.meeuw.math.abstractalgebra.AdditiveSemiGroupElement; +import org.meeuw.math.abstractalgebra.*; import static org.assertj.core.api.Assertions.assertThat; @@ -39,8 +38,9 @@ default void additiveCommutativity ( @Property default void additiveCommutativityProperty( - @ForAll(STRUCTURE) AdditiveAbelianSemiGroup group) { - assertThat(group.additionIsCommutative()).isTrue(); + @ForAll(STRUCTURE) AlgebraicStructure group) { + AdditiveSemiGroup casted = (AdditiveSemiGroup) group; + assertThat(casted.additionIsCommutative()).isTrue(); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveGroupTheory.java index fad9cefc..d39e852f 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveGroupTheory.java @@ -18,12 +18,12 @@ import net.jqwik.api.ForAll; import net.jqwik.api.Property; -import org.meeuw.math.abstractalgebra.*; +import org.meeuw.math.abstractalgebra.AdditiveGroupElement; +import org.meeuw.math.abstractalgebra.AlgebraicStructure; +import org.meeuw.math.operators.BasicAlgebraicBinaryOperator; import static org.assertj.core.api.Assertions.assertThat; - import static org.meeuw.math.abstractalgebra.AlgebraicElement.eqComparator; -import org.meeuw.math.operators.BasicAlgebraicBinaryOperator; /** * @author Michiel Meeuwissen @@ -33,7 +33,7 @@ public interface AdditiveGroupTheory> extends AdditiveMonoidTheory { @Property - default void additiveGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { + default void additiveGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.ADDITION, BasicAlgebraicBinaryOperator.SUBTRACTION); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveSemiGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveSemiGroupTheory.java index e9c35c26..2ed1dfcd 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveSemiGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AdditiveSemiGroupTheory.java @@ -31,7 +31,7 @@ public interface AdditiveSemiGroupTheory> extends MagmaTheory { @Property - default void additiveSemiGroupOperators(@ForAll(STRUCTURE) AdditiveSemiGroup s) { + default void additiveSemiGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.ADDITION); } @@ -45,8 +45,9 @@ default void additiveAssociativity ( .isEqTo(v1.plus((v2.plus(v3)))); } @Property - default void additionCommutativity(@ForAll(STRUCTURE) AdditiveSemiGroup s) { - if (s.additionIsCommutative()) { + default void additionCommutativity(@ForAll(STRUCTURE) AlgebraicStructure s) { + AdditiveSemiGroup casted = (AdditiveSemiGroup) s; + if (casted.additionIsCommutative()) { assertThat(s).isInstanceOf(AdditiveAbelianSemiGroup.class); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AlgebraicStructureTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AlgebraicStructureTheory.java index 74d111b2..928f7a41 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AlgebraicStructureTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/AlgebraicStructureTheory.java @@ -17,6 +17,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicLong; import java.util.function.IntConsumer; @@ -43,14 +44,14 @@ public interface AlgebraicStructureTheory> extend String STRUCTURE = "structure"; @Provide - default Arbitrary> structure() { - return element().map(AlgebraicElement::getStructure); + default Arbitrary> structure() { + return Arbitraries.of(elements().filter(Objects::nonNull).sample().getStructure()); } @SuppressWarnings("unchecked") @Property() default void cardinalityAndStreaming( - @ForAll(STRUCTURE) AlgebraicStructure s) { + @ForAll(STRUCTURE) AlgebraicStructure s) { Logger log = getLogger(); @@ -71,19 +72,24 @@ default void cardinalityAndStreaming( } } ); - IntConsumer skipAndStream = (skip) -> + IntConsumer skipAndStream = (skip) -> { + Instant last = Instant.now(); streamAble.stream().skip(skip).limit(20).forEach(e -> { - if (count.get() < skip) { - count.set(skip); - log.info("Skipping to {}", skip); + if (count.get() < skip) { + count.set(skip); + log.info("Skipping to {}", skip); + } + count.incrementAndGet(); + log.info(e::toString); } - count.incrementAndGet(); - log.info(e::toString); - } ); - ; + }; + log.info("Skip to 5000"); skipAndStream.accept(5000); - skipAndStream.accept(1_000_000); + log.info("Skip to 100 000"); + skipAndStream.accept(100_000); + log.info("Skip to 500 000"); + skipAndStream.accept(500_000); } catch (NotStreamable ns) { log.warn(ns.getMessage()); @@ -98,7 +104,7 @@ default void cardinalityAndStreaming( } @Property - default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure s) { + default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure s) { Random random = new Random(); try { for (int i = 0; i < 10; i++) { @@ -110,15 +116,15 @@ default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure s) { } @Property - default void structureSameInstance(@ForAll(ELEMENTS) E e1, @ForAll(ELEMENT) E e2) { + default void structureSameInstance(@ForAll(ELEMENTS) AlgebraicElement e1, @ForAll(ELEMENTS) AlgebraicElement e2) { assertThat(e1.getStructure() == e2.getStructure()).isTrue(); assertThat(e1.getStructure().equals(e2.getStructure())).isTrue(); } @Property default void elementClass( - @ForAll(STRUCTURE) AlgebraicStructure s, - @ForAll(ELEMENTS) E e + @ForAll(STRUCTURE) AlgebraicStructure s, + @ForAll(ELEMENTS) AlgebraicElement e ) { assertThat(e).isInstanceOf(s.getElementClass()); } @@ -129,10 +135,12 @@ default void elementClass( @Property default void algebraicBinaryOperators( - @ForAll(STRUCTURE) AlgebraicStructure s, - @ForAll(ELEMENTS) E e1, - @ForAll(ELEMENTS) E e2) throws Throwable { + @ForAll(STRUCTURE) AlgebraicStructure s, + @ForAll(ELEMENTS) AlgebraicElement o1, + @ForAll(ELEMENTS) AlgebraicElement o2) throws Throwable { + E e1 = (E) o1; + E e2 = (E) o2; AtomicLong count = COUNTS.computeIfAbsent(s, k -> new AtomicLong(0)); AtomicLong error = ERROR_COUNTS.computeIfAbsent(s, k -> new AtomicLong(0)); int size = s.getSupportedOperators().size(); @@ -176,8 +184,9 @@ default void algebraicBinaryOperators( @Property default void algebraicUnaryOperators( - @ForAll(STRUCTURE) AlgebraicStructure s, - @ForAll(ELEMENTS) E e1) throws Throwable { + @ForAll(STRUCTURE) AlgebraicStructure s, + @ForAll(ELEMENTS) AlgebraicElement o1) throws Throwable { + E e1 = (E) o1; AtomicLong count = UCOUNTS.computeIfAbsent(s, k -> new AtomicLong(0)); AtomicLong countError = ERROR_UCOUNTS.computeIfAbsent(s, k -> new AtomicLong(0)); @@ -213,8 +222,8 @@ default void algebraicUnaryOperators( @Property default void functions( - @ForAll(STRUCTURE) AlgebraicStructure s, - @ForAll(ELEMENTS) E e1) throws Throwable { + @ForAll(STRUCTURE) AlgebraicStructure s, + @ForAll(ELEMENTS) AlgebraicElement e1) throws Throwable { for (GenericFunction o : s.getSupportedFunctions()) { try { @@ -237,7 +246,7 @@ default void functions( @Property - default void getComparisonOperators(@ForAll(STRUCTURE) AlgebraicStructure struct) { + default void getComparisonOperators(@ForAll(STRUCTURE) AlgebraicStructure struct) { if (Ordered.class.isAssignableFrom(struct.getElementClass())) { assertThat(struct.getSupportedComparisonOperators()) .contains(LT, LTE, GT, GTE); @@ -247,7 +256,7 @@ default void getComparisonOperators(@ForAll(STRUCTURE) AlgebraicStructure str @Property - default void examples(@ForAll(STRUCTURE) AlgebraicStructure struct) { + default void examples(@ForAll(STRUCTURE) AlgebraicStructure struct) { Example[] annotation = struct.getClass().getAnnotationsByType(Example.class); for (Example example : annotation) { assertThat(example.value()).isAssignableFrom(struct.getClass()); @@ -255,14 +264,14 @@ default void examples(@ForAll(STRUCTURE) AlgebraicStructure struct) { } @Property - default void toString(@ForAll(STRUCTURE) AlgebraicStructure struct) { + default void toString(@ForAll(STRUCTURE) AlgebraicStructure struct) { getLogger().info(struct.getClass().getSimpleName() + " -> " + struct); } @Property default void staticOperators( - @ForAll(STRUCTURE) AlgebraicStructure structure, + @ForAll(STRUCTURE) AlgebraicStructure structure, @ForAll BasicAlgebraicBinaryOperator o) { try { @@ -288,7 +297,7 @@ default void staticOperators( @Property default void staticUnaryOperators( - @ForAll(STRUCTURE) AlgebraicStructure structure, + @ForAll(STRUCTURE) AlgebraicStructure structure, @ForAll BasicAlgebraicUnaryOperator o) { try { diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/CompleteFieldTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/CompleteFieldTheory.java index 13b90295..da0613e0 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/CompleteFieldTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/CompleteFieldTheory.java @@ -21,8 +21,7 @@ import net.jqwik.api.Property; import org.meeuw.math.NonAlgebraic; -import org.meeuw.math.abstractalgebra.CompleteField; -import org.meeuw.math.abstractalgebra.CompleteFieldElement; +import org.meeuw.math.abstractalgebra.*; import org.meeuw.math.exceptions.IllegalLogarithmException; import org.meeuw.math.exceptions.OverflowException; @@ -38,12 +37,12 @@ public interface CompleteFieldTheory> extends FieldTheory { @Property - default void getUnary(@ForAll(STRUCTURE) CompleteField struct) { + default void getUnary(@ForAll(STRUCTURE) AlgebraicStructure struct) { assertThat(struct.getSupportedUnaryOperators()).contains(SQRT, SIN, COS); } @Property - default void getOperators(@ForAll(STRUCTURE) CompleteField struct) { + default void getOperators(@ForAll(STRUCTURE) AlgebraicStructure struct) { assertThat(struct.getSupportedOperators()).contains(POWER); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/DivisionRingTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/DivisionRingTheory.java index bf5a6c87..0fcfe011 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/DivisionRingTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/DivisionRingTheory.java @@ -35,7 +35,7 @@ public interface DivisionRingTheory> extends AdditiveGroupTheory { @Property - default void fieldOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { + default void fieldOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/ElementTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/ElementTheory.java index 0c4c4b8c..ffdf9444 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/ElementTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/ElementTheory.java @@ -26,14 +26,13 @@ /** * The connection between {@link BasicObjectTheory} and algebra testing. - * {@link BasicObjectTheory#datapoints()} is identified with {@link #element()} + * {@link BasicObjectTheory#datapoints()} is identified with {@link #elements()} * * @author Michiel Meeuwissen * @since 0.4 */ public interface ElementTheory extends BasicObjectTheory { - String ELEMENT = "element"; String ELEMENTS = "elements"; @BeforeEach @@ -45,17 +44,13 @@ default void setupForAll() { @Provide Arbitrary elements(); - @Provide - default Arbitrary element() { - return Arbitraries.of(elements().sample()); - } default Logger getLogger() { return LogManager.getLogger(this.getClass()); } @Override - default Arbitrary datapoints() { - return elements(); + default Arbitrary datapoints() { + return elements().asGeneric(); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/GroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/GroupTheory.java index b9bad709..9cd91e11 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/GroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/GroupTheory.java @@ -36,12 +36,12 @@ public interface GroupTheory> extends MagmaTheory { @Property - default void groupOperators(@ForAll(STRUCTURE) Group s) { + default void groupOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.OPERATION); } @Property - default void groupUnitaryOperators(@ForAll(STRUCTURE) Group s) { + default void groupUnitaryOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedUnaryOperators()).contains(BasicAlgebraicUnaryOperator.INVERSION); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MagmaTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MagmaTheory.java index 55ff2a47..01dee461 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MagmaTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MagmaTheory.java @@ -18,8 +18,7 @@ import net.jqwik.api.ForAll; import net.jqwik.api.Property; -import org.meeuw.math.abstractalgebra.Magma; -import org.meeuw.math.abstractalgebra.MagmaElement; +import org.meeuw.math.abstractalgebra.*; import org.opentest4j.TestAbortedException; import static org.meeuw.assertj.Assertions.assertThat; @@ -34,28 +33,30 @@ public interface MagmaTheory> extends AlgebraicStructureTheory { @Property - default void magmaOperators(@ForAll(STRUCTURE) Magma s) { + default void magmaOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(OPERATION); } @Property - default void operatorAndCommutativity(@ForAll(ELEMENTS) E e1, @ForAll(ELEMENT) E e2) { - boolean isCommutative = e1.getStructure().operationIsCommutative(); + default void operatorAndCommutativity(@ForAll(ELEMENTS) AlgebraicElement e1, @ForAll(ELEMENTS) AlgebraicElement e2) { + E m1 = (E) e1; + E m2 = (E) e2; + boolean isCommutative = m1.getStructure().operationIsCommutative(); if (isCommutative) { - String s = OPERATION.stringify(e1, e2) + " %s" + - OPERATION.stringify(e2, e1); - assertThat(e1.operate(e2)).withFailMessage( + String s = OPERATION.stringify(m1, m2) + " %s" + + OPERATION.stringify(m2, m1); + assertThat(m1.operate(m2)).withFailMessage( String.format(s, "should be") - ).isEqTo(e2.operate(e1)); + ).isEqTo(m2.operate(m1)); getLogger().debug(String.format(s, "is")); } else { - String s = OPERATION.stringify(e1, e2) + " %s " + - OPERATION.stringify(e2, e1); - E e3 = e1.operate(e2); + String s = OPERATION.stringify(m1, m2) + " %s " + + OPERATION.stringify(m2, m1); + E e3 = m1.operate(m2); try { assertThat(e3).withFailMessage( String.format(s, "should not be") - ).isNotEqTo(e2.operate(e1)); + ).isNotEqTo(m2.operate(m1)); getLogger().debug(String.format(s, "is not ")); } catch (AssertionError ae) { getLogger().info(String.format(s, "is (!) ") + " (" + e3 + ")"); diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeAbelianSemiGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeAbelianSemiGroupTheory.java index 349ef305..ac263319 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeAbelianSemiGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeAbelianSemiGroupTheory.java @@ -44,8 +44,9 @@ default void multiplicativeCommutativity ( @Property default void multiplicativeCommutativityProperty( - @ForAll(STRUCTURE) MultiplicativeAbelianSemiGroup group) { - assertThat(group.multiplicationIsCommutative()).isTrue(); + @ForAll(STRUCTURE) AlgebraicStructure group) { + MultiplicativeSemiGroup casted = (MultiplicativeSemiGroup) group; + assertThat(casted.multiplicationIsCommutative()).isTrue(); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeGroupTheory.java index 72e5b8a1..a86856a9 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeGroupTheory.java @@ -17,8 +17,7 @@ import net.jqwik.api.*; -import org.meeuw.math.abstractalgebra.MultiplicativeGroup; -import org.meeuw.math.abstractalgebra.MultiplicativeGroupElement; +import org.meeuw.math.abstractalgebra.*; import org.meeuw.math.exceptions.IllegalPowerException; import org.meeuw.math.exceptions.ReciprocalException; import org.meeuw.math.operators.BasicAlgebraicBinaryOperator; @@ -36,7 +35,7 @@ public strictfp interface MultiplicativeGroupTheory { @Property - default void multiplicativeGroupOperators(@ForAll(STRUCTURE) MultiplicativeGroup group) { + default void multiplicativeGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure group) { assertThat(group.getSupportedOperators()) .contains(BasicAlgebraicBinaryOperator.MULTIPLICATION, BasicAlgebraicBinaryOperator.DIVISION); } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeSemiGroupTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeSemiGroupTheory.java index 1e5551d0..b50d0fb4 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeSemiGroupTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/MultiplicativeSemiGroupTheory.java @@ -33,13 +33,14 @@ public interface MultiplicativeSemiGroupTheory { @Property - default void multiplicativeSemiGroupOperators(@ForAll(STRUCTURE) MultiplicativeSemiGroup s) { + default void multiplicativeSemiGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure s) { assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.MULTIPLICATION); } @Property - default void multiplicationCommutativity(@ForAll(STRUCTURE) MultiplicativeSemiGroup s) { - if (s.multiplicationIsCommutative()) { + default void multiplicationCommutativity(@ForAll(STRUCTURE) AlgebraicStructure s) { + MultiplicativeSemiGroup cast = (MultiplicativeSemiGroup) s; + if (cast.multiplicationIsCommutative()) { assertThat(s).isInstanceOf(MultiplicativeAbelianSemiGroup.class); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/RngTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/RngTheory.java index b0539f0a..12a2bcc7 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/RngTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/abstractalgebra/RngTheory.java @@ -30,7 +30,7 @@ public interface RngTheory> extends AdditiveAbelianGroupTheory, MultiplicativeSemiGroupTheory { @Property - default void rngOperators(@ForAll(ELEMENT) E v1) { + default void rngOperators(@ForAll(ELEMENTS) E v1) { assertThat(v1.getStructure().getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.MULTIPLICATION, BasicAlgebraicBinaryOperator.ADDITION, BasicAlgebraicBinaryOperator.SUBTRACTION); } } diff --git a/mihxil-theories/src/main/java/org/meeuw/theories/numbers/ScalarTheory.java b/mihxil-theories/src/main/java/org/meeuw/theories/numbers/ScalarTheory.java index 1d02893a..ed95cd6d 100644 --- a/mihxil-theories/src/main/java/org/meeuw/theories/numbers/ScalarTheory.java +++ b/mihxil-theories/src/main/java/org/meeuw/theories/numbers/ScalarTheory.java @@ -37,7 +37,7 @@ default void implementsScalar(@ForAll(ELEMENTS) S e1) { } @Property - default void absSignum(@ForAll(ELEMENT) S e) { + default void absSignum(@ForAll(ELEMENTS) S e) { assertThat(e.abs().signum()).isIn(0, 1); } diff --git a/pom.xml b/pom.xml index abf606aa..3b74a456 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 5.11.2 0.8.12 3.26.3 - 1.7.2 + 1.9.1 0.10.2 8.0.1.Final 2.22.1