static char* S_charmony_string_defines() { const char *pattern = "#define CFISH_INLINE %s\n" "#define CFISH_EXPORT %s\n" "#define CFISH_IMPORT %s\n" "#define CFISH_SIZEOF_CHAR %s\n" "#define CFISH_SIZEOF_SHORT %s\n" "#define CFISH_SIZEOF_INT %s\n" "#define CFISH_SIZEOF_LONG %s\n" "#define CFISH_SIZEOF_SIZE_T %s\n" "#define CFISH_FUNC_MACRO %s\n" "#define CFISH_U64_TO_DOUBLE(x) %s\n"; char *defines = CFCUtil_sprintf(pattern, XSTRING(CHY_INLINE), XSTRING(CHY_EXPORT), XSTRING(CHY_IMPORT), XSTRING(CHY_SIZEOF_CHAR), XSTRING(CHY_SIZEOF_SHORT), XSTRING(CHY_SIZEOF_INT), XSTRING(CHY_SIZEOF_LONG), XSTRING(CHY_SIZEOF_SIZE_T), XSTRING(CHY_FUNC_MACRO), XSTRING(CHY_U64_TO_DOUBLE(x))); return defines; }
static void test_oversize__growth_rate(TestBatchRunner *runner) { bool success = true; uint64_t size = 0; double growth_count = 0; double average_growth_rate = 0.0; while (size < SIZE_MAX) { uint64_t next_size = Memory_oversize((size_t)size + 1, sizeof(void*)); if (next_size < size) { success = false; FAIL(runner, "Asked for %" PRId64 ", got smaller amount %" PRId64, size + 1, next_size); break; } if (size > 0) { growth_count += 1; double growth_rate = CHY_U64_TO_DOUBLE(next_size) / CHY_U64_TO_DOUBLE(size); double sum = growth_rate + (growth_count - 1) * average_growth_rate; average_growth_rate = sum / growth_count; if (average_growth_rate < 1.1) { FAIL(runner, "Average growth rate dropped below 1.1x: %f", average_growth_rate); success = false; break; } } size = next_size; } TEST_TRUE(runner, growth_count > 0, "Grew %f times", growth_count); if (success) { TEST_TRUE(runner, average_growth_rate > 1.1, "Growth rate of oversize() averages above 1.1: %.3f", average_growth_rate); } for (size_t minimum = 1; minimum < 8; minimum++) { uint64_t next_size = Memory_oversize(minimum, sizeof(void*)); double growth_rate = CHY_U64_TO_DOUBLE(next_size) / (double)minimum; TEST_TRUE(runner, growth_rate > 1.2, "Growth rate is higher for smaller arrays (%u, %.3f)", (unsigned)minimum, growth_rate); } }