Right-B[I]CEP: Checking Inverse Relationships

Learn about writing the unit tests with the inverse relationship technique.

Logical inverse relationships

Sometimes, we’ll be able to check behavior by applying its logical inverse. For mathematical computations, this is often the case. We can:

  • Verify division with multiplication
  • Verify addition with subtraction

Implementation of the square-root function

Let’s take a look at the square-root function using Newton’s algorithm.

Remember that if we derive the square root of a number and square that result (that is, multiply it by itself), we should get the same number we started with:

Get hands-on with 1200+ tech skills courses.