Created
April 6, 2020 14:08
-
-
Save ythirion/b7fb2bd21fca64a235639260069078bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Addition_properties_with_vavr_test { | |
private final int size = 10_000, tries = 100; | |
@Test | |
public void commutative() { | |
Property.def("Addition is commutative") | |
.forAll(Arbitrary.integer(), Arbitrary.integer()) | |
.suchThat((x, y) -> Calculator.add(x, y) == Calculator.add(y, x)) | |
.check(size, tries) | |
.assertIsSatisfied(); | |
} | |
@Test | |
public void associative() { | |
Property.def("Addition is associative") | |
.forAll(Arbitrary.integer()) | |
.suchThat(x -> Calculator.add(Calculator.add(x, 1), 1) == Calculator.add(x, 2)) | |
.check(size, tries) | |
.assertIsSatisfied(); | |
} | |
@Test | |
public void identity() { | |
Property.def("0 is the identity") | |
.forAll(Arbitrary.integer()) | |
.suchThat((x) -> Calculator.add(x, 0) == x) | |
.check(size, tries) | |
.assertIsSatisfied(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment