2

I've been tasked with providing a comprehensive test for some code that calculates x-y.

You can assume that the code is not simply (x-y)

My idea is that a good set of values would be: 3 and 7

I think this because they are prime. Can anyone give me their opinion on this.

Many thanks.

Gerry Myerson
  • 179,216
  • My opinion is that this is a coding problem, and would fit better on the coding website than here on the math website. – Gerry Myerson Nov 04 '12 at 11:54
  • 1
    @Fendorio, it is impossible to completely test it because there are infinitely many numbers and you can only test finitely many! To check that - is correct you need to proof by induction. – sperners lemma Nov 04 '12 at 11:56

1 Answers1

3

This is really a coding question, but I would recommend having a set of test data which ensures that all possible sorts of result are tested, such as:

  • $x=7$ and $y=7$ (test it gives the correct answer for equal inputs)
  • $x=3$ and $y=7$ (test it gives the correct answer for $x<y$)
  • $x=7$ and $y=3$ (test it gives the correct answer for $x>y$)

It is probably also worth testing that you get the correct answer if $x$ or $y$ or both take the maximum value (or minimum value, i.e. most negative) allowed in your implementation language.

Old John
  • 19,569
  • 3
  • 59
  • 113
  • Ok that's brilliant. Thank you for your input! When i'm able to vote answers up i will be sure to vote yours. Thanks again. – Lee Brindley Nov 04 '12 at 15:10