Challenge: Applying TDD

Challenge yourself by applying TDD.

In this lesson’s playground, we have an incomplete application. The application needs to accept an integer and tell us if the integer’s value is odd, even, or invalid. Any value smaller than one is classed as invalid. The information is returned in the form of a human-readable string.

The red stage of the TDD process is already complete. We have the tests that cover all the scenarios of our interest. Now, we need to complete the TDD process and write the required code. We cannot modify the tests, as those have already been approved.

Our goal is to bring the code to the completed refactor stage. For that, our code needs to be clean according to the following requirements:

  • If a method is assigned more than one operation, it must be split into two or more methods.

  • Any predefined values must be defined as constants.

Get hands-on with 1400+ tech skills courses.