Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Functions.

RUNTask 23 of 23 · step 9: Homework: the fractionRun the homework tests
Run the homework tests in practice/01/

In CLion pick All CTest and ▶, or run only topic 5's tests in the terminal. Start with numbers.c.

Checklist

  • Every task is one commit with a clear message.
  • Zero compiler warnings: the code builds with -Werror.
  • Once per topic you step through your code in the debugger (CLion, gdb).
  • Every function has preconditions and postconditions, and assert tests check them.
Details & hint
$ ctest --preset debug -L hw05
    Start 11: hw05_functions
1/6 Test #11: hw05_functions ...................***Failed    0.04 sec
Assertion failed: gcd(84, 36) == 12, file C:/.../hw/05/unit_tests.c, line 14

    Start 12: hw05_precondition
2/6 Test #12: hw05_precondition ................***Failed    0.08 sec

=== hw05_precondition: FAILED ===
The program did not stop, but it should have.
gcd(-1, 5) must stop at an assert that checks the precondition a >= 0.
--- output ---
gcd(-1, 5) returned 0: no assert stopped it.

You should see: While the functions aren't written, unit_tests.c stops at the first assert, and hw05_precondition reports that gcd(-1, 5) didn't stop. When all is well: 100% tests passed.

Stuck? hw05_precondition passes only when gcd checks its precondition with an assert on its first line. The fraction tests rely on gcd, so the functions come first.

practice 01 CMakeLists.txt Code Diff
UNCHANGED This step does not change this file.
add_executable(p01_hello main.c)
opened for this task
$ ctest --preset debug -L hw05
    Start 11: hw05_functions
1/6 Test #11: hw05_functions ...................***Failed    0.04 sec
Assertion failed: gcd(84, 36) == 12, file C:/.../hw/05/unit_tests.c, line 14

    Start 12: hw05_precondition
2/6 Test #12: hw05_precondition ................***Failed    0.08 sec

=== hw05_precondition: FAILED ===
The program did not stop, but it should have.
gcd(-1, 5) must stop at an assert that checks the precondition a >= 0.
--- output ---
gcd(-1, 5) returned 0: no assert stopped it.