Skip to content

Instantly share code, notes, and snippets.

@quii
Last active March 7, 2016 22:16
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 quii/7b8473a388aebef9b91b to your computer and use it in GitHub Desktop.
Save quii/7b8473a388aebef9b91b to your computer and use it in GitHub Desktop.
func TestAddingZeroMakesNoDifference(t *testing.T) {
/*
Create an assertion, which is a function that takes N inputs of
random data and returns true if the assertion passes.
In this case, we're saying take any random integer (x)
If you add 0, it should equal x
*/
assertion := func(x int) bool {
return add(x, 0) == x
}
// Run the assertion through the quick checker
if err := quick.Check(assertion, nil); err != nil {
t.Error(err)
}
}
func TestAssociativity(t *testing.T) {
assertion := func(x, y, z int) bool {
return add(add(x, y), z) == add(add(z, y), x)
}
if err := quick.Check(assertion, nil); err != nil {
t.Error(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment