Skip to content

Commit 96a7fb7

Browse files
committed
code cov
1 parent a091629 commit 96a7fb7

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

test/src/require.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <assert.h> /* assert */
12
#include <stdio.h> /* printf */
23
#include <stdlib.h> /* abort */
34

@@ -19,11 +20,16 @@ static inline void
1920
((bool)(expr) ? (void)0 : require_fail(#expr, __FILE__, __LINE__, TPH_PRETTY_FUNCTION))
2021
/* clang-format on */
2122

23+
/* Dummy malloc/free functions. Used to set up incomplete allocators, should never be called.
24+
* Having the function definitions here means that these functions don't show up as missing
25+
* code coverage. */
26+
2227
static inline void *dummy_malloc(ptrdiff_t size, void *ctx)
2328
{
2429
(void)size;
2530
(void)ctx;
2631

32+
assert(false && "called dummy_malloc");
2733
static int a[2];
2834
return (void *)a;
2935
}
@@ -35,4 +41,5 @@ static inline void dummy_free(void *ptr, ptrdiff_t size, void *ctx)
3541
(void)ctx;
3642

3743
// Do nothing!
44+
assert(false && "called dummy_free");
3845
}

test/src/tph_poisson_test.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,20 @@ static void TestVaryingSeed()
207207
// we say that the sample from the first point set is distinct
208208
// from every sample in the second point set. Thus the two
209209
// distributions must be different.
210-
auto distinct_sample_found = false;
211-
for (ptrdiff_t i = 0; i < sampling_1981->nsamples; ++i) {
212-
const Real *p = &samples_1981[i * sampling_1981->ndims];
213-
Real min_sqr_dist = std::numeric_limits<Real>::max();
214-
for (ptrdiff_t j = 0; j < sampling_1337->nsamples; ++j) {
215-
const Real *q = &samples_1337[j * sampling_1337->ndims];
216-
Real sqr_dist = 0;
217-
for (int32_t k = 0; k < ndims; ++k) { sqr_dist += (p[k] - q[k]) * (p[k] - q[k]); }
218-
min_sqr_dist = std::min(min_sqr_dist, sqr_dist);
219-
}
220-
if (std::sqrt(min_sqr_dist) > static_cast<Real>(0.1)) {
221-
distinct_sample_found = true;
222-
break;
210+
REQUIRE([&]() {
211+
for (ptrdiff_t i = 0; i < sampling_1981->nsamples; ++i) {
212+
const Real *p = &samples_1981[i * sampling_1981->ndims];
213+
Real min_sqr_dist = std::numeric_limits<Real>::max();
214+
for (ptrdiff_t j = 0; j < sampling_1337->nsamples; ++j) {
215+
const Real *q = &samples_1337[j * sampling_1337->ndims];
216+
Real sqr_dist = 0;
217+
for (int32_t k = 0; k < ndims; ++k) { sqr_dist += (p[k] - q[k]) * (p[k] - q[k]); }
218+
min_sqr_dist = std::min(min_sqr_dist, sqr_dist);
219+
}
220+
if (std::sqrt(min_sqr_dist) > static_cast<Real>(0.1)) { return true; }
223221
}
224-
}
225-
226-
REQUIRE(distinct_sample_found);
222+
return false;
223+
}());
227224
}
228225

229226
static void TestInvalidArgs()

0 commit comments

Comments
 (0)