Debugging and testing · 9 / 14 Exercise Medium

Text test table

Objective

Create a Python program that runs a test table: a list of inputs with the expected result of each one.

Instructions

  • Define capitalize_words(text), which puts the first letter of each word in upper case and the rest in lower case: " ".join(w.capitalize() for w in text.split()).
  • Read an integer n and then n lines with the format text|expected (split them with split("|")).
  • For each case show Test K: OK if capitalize_words(text) equals the expected value, or Test K: FAIL (got: X) otherwise. K starts at 1.
  • At the end show Passed: P of N.
Input
3
hola mundo|Hola Mundo
PYTHON|Python
ana lópez|Ana lópez
Output
Test 1: OK
Test 2: OK
Test 3: FAIL (got: Ana López)
Passed: 2 of 3

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise