Skip to content

Commit

Permalink
More clean up possible because of jqwik update.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Dec 16, 2024
1 parent 120b421 commit 46f539d
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ default void additiveCommutativity (

@Property
default void additiveCommutativityProperty(
@ForAll(STRUCTURE) AlgebraicStructure<?> group) {
AdditiveSemiGroup<E> casted = (AdditiveSemiGroup<E>) group;
assertThat(casted.additionIsCommutative()).isTrue();
@ForAll(STRUCTURE) AdditiveSemiGroup<E> group) {
assertThat(group.additionIsCommutative()).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;

import org.meeuw.math.abstractalgebra.AdditiveGroupElement;
import org.meeuw.math.abstractalgebra.AlgebraicStructure;
import org.meeuw.math.abstractalgebra.*;
import org.meeuw.math.operators.BasicAlgebraicBinaryOperator;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -33,7 +32,7 @@ public interface AdditiveGroupTheory<E extends AdditiveGroupElement<E>>
extends AdditiveMonoidTheory<E> {

@Property
default void additiveGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void additiveGroupOperators(@ForAll(STRUCTURE) AdditiveGroup<E> s) {
assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.ADDITION, BasicAlgebraicBinaryOperator.SUBTRACTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface AdditiveSemiGroupTheory<E extends AdditiveSemiGroupElement<E>>
extends MagmaTheory<E> {

@Property
default void additiveSemiGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void additiveSemiGroupOperators(@ForAll(STRUCTURE) AdditiveSemiGroup<E> s) {
assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.ADDITION);
}

Expand All @@ -45,9 +45,8 @@ default void additiveAssociativity (
.isEqTo(v1.plus((v2.plus(v3))));
}
@Property
default void additionCommutativity(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
AdditiveSemiGroup<E> casted = (AdditiveSemiGroup<E>) s;
if (casted.additionIsCommutative()) {
default void additionCommutativity(@ForAll(STRUCTURE) AdditiveSemiGroup<E> s) {
if (s.additionIsCommutative()) {
assertThat(s).isInstanceOf(AdditiveAbelianSemiGroup.class);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public interface AlgebraicStructureTheory<E extends AlgebraicElement<E>> extend
String STRUCTURE = "structure";

@Provide
default Arbitrary<? extends AlgebraicStructure<?>> structure() {
default Arbitrary<? extends AlgebraicStructure<E>> structure() {
return Arbitraries.of(elements().filter(Objects::nonNull).sample().getStructure());
}

@SuppressWarnings("unchecked")
@Property()
default void cardinalityAndStreaming(
@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
@ForAll(STRUCTURE) AlgebraicStructure<E> s) {

Logger log = getLogger();

Expand Down Expand Up @@ -106,7 +106,7 @@ default void cardinalityAndStreaming(
}

@Property
default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure<E> s) {
Random random = new Random();
try {
for (int i = 0; i < 10; i++) {
Expand All @@ -118,15 +118,15 @@ default void nextRandom(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
}

@Property
default void structureSameInstance(@ForAll(ELEMENTS) AlgebraicElement<?> e1, @ForAll(ELEMENTS) AlgebraicElement<?> e2) {
default void structureSameInstance(@ForAll(ELEMENTS) E e1, @ForAll(ELEMENTS) E e2) {
assertThat(e1.getStructure() == e2.getStructure()).isTrue();
assertThat(e1.getStructure().equals(e2.getStructure())).isTrue();
}

@Property
default void elementClass(
@ForAll(STRUCTURE) AlgebraicStructure<?> s,
@ForAll(ELEMENTS) AlgebraicElement<?> e
@ForAll(STRUCTURE) AlgebraicStructure<E> s,
@ForAll(ELEMENTS) AlgebraicElement<E> e
) {
assertThat(e).isInstanceOf(s.getElementClass());
}
Expand All @@ -137,12 +137,10 @@ default void elementClass(

@Property
default void algebraicBinaryOperators(
@ForAll(STRUCTURE) AlgebraicStructure<?> s,
@ForAll(ELEMENTS) AlgebraicElement<?> o1,
@ForAll(ELEMENTS) AlgebraicElement<?> o2) throws Throwable {
@ForAll(STRUCTURE) AlgebraicStructure<E> s,
@ForAll(ELEMENTS) E e1,
@ForAll(ELEMENTS) E e2) 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public interface CompleteFieldTheory<E extends CompleteFieldElement<E>> extends
FieldTheory<E> {

@Property
default void getUnary(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
default void getUnary(@ForAll(STRUCTURE) AlgebraicStructure<E> struct) {
assertThat(struct.getSupportedUnaryOperators()).contains(SQRT, SIN, COS);
}

@Property
default void getOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
default void getOperators(@ForAll(STRUCTURE) AlgebraicStructure<E> struct) {
assertThat(struct.getSupportedOperators()).contains(POWER);
}

Expand All @@ -71,31 +71,27 @@ default void lnAndPow(@ForAll(ELEMENTS) E a, @ForAll(ELEMENTS) E b) {
}

@Property
default void ePowZero(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
CompleteField<E> casted = (CompleteField<E>) struct;
assertThat(casted.e().pow(casted.zero())).isEqTo(casted.one());
default void ePowZero(@ForAll(STRUCTURE) CompleteField<E> struct) {
assertThat(struct.e().pow(struct.zero())).isEqTo(struct.one());
}

@Property
default void sinPi(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
CompleteField<E> casted = (CompleteField<E>) struct;
assertThat(casted.pi().sin()).isEqTo(casted.zero());
default void sinPi(@ForAll(STRUCTURE) CompleteField<E> struct) {
assertThat(struct.pi().sin()).isEqTo(struct.zero());
}

@Property
default void cosPi(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
CompleteField<E> casted = (CompleteField<E>) struct;
assertThat(casted.pi().cos()).isEqTo(casted.one().negation());
default void cosPi(@ForAll(STRUCTURE) CompleteField<E> struct) {
assertThat(struct.pi().cos()).isEqTo(struct.one().negation());
}

@Property
default void goldenRatio(@ForAll(STRUCTURE) AlgebraicStructure<?> struct) {
CompleteField<E> casted = (CompleteField<E>) struct;
default void goldenRatio(@ForAll(STRUCTURE) CompleteField<E> struct) {
try {
setConfiguration(builder ->
builder.configure(MathContextConfiguration.class,
(mathContextConfiguration) -> mathContextConfiguration.withContext(new MathContext(4))));
assertThat(casted.φ().sqr()).isEqTo(casted.φ().plus(casted.one()));
assertThat(struct.φ().sqr()).isEqTo(struct.φ().plus(struct.one()));
} finally {
ConfigurationService.resetToDefaults();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface DivisionRingTheory<E extends DivisionRingElement<E>> extends
AdditiveGroupTheory<E> {

@Property
default void fieldOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void fieldOperators(@ForAll(STRUCTURE) DivisionRing<E> s) {
assertThat(s.getSupportedOperators()).contains(ADDITION, SUBTRACTION, MULTIPLICATION, DIVISION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public interface GroupTheory<E extends GroupElement<E>>
extends MagmaTheory<E> {

@Property
default void groupOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void groupOperators(@ForAll(STRUCTURE) Group<E> s) {
assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.OPERATION);
}

@Property
default void groupUnitaryOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void groupUnitaryOperators(@ForAll(STRUCTURE) Group<E> s) {
assertThat(s.getSupportedUnaryOperators()).contains(BasicAlgebraicUnaryOperator.INVERSION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ public interface MagmaTheory<E extends MagmaElement<E>>
extends AlgebraicStructureTheory<E> {

@Property
default void magmaOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void magmaOperators(@ForAll(STRUCTURE) AlgebraicStructure<E> s) {
assertThat(s.getSupportedOperators()).contains(OPERATION);
}

@Property
default void operatorAndCommutativity(@ForAll(ELEMENTS) AlgebraicElement<?> e1, @ForAll(ELEMENTS) AlgebraicElement<?> e2) {
E m1 = (E) e1;
E m2 = (E) e2;
default void operatorAndCommutativity(@ForAll(ELEMENTS) E m1, @ForAll(ELEMENTS) E m2) {
boolean isCommutative = m1.getStructure().operationIsCommutative();
if (isCommutative) {
String s = OPERATION.stringify(m1, m2) + " %s" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ default void multiplicativeCommutativity (

@Property
default void multiplicativeCommutativityProperty(
@ForAll(STRUCTURE) AlgebraicStructure<?> group) {
MultiplicativeSemiGroup<E> casted = (MultiplicativeSemiGroup<E>) group;
assertThat(casted.multiplicationIsCommutative()).isTrue();
@ForAll(STRUCTURE) MultiplicativeSemiGroup<E> group) {
assertThat(group.multiplicationIsCommutative()).isTrue();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public strictfp interface MultiplicativeGroupTheory<E extends MultiplicativeGrou
extends MultiplicativeMonoidTheory<E> {

@Property
default void multiplicativeGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> group) {
default void multiplicativeGroupOperators(@ForAll(STRUCTURE) MultiplicativeGroup<E> group) {
assertThat(group.getSupportedOperators())
.contains(BasicAlgebraicBinaryOperator.MULTIPLICATION, BasicAlgebraicBinaryOperator.DIVISION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@ public interface MultiplicativeSemiGroupTheory<E extends MultiplicativeSemiGroup
extends MagmaTheory<E> {

@Property
default void multiplicativeSemiGroupOperators(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
default void multiplicativeSemiGroupOperators(@ForAll(STRUCTURE) MultiplicativeSemiGroup<E> s) {
assertThat(s.getSupportedOperators()).contains(BasicAlgebraicBinaryOperator.MULTIPLICATION);
}

@Property
default void multiplicationCommutativity(@ForAll(STRUCTURE) AlgebraicStructure<?> s) {
MultiplicativeSemiGroup<E> cast = (MultiplicativeSemiGroup<E>) s;
if (cast.multiplicationIsCommutative()) {
default void multiplicationCommutativity(@ForAll(STRUCTURE) MultiplicativeSemiGroup<E> s) {
if (s.multiplicationIsCommutative()) {
assertThat(s).isInstanceOf(MultiplicativeAbelianSemiGroup.class);
}
}
Expand Down

0 comments on commit 46f539d

Please sign in to comment.