Introduction to Generalization in TDD

Welcome back to our course on Test-Driven Development (TDD) using Kotlin. In our previous lesson, we introduced the fundamentals of TDD along with the Red-Green-Refactor workflow. Now, we will elevate our TDD skills by focusing on generalizing solutions and enhancing the complexity of our testing scenarios.

As a brief reminder, TDD involves a repetitive cycle known as Red-Green-Refactor:

  • Red: Write a failing test to clarify the new functionality you aim to implement.
  • Green: Develop the smallest amount of code needed to make that test pass.
  • Refactor: Clean up the code, enhancing its quality while maintaining its functionality and ensuring all tests remain passing.

In this lesson, we will expand upon the sum function, demonstrating how to generalize it while following these TDD principles.

Examining the Current Code Structure

Before we dive into coding, let's review our current setup. You are already familiar with the sum function, which is implemented in Calculator.kt and its corresponding test in CalculatorTest.kt:

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal