formatting pass.

This commit is contained in:
NunoSempere 2023-07-23 15:44:22 +02:00
parent 6b2349132b
commit 88e998edce

View File

@ -1,8 +1,8 @@
#include "../squiggle.h"
#include <stdint.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define PERCENTAGE_TOLERANCE 1.0 / 1000.0
#define PERCENTAGE_TOLERANCE_LOGNORMAL 5.0 / 1000.0
@ -19,14 +19,14 @@ struct array_expectations {
double tolerance;
};
void test_array_expectations(struct array_expectations e){
void test_array_expectations(struct array_expectations e)
{
double mean = array_mean(e.array, e.n);
double delta_mean = mean - e.expected_mean;
double std = array_std(e.array, e.n);
double delta_std = std - e.expected_std;
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\n", e.name, mean, e.expected_mean);
@ -44,11 +44,11 @@ void test_array_expectations(struct array_expectations e){
}
printf("\n");
}
// Test unit uniform
void test_unit_uniform(uint64_t* seed){
void test_unit_uniform(uint64_t* seed)
{
int n = 1000 * 1000;
double* unit_uniform_array = malloc(sizeof(double) * n);
@ -70,7 +70,8 @@ void test_unit_uniform(uint64_t* seed){
}
// Test uniforms
void test_uniform(double start, double end, uint64_t* seed){
void test_uniform(double start, double end, uint64_t* seed)
{
int n = 1000 * 1000;
double* uniform_array = malloc(sizeof(double) * n);
@ -95,7 +96,8 @@ void test_uniform(double start, double end, uint64_t* seed){
}
// Test unit normal
void test_unit_normal(uint64_t* seed){
void test_unit_normal(uint64_t* seed)
{
int n = 1000 * 1000;
double* unit_normal_array = malloc(sizeof(double) * n);
@ -117,7 +119,8 @@ void test_unit_normal(uint64_t* seed){
}
// Test normal
void test_normal(double mean, double std, uint64_t* seed){
void test_normal(double mean, double std, uint64_t* seed)
{
int n = 10 * 1000 * 1000;
double* normal_array = malloc(sizeof(double) * n);
@ -142,7 +145,8 @@ void test_normal(double mean, double std, uint64_t* seed){
}
// Test lognormal
void test_lognormal(double logmean, double logstd, uint64_t* seed){
void test_lognormal(double logmean, double logstd, uint64_t* seed)
{
int n = 10 * 1000 * 1000;
double* lognormal_array = malloc(sizeof(double) * n);
@ -168,7 +172,8 @@ void test_lognormal(double logmean, double logstd, uint64_t* seed){
// Test beta
void test_beta(double a, double b, uint64_t* seed){
void test_beta(double a, double b, uint64_t* seed)
{
int n = 10 * 1000 * 1000;
double* beta_array = malloc(sizeof(double) * n);
@ -191,11 +196,12 @@ void test_beta(double a, double b, uint64_t* seed){
free(name);
}
int main(){
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);
@ -237,7 +243,7 @@ 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);
@ -255,7 +261,7 @@ int main(){
test_lognormal(mean, std, seed);
}
}
/*
printf("Testing beta distribution\n");
for (int i = 0; i < 100; i++) {
double a = sample_uniform(0, 1000, seed);
@ -275,6 +281,4 @@ int main(){
}
free(seed);
*/
}