Check your understanding of the previous reading: what a unit test is, why it matters, and how to judge whether a test passes.

Question 1

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.

  • Not quite. Without that import, assert_equal would not exist and the last line would crash.
  • Correct. The last line calls assert_equal, which only exists because the first line imported it.

Question 2

A unit test is:

Select one answer, then check.

  • Correct. A unit test calls a function with a known input and compares the result to a known output.
  • Not quite. "Unit" here means a small, isolated piece of code (like one function), not a unit of measurement.
  • Not quite. A unit test is a check on a function, not simply any function that returns True or False.
  • Not quite. assert_equal checks one known input/output pair; it does not analyze the function's code.

Question 3

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.

  • Passes. 3 * 0 + 4 is 4.
  • Passes. 3 * 3 + 4 is 13.
  • Passes. 3 * -0.5 + 4 is 2.5; Python does not enforce the int type hint at runtime.
  • Fails. simple_formula(0) is 4, not 0.
  • Fails. 3 * -1 + 4 is 1, not 2.
  • Fails — this is not valid Python at all; a type annotation cannot appear inside a function call.

Question 4

Which of the following are advantages of unit tests?

Select every answer that applies, then check.

  • Correct — one of the three advantages from the reading.
  • Correct — one of the three advantages from the reading.
  • Correct — one of the three advantages from the reading.
  • Not a stated advantage. Unit tests are separate code, alongside the function; they don't change how readable the function itself is.
  • Not an advantage. Running the tests takes extra time; they don't speed up the program itself.

Question 5

When someone says, "My program looks correct, but it says it fails the unit tests."

Select one answer, then check.

  • Correct. Looking correct is not the same as being correct — trust what the tests report.
  • Not quite. If a program fails its unit tests, something the programmer expected does not actually hold.

Question 6

How many unit tests should a program have?

Select one answer, then check.

  • Correct. The reading gives no fixed number — enough tests to be valid and thorough, which varies by function.
  • Not quite. A single test is rarely thorough enough to catch every incorrect implementation.
  • Not quite. There is no fixed number — it depends on the function being tested.
  • Not quite. There is no fixed number — it depends on the function being tested.
  • Not quite. Tests are written per scenario, not per line — a single test line can exercise several lines of code.

Question 7

Unit tests are a 100% effective way of determining if your program is correct.

Select one answer, then check.

  • Not quite. Passing tests is evidence your code is correct, not proof.
  • Correct. The reading is explicit: unit tests are "merely evidence to support the hypothesis that your code is correct."