Simvik

Write tests that catch the bugs

Write a test suite for a scaling function. It is graded by running it against buggy versions it must reject. A medium embedded C problem (Testing and code…

medium · Testing and code coverage · testing · test-design · boundaries · mutation-testing

This time you write the tests. test_percent(f) must call the function f with inputs of your choice, check its results against the specification in the comment above, and return true only if every check passes.

Your suite is graded the way mutation testing grades a test suite. It is run against a correct implementation, which it must pass, and against versions with one bug each, which it must reject. The visible test shows three of them. The hidden test has more: think about each line of the specification and what could go wrong with it.

Starter code

bool test_percent(percent_fn f) {
  return f(2048, 0, 4095) == 50;
}

Example tests

The correct version, and three bugs

judge("correct", good);
judge("no top clamp", no_top_clamp);
judge("no bottom clamp", no_bottom_clamp);
judge("divides first", divides_first);

Expected output:

correct: passes
no top clamp: caught
no bottom clamp: caught
divides first: caught

Learn it first

More Testing and code coverage problems