#include "../squiggle.h" #include #include #include #include #define N 1000 * 1000 #define PERCENTAGE_TOLERANCE 1.0/1000.0 void test_unit_uniform(uint64_t* seed){ double* unit_uniform_array = malloc(sizeof(double) * N); for(int i=0; i PERCENTAGE_TOLERANCE){ printf("[-] Mean test for unit uniform NOT passed.\n"); }else { printf("[x] Mean test for unit uniform PASSED\n"); } if(fabs(delta_std) > PERCENTAGE_TOLERANCE){ printf("[-] Std test for unit uniform NOT passed.\n"); }else { printf("[x] Std test for unit uniform PASSED\n"); } printf("\n"); } void test_uniform(double start, double end, uint64_t* seed){ double* uniform_array = malloc(sizeof(double) * N); for(int i=0; i width * PERCENTAGE_TOLERANCE){ printf("[-] Mean test for [%.1f, %.1f] uniform NOT passed.\n", start, end); printf("Mean of [%.1f, %.1f] uniform: %f, vs expected mean: %f, delta: %f\n", start, end, mean, expected_mean, mean - expected_mean); }else { printf("[x] Mean test for [%.1f, %.1f] uniform PASSED\n", start, end); } if(fabs(delta_std) > width * PERCENTAGE_TOLERANCE){ printf("[-] Std test for [%.1f, %.1f] uniform NOT passed.\n", start, end); printf("Std of [%.1f, %.1f] uniform: %f, vs expected std: %f, delta: %f\n", start, end, std, expected_std, std - expected_std); for(int i=0; i<10; i++){ printf("%.1f, ", uniform_array[i]); } }else { printf("[x] Std test for [%.1f, %.1f] uniform PASSED\n", start, end); } printf("\n"); } int main(){ // set randomness seed uint64_t* seed = malloc(sizeof(uint64_t)); *seed = 1000; // xorshift can't start with a seed of 0 printf("Testing unit uniform\n"); test_unit_uniform(seed); printf("Testing small uniforms\n"); for(int i=0; i<100; i++){ double start = sample_uniform(-10, 10, seed); double end = sample_uniform(-10, 10, seed); if ( end > start){ test_uniform(start, end, seed); } } printf("Testing wide uniforms\n"); for(int i=0; i<100; i++){ double start = sample_uniform(-1000 * 1000, 1000 * 1000, seed); double end = sample_uniform(-1000 * 1000, 1000 * 1000, seed); if ( end > start){ test_uniform(start, end, seed); } } free(seed); }