5.1. Exercises

Assert Questions

Unit Tests Questions

def acronym_it(sentence):
    words = sentence.split()
    first_letters = [word[0].upper() for word in words]
    acronym =  "".join(first_letters)
    return acronym

Unit Tests and Test-Driven Development Questions

Writing Tests

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Given our BMI function from the previous few questions, let’s write some unit tests.

Tasks:

  • Write at least 4 unit tests and check that at least 2 of them are testing edge cases.
  • For this exercsie, use single quotes '' instead of double quotes "" for the assert messages.
Hint 1
  • Are you using Assert statements?
  • Are you checking that they equal a correct value?
Fully worked solution: