Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ythirion/b7fb2bd21fca64a235639260069078bf to your computer and use it in GitHub Desktop.
Save ythirion/b7fb2bd21fca64a235639260069078bf to your computer and use it in GitHub Desktop.
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