Inside the companion
Build your studio
Two small CMake checkpoints: one executable, then a library with tests and presets.
Project files 9
Give the pattern an oracle
Known checker values and boundary cases for the CTest checkpoint.
#include "studio/checker.hpp"
#include <array>
#include <iostream>
#include <limits>
int main() {
struct Case { std::size_t x; std::size_t y; int expected; };
constexpr auto largest = std::numeric_limits<std::size_t>::max();
constexpr std::array cases{
Case{0, 0, 32}, Case{1, 1, 32}, Case{2, 0, 224},
Case{0, 2, 224}, Case{2, 2, 32}, Case{4, 0, 32},
Case{largest, largest, 32}, Case{largest, 0, 224}
};
int failures = 0;
for (const auto& item : cases) {
if (studio::shade(item.x, item.y) != item.expected) {
std::cerr << "Unexpected shade at " << item.x << ',' << item.y << '\n';
++failures;
}
}
if (failures != 0) return 1;
std::cout << cases.size() << " checker contracts passed\n";
std::cout.flush();
return std::cout ? 0 : 1;
}
This is the file included with the course. Copy and download give you its complete source.
Taking your work offline? Download all course companions
