diff --git a/examples/01_one_sample/example b/examples/01_one_sample/example index 0395c5c..a8bdd5d 100755 Binary files a/examples/01_one_sample/example and b/examples/01_one_sample/example differ diff --git a/examples/02_many_samples/example b/examples/02_many_samples/example index 67494bd..1e63c34 100755 Binary files a/examples/02_many_samples/example and b/examples/02_many_samples/example differ diff --git a/examples/03_gcc_nested_function/example b/examples/03_gcc_nested_function/example index f669b12..5bf8d86 100755 Binary files a/examples/03_gcc_nested_function/example and b/examples/03_gcc_nested_function/example differ diff --git a/examples/04_sample_from_cdf_simple/example b/examples/04_sample_from_cdf_simple/example index e272595..a11109c 100755 Binary files a/examples/04_sample_from_cdf_simple/example and b/examples/04_sample_from_cdf_simple/example differ diff --git a/examples/05_sample_from_cdf_beta/example b/examples/05_sample_from_cdf_beta/example index b1afd6f..8a07292 100755 Binary files a/examples/05_sample_from_cdf_beta/example and b/examples/05_sample_from_cdf_beta/example differ diff --git a/examples/06_gamma_beta/example b/examples/06_gamma_beta/example index 11e0a92..a82f6b9 100755 Binary files a/examples/06_gamma_beta/example and b/examples/06_gamma_beta/example differ diff --git a/squiggle.c b/squiggle.c index 8832c36..b148092 100644 --- a/squiggle.c +++ b/squiggle.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -161,8 +161,7 @@ double array_std(double* array, int length) double mean = array_mean(array, length); double std = 0.0; for (int i = 0; i < length; i++) { - std += (array[i] - mean); - std *= std; + std += (array[i] - mean) * (array[i] - mean); } std = sqrt(std / length); return std; diff --git a/test/makefile b/test/makefile index e4139a0..50cae10 100644 --- a/test/makefile +++ b/test/makefile @@ -36,6 +36,9 @@ format: $(SRC) run: $(SRC) $(OUTPUT) ./$(OUTPUT) +verify: $(SRC) $(OUTPUT) + ./$(OUTPUT) | grep "NOT passed" || true + time-linux: @echo "Requires /bin/time, found on GNU/Linux systems" && echo diff --git a/test/test b/test/test index f6a849c..f65f306 100755 Binary files a/test/test and b/test/test differ diff --git a/test/test.c b/test/test.c index 2c8f909..c4d571f 100644 --- a/test/test.c +++ b/test/test.c @@ -4,7 +4,8 @@ #include #include -#define N 100 +#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); @@ -24,13 +25,13 @@ void test_unit_uniform(uint64_t* seed){ printf("Mean of unit uniform: %f, vs expected mean: %f, delta: %f\n", mean, expected_mean, delta_mean); printf("Std of unit uniform: %f, vs expected std: %f, delta: %f\n", std, expected_std, delta_std); - if(fabs(delta_mean) > 1.0/1000.0){ + if(fabs(delta_mean) > 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) > 1.0/1000.0){ + 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"); @@ -56,22 +57,22 @@ void test_uniform(double start, double end, uint64_t* seed){ double delta_std = std - expected_std; double width = fabs(end - start); - if(fabs(delta_mean) > width * 1.0/1000.0){ + if(fabs(delta_mean) > 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 unit uniform PASSED\n"); + printf("[x] Mean test for [%.1f, %.1f] uniform PASSED\n", start, end); } - if(fabs(delta_std) > width * 1.0/1000.0){ + 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 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); }