Skip to content

Instantly share code, notes, and snippets.

@ythirion
Created April 6, 2020 12:37
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/c342d0369f5e9517bcc10537fdade046 to your computer and use it in GitHub Desktop.
Save ythirion/c342d0369f5e9517bcc10537fdade046 to your computer and use it in GitHub Desktop.
PBT
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import org.junit.Assert;
import org.junit.runner.RunWith;
@RunWith(JUnitQuickcheck.class)
public class Addition_properties {
@Property
public void commutative(int randomX, int randomY) {
int result1 = Calculator.add(randomX, randomY);
int result2 = Calculator.add(randomY, randomX);
Assert.assertEquals(result1, result2);
}
@Property
public void associative(int randomX) {
int result1 = Calculator.add(randomX, 1);
result1 = Calculator.add(result1, 1);
int result2 = Calculator.add(randomX, 2);
Assert.assertEquals(result1, result2);
}
@Property
public void identity(int randomX) {
int result1 = Calculator.add(randomX, 0);
Assert.assertEquals(result1, randomX);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment