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

159 lines
5.6 KiB
C++
Raw Normal View History

2019-10-08 14:49:52 -04:00
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS
#include "doctest.h"
2017-07-25 12:19:11 -04:00
#include <math.h>
2018-01-18 18:39:54 -05:00
#include "testutils.h"
2017-07-25 12:19:11 -04:00
#include "catima/catima.h"
#include "catima/storage.h"
2020-12-01 18:10:40 -05:00
using namespace std;
using catima::LN10;
2017-10-17 10:39:04 -04:00
2019-10-08 14:49:52 -04:00
TEST_CASE("datapoints equal operator"){
2017-07-25 12:19:11 -04:00
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;
2019-10-08 14:49:52 -04:00
CHECK(a == b);
CHECK(!(a==c));
CHECK(d == c);
CHECK(!(d==b));
CHECK(!(e==a));
2017-07-25 12:19:11 -04:00
d = a;
2019-10-08 14:49:52 -04:00
CHECK(!(d==c));
CHECK(d==b);
2017-07-25 12:19:11 -04:00
2019-10-08 14:49:52 -04:00
}
2017-07-25 12:19:11 -04:00
2019-10-08 14:49:52 -04:00
TEST_CASE("storage add"){
2017-07-25 12:19:11 -04:00
catima::Projectile p{12,6,6,1000};
catima::Material water({
{1,1,2},
{16,8,1}
});
catima::Material graphite({
{12,6,1}
});
2019-05-11 13:18:35 -04:00
2017-07-25 12:19:11 -04:00
catima::_storage.Reset();
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==0);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,water);
2018-10-21 16:08:16 -04:00
auto& dp = catima::_storage.Get(0);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==1);
CHECK(dp.p.A==12);
CHECK(dp.m.ncomponents()==2);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,water);
2018-10-21 16:08:16 -04:00
auto& dp2 = catima::_storage.Get(1);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==1);
CHECK(dp2.p.A==0);
CHECK(dp2.m.ncomponents()==0);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,graphite);
2018-10-21 16:08:16 -04:00
auto& dp3 = catima::_storage.Get(1);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==2);
CHECK(dp3.p.A==12);
CHECK(dp3.m.ncomponents()==1);
2017-07-25 12:19:11 -04:00
catima::_storage.Add(p,graphite);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==2);
2018-01-20 22:05:42 -05:00
2019-05-11 13:18:35 -04:00
catima::Config c1;
c1.z_effective = catima::z_eff_type::global;
2018-01-20 22:05:42 -05:00
catima::_storage.Add(p,graphite, c1);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==3);
2018-01-20 22:05:42 -05:00
catima::_storage.Add(p,graphite);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==3);
2019-05-11 13:18:35 -04:00
c1.z_effective = catima::z_eff_type::hubert;
2018-01-20 22:05:42 -05:00
catima::_storage.Add(p,graphite ,c1);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==4);
2018-01-20 22:05:42 -05:00
2019-10-08 14:49:52 -04:00
}
TEST_CASE("test maximum storage"){
2018-02-07 18:52:16 -05:00
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();
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==0);
2018-02-07 18:52:16 -05:00
for(int i=1;i<maxdata+1;i++){
2018-10-09 06:23:51 -04:00
catima::Projectile p1{2.0*i,(double)i,(double)i,1000};
2017-10-17 10:39:04 -04:00
catima::_storage.Add(p1,graphite);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==i);
CHECK(catima::_storage.GetN()==maxdata);
2017-08-02 06:17:34 -04:00
}
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==maxdata);
2018-02-07 18:52:16 -05:00
for(int i=1;i<maxdata-1;i++){
2018-10-09 06:23:51 -04:00
catima::Projectile p1{2.0*i,(double)i,(double)i,1000};
2017-10-17 10:39:04 -04:00
catima::_storage.Add(p1,water);
2019-10-08 14:49:52 -04:00
CHECK(catima::_storage.get_index()==i);
CHECK(catima::_storage.GetN()==maxdata);
2017-10-17 10:39:04 -04:00
}
2019-10-08 14:49:52 -04:00
}
TEST_CASE("energy table"){
2022-04-22 16:52:10 -04:00
catima::LogVArray<catima::max_datapoints> etable(catima::logEmin,catima::logEmax);
catima::EnergyTable<catima::max_datapoints> energy_table(catima::logEmin,catima::logEmax);
2017-07-25 12:19:11 -04:00
double step = (catima::logEmax - catima::logEmin)/(catima::max_datapoints-1);
2022-04-22 16:52:10 -04:00
CHECK(energy_table.step==step);
CHECK(energy_table[0]==approx(exp(LN10*(catima::logEmin))).R(1e-9));
CHECK(energy_table[1]==approx(exp(LN10*(catima::logEmin+step))).R(1e-9));
CHECK(energy_table[2]==approx(exp(LN10*(catima::logEmin+2.0*step))).R(1e-9));
CHECK(energy_table[3]==approx(exp(LN10*(catima::logEmin+3.0*step))).R(1e-9));
CHECK(energy_table[4]==approx(exp(LN10*(catima::logEmin+4.0*step))).R(1e-9));
CHECK(energy_table[5]==approx(exp(LN10*(catima::logEmin+5.0*step))).R(1e-9));
CHECK(energy_table[catima::max_datapoints-1]==approx(exp(LN10*(catima::logEmax))).epsilon(1e-6));
CHECK(etable.step_size()==step);
CHECK(etable[0]==approx(exp(LN10*(catima::logEmin))).R(1e-9));
CHECK(etable[1]==approx(exp(LN10*(catima::logEmin+step))).R(1e-9));
CHECK(etable[2]==approx(exp(LN10*(catima::logEmin+2.0*step))).R(1e-9));
CHECK(etable[3]==approx(exp(LN10*(catima::logEmin+3.0*step))).R(1e-9));
CHECK(etable[4]==approx(exp(LN10*(catima::logEmin+4.0*step))).R(1e-9));
CHECK(etable[5]==approx(exp(LN10*(catima::logEmin+5.0*step))).R(1e-9));
CHECK(etable[catima::max_datapoints-1]==approx(exp(LN10*(catima::logEmax))).epsilon(1e-6));
2019-10-08 14:49:52 -04:00
}
TEST_CASE("indexing"){
2018-02-26 17:20:42 -05:00
double val, dif;
2022-04-22 16:52:10 -04:00
catima::LogVArray<catima::max_datapoints> etable(catima::logEmin,catima::logEmax);
catima::EnergyTable<catima::max_datapoints> energy_table(catima::logEmin,catima::logEmax);
2018-02-26 17:20:42 -05:00
2022-04-22 16:52:10 -04:00
CHECK(energy_table.index(0.0)==-1);
2018-10-31 20:49:48 -04:00
for(int i=0;i<catima::max_datapoints-1;i++){
2022-04-22 16:52:10 -04:00
val = energy_table[i];
dif = energy_table[i+1] - val;
CHECK(energy_table.index(val)==i);
CHECK(energy_table.index(val+0.5*dif)==i);
CHECK(energy_table.index(val)==i);
CHECK(energy_table.index(val+0.5*dif)==i);
CHECK(etable.index(val)==i);
CHECK(etable.index(val+0.5*dif)==i);
CHECK(etable.index(val+0.01*dif)==i);
CHECK(etable.index(val+0.99*dif)==i);
2018-02-26 17:20:42 -05:00
}
2020-12-01 18:10:40 -05:00
}