1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-29 21:48:51 -05:00
catima/tests/test_storage.cpp

146 lines
4.2 KiB
C++
Raw Normal View History

2017-07-25 12:19:11 -04:00
#include "lest.hpp"
#include <math.h>
2018-01-18 18:39:54 -05:00
#include "testutils.h"
2017-07-25 12:19:11 -04:00
using namespace std;
#include "catima/catima.h"
#include "catima/storage.h"
2017-10-17 10:39:04 -04:00
2018-01-18 18:39:54 -05:00
using catima::approx;
2017-07-25 12:19:11 -04:00
const lest::test specification[] =
{
CASE("datapoints equal operator"){
catima::Projectile p{12,6,6,1000};
catima::Material water({
{1,1,2},
{16,8,1}
});
catima::Material graphite({
{12,6,1}
});
2018-01-18 18:39:54 -05:00
catima::Config c2;
c2.z_effective = catima::z_eff_type::winger;
2017-07-25 12:19:11 -04:00
catima::DataPoint a(p,water);
catima::DataPoint b(p,water);
catima::DataPoint c(p,graphite);
catima::DataPoint d;
2018-01-18 18:39:54 -05:00
catima::DataPoint e(p,water,c2);
2017-07-25 12:19:11 -04:00
d = c;
EXPECT(a == b);
EXPECT(!(a==c));
EXPECT(d == c);
EXPECT(!(d==b));
2018-01-18 18:39:54 -05:00
EXPECT(!(e==a));
2017-07-25 12:19:11 -04:00
d = a;
EXPECT(!(d==c));
EXPECT(d==b);
},
CASE("storage add"){
catima::Projectile p{12,6,6,1000};
catima::Material water({
{1,1,2},
{16,8,1}
});
catima::Material graphite({
{12,6,1}
});
2018-01-20 22:05:42 -05:00
catima::Config c1;
c1.z_effective = catima::z_eff_type::global;
2017-07-25 12:19:11 -04:00
catima::_storage.Reset();
EXPECT(catima::_storage.get_index()==0);
catima::_storage.Add(p,water);
2017-11-17 04:49:28 -05:00
auto dp = catima::_storage.Get(0);
2017-07-25 12:19:11 -04:00
EXPECT(catima::_storage.get_index()==1);
2017-11-17 04:49:28 -05:00
EXPECT(dp.p.A==12);
EXPECT(dp.m.ncomponents()==2);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,water);
2017-11-17 04:49:28 -05:00
auto dp2 = catima::_storage.Get(1);
2017-07-25 12:19:11 -04:00
EXPECT(catima::_storage.get_index()==1);
2017-11-17 04:49:28 -05:00
EXPECT(dp2.p.A==0);
EXPECT(dp2.m.ncomponents()==0);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,graphite);
2017-11-17 04:49:28 -05:00
auto dp3 = catima::_storage.Get(1);
2017-07-25 12:19:11 -04:00
EXPECT(catima::_storage.get_index()==2);
2017-11-17 04:49:28 -05:00
EXPECT(dp3.p.A==12);
EXPECT(dp3.m.ncomponents()==1);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,graphite);
EXPECT(catima::_storage.get_index()==2);
2018-01-20 22:05:42 -05:00
catima::_storage.Add(p,graphite, c1);
EXPECT(catima::_storage.get_index()==3);
catima::_storage.Add(p,graphite);
EXPECT(catima::_storage.get_index()==3);
c1.z_effective = catima::z_eff_type::atima14;
catima::_storage.Add(p,graphite ,c1);
EXPECT(catima::_storage.get_index()==4);
2017-07-25 12:19:11 -04:00
},
2018-02-07 18:52:16 -05:00
CASE("test maximum storage"){
auto maxdata = catima::max_storage_data;
2017-10-17 10:39:04 -04:00
catima::Projectile p{12,6,6,1000};
catima::Material water({
{1,1,2},
{16,8,1}
});
catima::Material graphite({
{12,6,1}
});
catima::_storage.Reset();
EXPECT(catima::_storage.get_index()==0);
2018-02-07 18:52:16 -05:00
for(int i=1;i<maxdata+1;i++){
2017-10-17 10:39:04 -04:00
catima::Projectile p1{2*i,i,i,1000};
catima::_storage.Add(p1,graphite);
EXPECT(catima::_storage.get_index()==i);
2018-02-07 18:52:16 -05:00
EXPECT(catima::_storage.GetN()==maxdata);
2017-08-02 06:17:34 -04:00
}
2018-02-07 18:52:16 -05:00
EXPECT(catima::_storage.get_index()==maxdata);
for(int i=1;i<maxdata-1;i++){
2017-10-17 10:39:04 -04:00
catima::Projectile p1{2*i,i,i,1000};
catima::_storage.Add(p1,water);
EXPECT(catima::_storage.get_index()==i);
2018-02-07 18:52:16 -05:00
EXPECT(catima::_storage.GetN()==maxdata);
2017-10-17 10:39:04 -04:00
}
2017-08-02 06:17:34 -04:00
},
2017-07-25 12:19:11 -04:00
CASE("energy table"){
double step = (catima::logEmax - catima::logEmin)/(catima::max_datapoints-1);
EXPECT(catima::energy_table.step==step);
EXPECT(catima::energy_table.values[0]==exp(M_LN10*(catima::logEmin)));
EXPECT(catima::energy_table.values[1]==exp(M_LN10*(catima::logEmin+step)));
2018-01-18 18:39:54 -05:00
EXPECT(catima::energy_table.values[catima::max_datapoints-1]==approx(exp(M_LN10*(catima::logEmax))).epsilon(1e-6));
2018-02-26 17:20:42 -05:00
},
CASE("indexing"){
double step = catima::energy_table.step;
double val, dif;
EXPECT(EnergyTable_index(catima::energy_table, 0.0)==-1);
for(int i:{5,10,100,498}){
val = catima::energy_table.values[i];
dif = catima::energy_table.values[i+1] - val;
EXPECT(EnergyTable_index(catima::energy_table, val)==i);
EXPECT(EnergyTable_index(catima::energy_table, val+0.5*dif)==i);
}
2017-07-25 12:19:11 -04:00
}
};
int main( int argc, char * argv[] )
{
return lest::run( specification, argc, argv );
}