March 2015
Intermediate to advanced
236 pages
5h 26m
English
Sometimes you’ll be able to check behavior by applying its logical inverse. For mathematic computations, this is often the case: you can verify division with multiplication, addition with subtraction, and so on.
We decided to implement our own square-root function using Newton’s algorithm (a silly idea, given that Math.sqrt() is a trustworthy native implementation; apparently, we suffer from not-invented-here syndrome). We recall 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:
| iloveyouboss/15/test/scratch/NewtonTest.java | |
| | import org.junit.*; |
| | import static org.junit.Assert.*; |
| | import static ... |
Read now
Unlock full access