In this exercise, I recreated some of the array methods with a propose of better understanding test-driven development. The standard is to duplicate what the native array methods do as close as possible.
Here are some guidelines:
-
Write down all test cases I can think of
-
Go through carefully if I need them
-
Cut
-
Think of examples first
-
Focus on observable behaviors but not implementation
Ask myself about my test cases:
- Are your tests lying?
- Are you testing the smallest pieces/Are your tests atomic enough?
- Are your tests in a sensible order?
- Do your tests cover edge cases: empty arrays, empty indexes(at the beginning of an array, middle, end), undefined, NaN, null.