diff --git a/test/makefile b/test/makefile index 50cae10..6865ee0 100644 --- a/test/makefile +++ b/test/makefile @@ -37,7 +37,7 @@ run: $(SRC) $(OUTPUT) ./$(OUTPUT) verify: $(SRC) $(OUTPUT) - ./$(OUTPUT) | grep "NOT passed" || true + ./$(OUTPUT) | grep "NOT passed" -A 1 --group-separator='' || true time-linux: @echo "Requires /bin/time, found on GNU/Linux systems" && echo diff --git a/test/test b/test/test index e3f2968..cd8449d 100755 Binary files a/test/test and b/test/test differ diff --git a/test/test.c b/test/test.c index 0fd1d67..67de207 100644 --- a/test/test.c +++ b/test/test.c @@ -4,9 +4,8 @@ #include #include -#define N 1000 * 1000 -#define PERCENTAGE_TOLERANCE_UNIFORM 1.0/1000.0 -#define PERCENTAGE_TOLERANCE_NORMAL 5.0/1000.0 +#define PERCENTAGE_TOLERANCE 1.0/1000.0 +#define PERCENTAGE_TOLERANCE_LOGNORMAL 5.0/1000.0 #define MAX_NAME_LENGTH 500 // Structs @@ -28,16 +27,18 @@ void test_array_expectations(struct array_expectations e){ double delta_std = std - e.expected_std; - if(fabs(delta_mean) > e.tolerance){ + if(fabs(delta_mean)/fabs(mean) > e.tolerance){ printf("[-] Mean test for %s NOT passed.\n", e.name); - printf("Mean of %s: %f, vs expected mean: %f, delta: %f\n", e.name, mean, e.expected_mean, delta_mean); + printf("Mean of %s: %f, vs expected mean: %f\n", e.name, mean, e.expected_mean); + printf("delta: %f, relative delta: %f\n", delta_mean, delta_mean/fabs(mean)); }else { printf("[x] Mean test for %s PASSED\n", e.name); } - if(fabs(delta_std) > e.tolerance){ + if(fabs(delta_std)/fabs(std) > e.tolerance){ printf("[-] Std test for %s NOT passed.\n", e.name); - printf("Std of %s: %f, vs expected std: %f, delta: %f\n", e.name, std, e.expected_std, delta_std); + printf("Std of %s: %f, vs expected std: %f\n", e.name, std, e.expected_std); + printf("delta: %f, relative delta: %f\n", delta_std, delta_std/fabs(std)); }else { printf("[x] Std test for %s PASSED\n", e.name); } @@ -48,29 +49,32 @@ void test_array_expectations(struct array_expectations e){ // Test unit uniform void test_unit_uniform(uint64_t* seed){ - double* unit_uniform_array = malloc(sizeof(double) * N); + int n = 1000 * 1000; + double* unit_uniform_array = malloc(sizeof(double) * n); - for(int i=0; i 0){ test_normal(mean, std, seed); } @@ -202,7 +237,25 @@ int main(){ test_normal(mean, std, seed); } } + */ + printf("Testing very small lognormals\n"); + for(int i=0; i<10; i++){ + double mean = sample_uniform(-1, 1, seed); + double std = sample_uniform(0, 1, seed); + if ( std > 0){ + test_lognormal(mean, std, seed); + } + } + printf("Testing small lognormals\n"); + for(int i=0; i<10; i++){ + double mean = sample_uniform(-1, 5, seed); + double std = sample_uniform(0, 5, seed); + if ( std > 0){ + test_lognormal(mean, std, seed); + } + } + /* printf("Testing beta distribution\n"); for(int i=0; i<100; i++){ double a = sample_uniform(0, 1000, seed); @@ -222,5 +275,6 @@ int main(){ } free(seed); + */ }