C Testing
Ten spines on testing C the way it actually gets tested: hand-rolled CHECK macros, what NDEBUG deletes from an assert, seams built from function pointers, forcing the allocation-failure branch on purpose, and comparing floating point with a tolerance instead of ==. Every graded snippet is checked to give the same answer on every machine, and several items exist to catch a test that looks reasonable but could never actually fail.
Who it is for
Tests the code they wrote, not the code they meant.
The behaviour people get wrong after they are already productive in the language.
You will get the most out of it if you have written C recently enough to read it without effort, and have been surprised by it at least once. If you are picking the language up for the first time, start with C Essentials and come back to this one.
How long it takes
90 graded questions at roughly 45 seconds each is about 68 minutes of answering in total.
At the default five questions a day, and because the session mixes in your other courses, expect around 18 days — call it 3 weeks — to see everything once, plus a few weeks of thinning reviews after that before it is all mastered.
A question is mastered on the third correct answer, once the gap between reviews has grown past a week — so a course cannot be finished in a weekend however long you sit with it.
Question mix
- 60 multiple choice
- 10 concept cards
- 10 predict the output
- 10 put it in order
- 10 matching questions
Syllabus
What you will be asked about
-
01
Assertions Without a Framework
Write and interpret hand-rolled CHECK assertions, and explain why do/while(0) makes the macro safe to use anywhere a statement is expected.
-
02
assert.h and NDEBUG
Predict when assert checks its expression and when NDEBUG deletes it - expression, side effects and all.
-
03
Pure Functions vs Global State
Tell a pure function apart from one that reads or writes shared state, and predict which is safe to call in any order.
-
04
Seams via Function Pointers
Inject a dependency through a function pointer parameter so a test can substitute a stub or spy for the real thing.
-
05
Forcing Allocation Failure
Inject the allocator as a function pointer so a fake that always returns NULL can force the out-of-memory branch on demand.
-
06
Table-Driven Tests
Run a suite of input/expected pairs through one loop, and count or report on the rows that disagree.
-
07
Comparing Floating Point With a Tolerance
Compare floating-point results with fabs(a - b) < eps instead of ==, and choose an eps that neither over- nor under-tolerates.
-
08
What main Returning Non-Zero Means
Predict what a program's exit status communicates to a shell or test runner, and how exit() and an implicit return interact with it.
-
09
Why a Test That Cannot Fail Is Not a Test
Spot a check that would pass no matter what the code under test does, and rewrite it so it could actually catch a bug.
-
10
Test Independence
Recognise when shared mutable state makes a test case's result depend on execution order, and reset it so each case starts from the same baseline.
8 more topics, and all 90 questions
C Testing is a Pro course. One subscription opens it and every other course in the catalogue, including the ones still being written.
A question from this course
Assertions Without a Framework
What does this print?
#include <stdio.h>
#define CHECK(cond) do { \
if (!(cond)) printf("FAIL: %s\n", #cond); \
else printf("PASS: %s\n", #cond); \
} while (0)
int main(void) {
CHECK(2 + 2 == 4);
return 0;
}
Show the answer
A PASS: 2 + 2 == 4
The condition 2 + 2 == 4 is true, so the macro takes the PASS branch, and #cond stringifies the exact tokens passed in - spaces and all - rather than the value they compute. You may have expected the message to show the computed value 4, but stringification captures source text, not a result.
The rest of the track
C at every depth
C Essentials
Covers C's basic types and integer promotion, operator precedence, control flow, functions and parameters, arrays, strings as char arrays, introductory pointers, printf specifiers, scope and lifetime, and const - the syntax a beginner reaches for first. Every item runs against a real compiler, so the surprising cases are proven rather than asserted.
C Core
Covers pointer arithmetic, arrays decaying to pointers, where const actually applies, struct assignment, malloc/free and ownership, the strcpy family, integer conversion and promotion, the ternary and comma operators, and static at file and block scope. Aimed at someone who already writes C daily but has never had the gap between what compiles and what is correct made explicit.
C Data & Collections
Arrays decay to pointers the instant they cross a function boundary, and every container in C is really addresses and strides under a comfortable-looking syntax. This course puts pressure on that comfort: row-major layout, struct-embedded arrays, flexible array members, qsort comparators, realloc growth, and hand-built linked lists, until the mental model matches what the compiler actually does.
C Errors & Edge Cases
Most C code you have seen handles the case where everything works; this course is about the returns, allocations, and reads that fail, and what checking them properly looks like in practice. It covers return codes versus errno, partial transfers, strtol and strncpy's sharp edges, off-by-one bounds, integer overflow before malloc, and the goto-cleanup and assert idioms that keep a program correct under failure.
C Standard Library
For a reader who reaches for a dependency before checking what the standard library already does. Works through string.h, stdio.h, stdlib.h, ctype.h, time.h, and the fixed-width types in stdint.h and limits.h, with every answer checked against what the C standard actually guarantees.
C Idioms & Pitfalls
For a reader who is fluent in C but still writes it like another language. Works through the array-length macro's function-parameter trap, const placement, designated initializers, compound literals, both meanings of static, header guards, function-pointer dispatch tables, restrict, X-macros, and the copy-semantics mistakes that leak in from Java, Python, or C++.
C Advanced
Pointers to pointers, function pointers, unions, variadic functions, the preprocessor, recursion, setjmp/longjmp, opaque pointers and _Generic - the traps a confident C developer trips over. Every answer here is guaranteed by the standard, never by one compiler's mood on one machine.
C Performance
Complexity you can count instead of guess: linear scans, strlen in a loop condition, memcpy versus a byte loop, realloc growth, buffered output, struct passing, static linkage, and hoisting invariant work. Every answer here is an operation count or a call count, checked by running the code - never a clock reading.
C Interview Questions
Ten spines of the C questions that come up when time is short: string and pointer traps, linked-list rewiring, bit tricks and const rules, each one checked to give the same answer on every machine. The items built on a premise the language does not actually guarantee - char signedness, argument evaluation order, signed overflow - explain why, instead of faking a single output.
Start C Testing
in tomorrow’s session.
Enrol and this course joins your daily five, mixed in with everything else you are studying — 90 questions spread over about 18 days rather than dropped on you at once.
Browse the catalogue