// build test subcases like a tree. // run: 1--2--end 1--3--end two subroutines. TEST_CASE("vectors can be sized and resized") { std::vector<int> v(5); // 1 REQUIRE(v.size() == 5); REQUIRE(v.capacity() >= 5);
SUBCASE("adding to the vector increases it's size") { // 2 v.push_back(1);
CHECK(v.size() == 6); CHECK(v.capacity() >= 6); } SUBCASE("reserving increases just the capacity") { // 3 v.reserve(6);
// Group the test cases. TEST_SUITE("math") { TEST_CASE("") {} // part of the math test suite TEST_CASE("") {} // part of the math test suite }
// Test template. TEST_CASE_TEMPLATE("test std::any as integer", T, char, short, int, longlongint) { auto v = T(); std::any var = T(); CHECK(std::any_cast<T>(var) == v); }
TEST_CASE_TEMPLATE("test std::any as string", T, constchar *, std::string_view, std::string) { T v = "hello world"; std::any var = v; CHECK(std::any_cast<T>(var) == v); }
TEST_CASE("tutorial_complexity_set_find") { // Create a single benchmark instance that is used in multiple benchmark // runs, with different settings for complexityN. ankerl::nanobench::Bench bench;
// a RNG to generate input data ankerl::nanobench::Rng rng;
std::set<uint64_t> set;
// Running the benchmark multiple times, with different number of elements for (auto setSize : {10U, 20U, 50U, 100U, 200U, 500U, 1000U, 2000U, 5000U, 10000U}) {
// fill up the set with random data while (set.size() < setSize) { set.insert(rng()); }
// Run the benchmark, provide setSize as the scaling variable. bench.complexityN(set.size()).run("std::set find", [&] { ankerl::nanobench::doNotOptimizeAway(set.find(rng())); }); }
// calculate BigO complexy best fit and print the results std::cout << bench.complexityBigO() << std::endl; }
set(WITH_STATIC_LIB ON CACHE BOOL "CMocka: Build with a static library" FORCE) set(WITH_CMOCKERY_SUPPORT OFF CACHE BOOL "CMocka: Install a cmockery header" FORCE) set(WITH_EXAMPLES OFF CACHE BOOL "CMocka: Build examples" FORCE) set(UNIT_TESTING ON CACHE BOOL "CMocka: Build with unit testing" FORCE) set(PICKY_DEVELOPER OFF CACHE BOOL "CMocka: Build with picky developer flags" FORCE)