Estimated time: 4 hours
We have been writing just Ruby methods and testing the functionality manually. We are going to level up QA (Quality Assurance) of our code with automated testing.
The idea: Write code that passes in input values to our method and expects a certain output. We can quickly run our test code to ensure that any changes we make in our main method passes all test cases.
Estimated time: 2 days
By this point you must have a Git repo of all your basic problem solving from chapter 1. Each in it's own open PR. We are going to revisit each of the PRs and write MiniTest for each of the solutions you have written out.
In each of the PR, add each solution to a folder with a file which will hold the solution method and a separate file with the tests.
View the file changes to see the example code and file structure.
- Start by creating tests given in the problem.
- Think of your own test cases considering edge cases.
TDD is where the tests are written first before any solution is written. The test cases once written correctly and once run, all of them will fail since there is no solution written. The task of the developer is to then get all the tests to pass. If all the tests pass, you can be confident that your code is good and solves for the problem.
This also helps in not having to manually test and verify answers for multiple inputs. Just run the test and the tests tell you what is correct and wrong.
Going forward, especially for the more complex algorithms we will be creating, write your tests first. It will make you life a lot easier to solve those questions and test various inputs for the correct solutions.