Info: Check-Expects

The importance of check-expects.

Importance of Checks

Good check-expects give you a road map to write your function. Check-expects should be correct based on the purpose of your function, not its current behavior.

  • A working function should pass all of its check-expects.
  • A function that does not do what it is supposed to do should fail some check-expect.
  • A function that sometimes gives the right answer and sometimes gives the wrong answer should pass some check-expects but not all of them.

The idea of check-expects is important because when you are working with more complex and possibly buggy functions (later in the course), the specification (“check-expect”) can be written first, then you can test to see your progress in completing the goals you set (so it is not all or nothing).

Five example check-expect ideas from checkers that build in complexity:

  • is it legal to move diagonally to an empty square?
  • is it illegal to move diagonally to an occupied square?
  • is it legal to jump a single opponent’s piece?
  • is it illegal to jump your own piece?
  • is it illegal to jump off the board?

A programmer might start by allowing any move to an adjacent square, then put in rules that the square had to be unoccupied, then allow jumping, etc.