void my_random_testDouble(double minValueIncluded, double maxValueNotIncluded, int64_t numSamples) { my_log_info("\nrandomTestDouble\n"); double *array = MY_MALLOC_NOINIT(numSamples, double); my_random_doubleList(minValueIncluded, maxValueNotIncluded, array, numSamples); double actualAvg = my_math_averageDoubleArray(numSamples, array); char *st = my_newString_double(actualAvg); my_log_info("%"PRIi64" random double numbers in [%lf,%lf): %s\n", numSamples, minValueIncluded, maxValueNotIncluded, st); validate_stats(actualAvg, (maxValueNotIncluded + minValueIncluded) / 2.0); MY_FREE_MULTI(st, array); }
void my_random_testInt(int64_t minValueIncluded, int64_t maxValueNotIncluded, int64_t numSamples) { my_log_info("\nrandomTestInt\n"); int64_t *array = MY_MALLOC(numSamples, int64_t); my_random_intList(minValueIncluded, maxValueNotIncluded, array, numSamples); double actualAvg = my_math_averageIntArray(numSamples, array); double expectedAvg = (maxValueNotIncluded - 1 + minValueIncluded) / 2.0; char *st = my_newString_double(actualAvg); my_log_info("%"PRIi64" random int numbers in [%"PRIi64",%"PRIi64"): %s\n", numSamples, minValueIncluded, maxValueNotIncluded, st); MY_FREE(st); validate_stats(actualAvg, expectedAvg); validate_frequencies(array, minValueIncluded, maxValueNotIncluded, numSamples); MY_FREE(array); }
int stats_foreach(char *iname, stats_foreach_cb cb, void *args) { struct query_args qargs; struct request_hdr request; int error; error = validate_stats(); if (error) return error; qargs.cb = cb; qargs.args = args; init_request_hdr(&request, MODE_STATS, OP_FOREACH, false); return netlink_request(iname, &request, sizeof(request), stats_query_response, &qargs); }