0
votes

I'm reading about Property based testing using Scala language. In this slide, they present this concept: For proving function a+b is true. we just only to prove those statements are true on random data:

  1. a + b = b + a
  2. a + 0 = a
  3. a + 1 + 1 = a + 2

My question is: Which methodologies for checking that our test cases are enough, and can cover all cases on different data. For example on previous example, how can we sure that after our three properties run correctly, we can sure that our implementation is right.

1
3. does not look correctstark

1 Answers

0
votes

First of all, I assume, you have a typo in #3, it's supposed to be + rather than *.

To answer your question, you most certainly can not be sure that your implementation is right if you prove these three properties. Consider this implementation for instance, that satisfies all three properties, but is definitely wrong:

def wrongPlus(a: Int, b: Int) = if(a < 3 || b <3) b a+b else 0

To definitively prove the (integer) addition, you need to have an independent implementation of next integer. Then, by definition:

1. a + 0 = a
2. a + next(b) = next(a + b) 

If these properties hold for any a and b and some operation +, then + is indeed the addition.