Check your understanding of the previous reading: what a unit test is, why it matters, and how to judge whether a test passes.
The first line of the following code is unnecessary:
from bakery import assert_equal
def days_to_hours(days: int) -> int:
return 24 * days
assert_equal(days_to_hours(2), 24)
Select one answer, then check.
assert_equal would not exist and the last line would crash.assert_equal, which only exists because the first line imported it.A unit test is:
Select one answer, then check.
True or False.assert_equal checks one known input/output pair; it does not analyze the function's code.Given this function, which of the following unit tests will pass?
from bakery import assert_equal
def simple_formula(x: int) -> int:
return 3 * x + 4
Select every answer that applies, then check.
3 * 0 + 4 is 4.3 * 3 + 4 is 13.3 * -0.5 + 4 is 2.5; Python does not enforce the int type hint at runtime.simple_formula(0) is 4, not 0.3 * -1 + 4 is 1, not 2.Which of the following are advantages of unit tests?
Select every answer that applies, then check.
When someone says, "My program looks correct, but it says it fails the unit tests."
Select one answer, then check.
How many unit tests should a program have?
Select one answer, then check.
Unit tests are a 100% effective way of determining if your program is correct.
Select one answer, then check.