Skip to content
Snippets Groups Projects
Commit f259025d authored by Veronique Legrand's avatar Veronique Legrand
Browse files

had forgotten to commit unit_test_math_utils.cpp

parent b29d3401
No related branches found
No related tags found
No related merge requests found
/*
* unit_test_math_utils.cpp
*
* Created on: 7 mai 2021
* Author: vlegrand
*/
#include <iostream>
#include <cassert>
#include <cmath>
#include "math_utils.h"
using namespace std;
void test_getCollisionProba() {
float p=getCollisionProba(2,5000000000,UINT_MAX,2);
assert(round(p*10000)==127);
p=getCollisionProba(2,5000000000,UINT_MAX,1);
assert(p=0.1128);
p =getCollisionProba(1,2,UINT_MAX,3);
//cout<<p<<endl;
assert(p==0.0);
p =getCollisionProba(1,1000000000,UINT_MAX,1);
assert(floor(p*1000+0.5)==23);
p =getCollisionProba(5,1000000000,UINT_MAX,1);
assert(floor(p*1000+0.5)==0);
p =getCollisionProba(5,50000000000,UINT_MAX,1);
assert(floor(p*1000+0.5)==975);
}
void test_gammln() {
float a;
a=gammln(1);
assert(exp(a)==1);
a=gammln(2);
assert(exp(a)==1);
a=gammln(3);
assert(exp(a)==2);
a=gammln(4);
assert(exp(a)==6);
a=gammln(5);
assert(exp(a)==24);
a=gammln(6);
float tmp=exp(a);
float tmp2=tmp*10000;
float tmp3=round(tmp2)/10000;
//printf("%s \n",tmp3);
assert(tmp3==120);
/* unsigned long n=5000;
unsigned long m=n+1;
a=gammln(m);
float b=gammln(n);
double truc=exp(a-b);
assert(truc==n);
*/
}
void test_pmf() {
unsigned long nb_k_mers=5000000000;
float p=pmf(0,nb_k_mers,UINT_MAX);
assert(round(p*10000)==3122);
p=pmf(1,nb_k_mers,UINT_MAX);
assert(round(p*10000)==3634);
p=pmf(2,nb_k_mers,UINT_MAX);
assert(round(p*10000)==2115);
}
void test_ccdf() {
unsigned long nb_k_mers=5000000000;
double res=ccdf(2,nb_k_mers,UINT_MAX);
assert(round(res*10000)==1128);
}
int main(int argc, char **argv) {
cout<<"testing the gammln function"<<endl;
test_gammln();
cout<<"testing the pmf function"<<endl;
test_pmf();
cout<<"testing the ccdf function"<<endl;
test_ccdf();
cout<<"testing computation of collision probability."<<endl;
test_getCollisionProba();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment