MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / correctness_sweep

Function correctness_sweep

examples/sort/bench_stable_sort.cpp:302–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300
301template <typename T>
302void correctness_sweep(const char * type_name) {
303 const size_t ns[] = { 0, 1, 2, 3, 5, 15, 16, 17, 31, 32, 33, 63, 64, 65, 100, 1000, 4096 };
304 const Pattern pats[] = { Pattern::Random, Pattern::Dups, Pattern::Sorted,
305 Pattern::Partial, Pattern::Reverse, Pattern::AllEqual };
306 int cases = 0;
307 for (uint32_t seed = 1; seed <= 5; seed++) {
308 for (size_t n : ns) {
309 for (Pattern p : pats) {
310 auto in = make_pattern<T>(p, n, seed * 7919u);
311 // Run each candidate on its own fresh copy, verify against the pristine input.
312 auto fail = [&](const char * nm) {
313 std::fprintf(stderr, "CORRECTNESS FAIL: %s on %s n=%zu pattern=%s seed=%u\n",
314 nm, type_name, n, pattern_name(p), seed);
315 std::abort();
316 };
317 auto run = [&](const char * nm, auto fn) {
318 auto out = in;
319 fn(out.data(), out.size(), sizeof(T), key_less);
320 if (!verify_full(out, in)) fail(nm);
321 cases++;
322 };
323 // Shipped functions (das_qsort_r.h): byte + typed.
324 run("#3 byte", [](void * b, size_t e, size_t w, bool(*c)(const void*, const void*)) { das_stable_sort_r(b, e, w, c); });
325 { auto out = in; das_stable_sort(out.data(), out.data() + out.size(), TypedLess<T>()); if (!verify_full(out, in)) fail("#3 typed"); cases++; }
326 // Reference candidates (bake-off record): #1 dropped, #4 deferred.
327 run("#1 merge", [](void * b, size_t e, size_t w, bool(*c)(const void*, const void*)) { das_stable_merge_r(b, e, w, c); });
328 run("#4 index", [](void * b, size_t e, size_t w, bool(*c)(const void*, const void*)) { das_stable_index_r(b, e, w, c); });
329 }
330 }
331 }
332 std::printf("correctness: %-14s %d cases OK (sorted + stable + permutation + element-integrity)\n", type_name, cases);
333}
334
335int pick_iters(size_t n) {
336 if (n <= 1000) return 5000;

Callers

nothing calls this directly

Calls 13

fprintfFunction · 0.85
pattern_nameFunction · 0.85
fnFunction · 0.85
verify_fullFunction · 0.85
failFunction · 0.85
runFunction · 0.85
das_stable_sort_rFunction · 0.85
das_stable_sortFunction · 0.85
das_stable_merge_rFunction · 0.85
das_stable_index_rFunction · 0.85
printfFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected