Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
test_vec_3d.cpp
Go to the documentation of this file.
1 #include <catch.hpp>
2 
3 #define BOOST_LOG_DYN_LINK 1
4 #include <boost/log/trivial.hpp>
5 
6 #include "class_vec_3d.hpp"
7 
8 TEST_CASE( "UNIT TEST: vector class {Vec_3D<T>}", "[core]" )
9 {
10  BOOST_LOG_TRIVIAL(info) << "vector class {Vec_3D<T>}";
11 
12  Vec_3D<double> vec_d(sqrt(2.), -sqrt(2.), sqrt(5.));
13  Vec_3D<float> vec_f(sqrt(2.f), -sqrt(2.f), sqrt(5.f));
14  Vec_3D<int> vec_i(3,0,-4);
15  CHECK( vec_d.norm() == Approx(3.) );
16  CHECK( vec_f.norm() == Approx(3.) );
17  CHECK( vec_i.norm() == Approx(5) );
18 
19  REQUIRE( vec_f[0] == Approx(sqrt(2.f)) );
20  REQUIRE( vec_f[2] == Approx(sqrt(5.)) );
21 
22  vec_d.fill(-1.345E1);
23  REQUIRE( vec_d[0] == -1.345E1 );
24  REQUIRE( vec_d[2] == -13.45 );
25 
26  vec_i.fill(0);
27  vec_i+=Vec_3D<int>(2, 3, -4);
28  REQUIRE ( (vec_i[0] + vec_i[1] + vec_i[2]) == Approx(1) );
29  // Vec_3D<double> vec_d2 = vec_i + Vec_3D<double>(1., 1.5, -3.5)*2.;
30  // REQUIRE( vec_d2[0] == Approx(4.) );
31  // REQUIRE( vec_d2[1] == Approx(6.) );
32  // REQUIRE( vec_d2[2] == Approx(-11.) );
33 
34  // double sumd = 0;
35  double sumi = 0;
36 
37  // for (double val : vec_d2) sumd += val;
38  for (int val : vec_i) sumi += val;
39 
40  // CHECK( sumd == Approx(-1.) );
41  CHECK( sumi == 1 );
42 
43  CHECK( Vec_3D<int>(4, -3, 8) == Vec_3D<int>(4, -3, 8) );
44  CHECK_FALSE( Vec_3D<int>(4, -3, 8) != Vec_3D<int>(4, -3, 8) );
45  CHECK( Vec_3D<int>(4, -3, 8) <= Vec_3D<int>(6, 0, 8) );
46  CHECK_FALSE( Vec_3D<int>(4, -3, 8) < Vec_3D<int>(2, 0, 10) );
47  CHECK_FALSE( Vec_3D<int>(4, -3, 8) > Vec_3D<int>(4, 0, 8) );
48 }
TEST_CASE("UNIT TEST: vector class {Vec_3D<T>}","[core]")
Definition: test_vec_3d.cpp:8
define container Vec_3D
#define REQUIRE(...)
Definition: catch.hpp:13849
Grid< NDIM, T > sqrt(Grid< NDIM, T > lhs)
Definition: grid.h:231
#define CHECK(...)
Definition: catch.hpp:13860
#define CHECK_FALSE(...)
Definition: catch.hpp:13861