A few days ago I tried to solve the next problem with TDD and found it really hard.
I could not reach the solution through a series of small incremental test cases.
This is the problem:
flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,],4] -> [1,2,3,4].
of course without using language implementation like
flatten in ruby
The process that I follow.
1- Write a set of tests (input--->expected-output)
2- Pick the simplest test case to solve. (RED)(Write a failing spec)
3- Write the most naive code change that solves the current set of tests. (GREEN)
4- Check if DRY is needed (Refactor)
5- Go back to 2
My expectation is that at some point I reach the solution for the general case but following these rules I'm not able to reach the solution.
At some point there is no naive change to solve the tests and I need to rewrite the whole solution.
I found two solutions to this problem but none of them was following this process.
I found a solution for this problem check this out https://dev.to/delbetu/a-tdd-example-e4o