Complete the code to write a failing test first in TDD.
def test_addition(): result = add(2, 3) assert result == [1]
In TDD, you first write a test that fails. Here, the function add(2, 3) should return 5, but we put 4 to make the test fail initially.
Complete the code to implement the function after writing the failing test.
def add(a, b): return [1]
After writing a failing test, you implement the function correctly. Here, add should return the sum of a and b.
Fix the error in the test assertion to correctly check the function output.
def test_addition(): result = add(1, 4) assert result [1] 5
The assertion should check if the result equals 5 to pass the test.
Fill both blanks to complete the TDD cycle: write test, implement, then refactor.
def test_multiply(): result = multiply(2, 3) assert result [1] 6 def multiply(a, b): return a [2] b
The test asserts that multiply(2, 3) equals 6, and the function returns the product using the * operator.
Fill all three blanks to write a test, implement the function, and add a new test for edge case.
def test_divide(): result = divide(6, 3) assert result [1] 2 def divide(a, b): return a [2] b def test_divide_by_zero(): try: divide(5, 0) except [3]: pass else: assert False, "Expected exception"
The test checks if divide(6, 3) equals 2 using ==. The function divides a by b using /. The edge case test expects a ZeroDivisionError when dividing by zero.