Esempio n. 1
0
TEST(string, ftos)
{
  auto f = [](double x) {
    return std::stod(json::ftos< double, char, std::char_traits<char>, std::allocator<char> >(x, std::allocator<char>()));
  };
  assert_almost_equal(f(0), 0);
  assert_almost_equal(f(1), 1);
  assert_almost_equal(f(-1.9), -1.9);
  assert_almost_equal(f(42.55), 42.55);
  assert_almost_equal(f(-42.55), -42.55);
}
Esempio n. 2
0
TEST(string, to_string)
{
  auto fi = [](int i) {
    return std::stoi(json::to_string< char, std::char_traits<char>, std::allocator<char> >(i));
  };
  auto fd = [](double d) {
    return std::stod(json::to_string< char, std::char_traits<char>, std::allocator<char> >(d));
  };
  assert_return(42, fi, 42);
  assert_return(-42, fi, -42);
  assert_almost_equal(1e-3, fd(1e-3));
  assert_almost_equal(-1e-3, fd(-1e-3));
}
Esempio n. 3
0
void test_scalar_product(void)
{
    Vector a, b;
    a.x = 1.; a.y = 2.;
    b.x = 3.; b.y = 4.;
    assert_almost_equal(a*b, real(11));
}
Esempio n. 4
0
void test_distance_periodic(void)
{
    //real distance_periodic(Vector p1, Vector p2)
    real L = 32;
    Vector a, b;

    a.x = 1;  a.y = 1;
    b.x = 31; b.y = 1;
    assert_almost_equal(distance_periodic(a, b, L), real(2));

    a.x = 1; a.y = 1;
    b.x = 1; b.y = 31;
    assert_almost_equal(distance_periodic(a, b, L), real(2));

    a.x = 1; a.y = 1;
    b.x = 31; b.y = 31;
    assert_almost_equal(distance_periodic(a, b, L), real(2)*std::sqrt(real(2)));

    a.x = 1; a.y = 1;
    b.x = 3; b.y = 1;
    assert_almost_equal(distance_periodic(a, b, L), real(2));

    a.x = 1; a.y = 1;
    b.x = 1; b.y = 3;
    assert_almost_equal(distance_periodic(a, b, L), real(2));

    a.x = 1; a.y = 1;
    b.x = 3; b.y = 3;
    assert_almost_equal(distance_periodic(a, b, L), real(2)*std::sqrt(real(2)));
}
Esempio n. 5
0
void test_get_average_number_of_neighbours(void)
{
    MATRIX n(4, 4);
    n.Set(0, 0, 0); n.Set(0, 1, 1); n.Set(0, 2, 1); n.Set(0, 3, 1);
    n.Set(1, 0, 1); n.Set(1, 1, 0); n.Set(1, 2, 1); n.Set(1, 3, 1);
    n.Set(2, 0, 0); n.Set(2, 1, 1); n.Set(2, 2, 0); n.Set(2, 3, 1);
    n.Set(3, 0, 0); n.Set(3, 1, 1); n.Set(3, 2, 1); n.Set(3, 3, 0);

    std::vector<real> ni(4);
    create_ni(n, ni);

    assert_almost_equal(get_average_number_of_neighbours(n), average(ni));
}
Esempio n. 6
0
void test_cts(void)
{
    real L = 32;
    std::vector<real> angles;
    std::vector<Vector> pos;
    Angdict angdict;
    //Posdict posdict;

    Vector a, b, c, d;
    a.x = 1.; a.y = 2.;
    b.x = 2.; b.y = 2.;
    c.x = 2.; c.y = 0.;
    d.x = 4.; d.y = 4.;

    angles = {0., PI/4., -PI/4., 0.};
    pos = {a, b, c, d};

    angdict[0] = angles;
    //posdict[0] = pos;

    Pi pi(angdict);

    /*pi:
    Vector(0., 0.)
    Vector(-0.70710678118, 0.)
    Vector(0.70710678118, 0.)
    Vector(0., 0.)
    */

    std::vector<real> ni(4);
    real nc;
    MATRIX n(4, 4);
    n.Zero();

    /* topological */

    calculate_n_topological(n, pos, L, 2);
    create_ni(n, ni);
    nc = average(ni);
    assert_almost_equal(nc, real(2));
    assert_almost_equal(CTs(0, pi, nc, ni), real(0.25));

    /* Metric */

    calculate_n_metric(n, pos, L, 2);
    create_ni(n, ni);
    nc = average(ni);
    assert_almost_equal(nc, real(1));
    assert_almost_equal(CTs(0, pi, nc, ni), real(0.375));

    /* Voronoi */

    calculate_n_voronoi(n, pos, L);
    create_ni(n, ni);
    nc = average(ni);
    assert_almost_equal(nc, real(3));
    assert_almost_equal(CTs(0, pi, nc, ni), real(0.25));
}
Esempio n. 7
0
void test_mixing_parameter(void)
{
    MATRIX n(2, 2);
    n.Set(0, 0, 1); n.Set(0, 1, 0);
    n.Set(1, 0, 0); n.Set(1, 1, 1);

    MATRIX m(2, 2);
    m.Set(0, 0, 1); m.Set(0, 1, 1);
    m.Set(1, 0, 0); m.Set(1, 1, 1);

    real nc = get_average_number_of_neighbours(n);

    assert_almost_equal(mixing_parameter(0.01, n, m, nc), real(50.));
}
Esempio n. 8
0
void test_average(void)
{
    //real average(const std::vector<real> &ni)
    std::vector<real> nums = {1., 2., 3., 4., 5., 6.};
    assert_almost_equal(average(nums), real(3.5));
}