Exemplo n.º 1
0
TEST_F(VectorTest, DefaultEntriesTest) {
    EXPECT_DOUBLE_EQ(0, emptyVector[0]);
    EXPECT_DOUBLE_EQ(0, emptyVector[1]);
    EXPECT_DOUBLE_EQ(0, emptyVector[2]);
}
Exemplo n.º 2
0
TEST_F(VectorTest, SumTest) {
    EXPECT_DOUBLE_EQ(6.6, vDouble1.sum());
    EXPECT_DOUBLE_EQ(-0.9, vDouble2.sum());
    EXPECT_EQ(6, vInt1.sum());
    EXPECT_EQ(-1, vInt2.sum());
}
Exemplo n.º 3
0
void expectEqTestRequest(const TestRequest& a, const TestRequest& b) {
  EXPECT_EQ(a.key().fullKey(), b.key().fullKey());

  EXPECT_EQ(a.testBool(), b.testBool());
  EXPECT_EQ(a.testChar(), b.testChar());
  EXPECT_EQ(a.testEnum(), b.testEnum());

  EXPECT_EQ(a.testInt8(), b.testInt8());
  EXPECT_EQ(a.testInt16(), b.testInt16());
  EXPECT_EQ(a.testInt32(), b.testInt32());
  EXPECT_EQ(a.testInt64(), b.testInt64());

  EXPECT_EQ(a.testUInt8(), b.testUInt8());
  EXPECT_EQ(a.testUInt16(), b.testUInt16());
  EXPECT_EQ(a.testUInt32(), b.testUInt32());
  EXPECT_EQ(a.testUInt64(), b.testUInt64());

  EXPECT_FLOAT_EQ(a.testFloat(), b.testFloat());
  EXPECT_DOUBLE_EQ(a.testDouble(), b.testDouble());

  EXPECT_EQ(a.testShortString(), b.testShortString());
  EXPECT_EQ(a.testLongString(), b.testLongString());

  EXPECT_EQ(
      coalesceAndGetRange(const_cast<folly::IOBuf&>(a.testIobuf())),
      coalesceAndGetRange(const_cast<folly::IOBuf&>(b.testIobuf())));

  // Mixed-in structure
  EXPECT_EQ(a.int32Member(), b.int32Member());
  EXPECT_EQ(a.stringMember(), b.stringMember());
  EXPECT_EQ(a.enumMember(), b.enumMember());
  expectEqSimpleStruct(a.asBase(), b.asBase());

  // Member structure
  expectEqSimpleStruct(a.testStruct(), b.testStruct());

  EXPECT_EQ(a.testList(), b.testList());

  EXPECT_EQ(a.testNestedVec(), b.testNestedVec());

  EXPECT_EQ(a.testEnumVec(), b.testEnumVec());

  EXPECT_EQ(a.testUMap(), b.testUMap());
  EXPECT_EQ(a.testMap(), b.testMap());
  EXPECT_EQ(a.testF14FastMap(), b.testF14FastMap());
  EXPECT_EQ(a.testF14NodeMap(), b.testF14NodeMap());
  EXPECT_EQ(a.testF14ValueMap(), b.testF14ValueMap());
  EXPECT_EQ(a.testF14VectorMap(), b.testF14VectorMap());
  EXPECT_EQ(a.testComplexMap(), b.testComplexMap());

  EXPECT_EQ(a.testUSet(), b.testUSet());
  EXPECT_EQ(a.testSet(), b.testSet());
  EXPECT_EQ(a.testF14FastSet(), b.testF14FastSet());
  EXPECT_EQ(a.testF14NodeSet(), b.testF14NodeSet());
  EXPECT_EQ(a.testF14ValueSet(), b.testF14ValueSet());
  EXPECT_EQ(a.testF14VectorSet(), b.testF14VectorSet());

  EXPECT_EQ(a.testOptionalString(), b.testOptionalString());
  compareOptionalIobuf(a.testOptionalIobuf(), b.testOptionalIobuf());

  EXPECT_EQ(a.testType().name, b.testType().name);
  EXPECT_EQ(a.testType().points, b.testType().points);

  EXPECT_EQ(a.testOptionalBool(), b.testOptionalBool());
  EXPECT_EQ(a.testOptionalVec(), b.testOptionalVec());
}
Exemplo n.º 4
0
TEST_F(VectorTest, VectorCopyDoubleAndInt) {
    Vector copyDoubleToDouble1(vDouble1);
    VectorInt copyIntToInt1(vInt1);
    Vector copyIntToDouble1(vInt2);
    VectorInt copyDoubleToInt1(vDouble2);

    Vector copyDoubleToDouble2 = vDouble1;
    VectorInt copyIntToInt2 = vInt1;
    Vector copyIntToDouble2 = vInt2;
    VectorInt copyDoubleToInt2 = vDouble2;

    EXPECT_DOUBLE_EQ(1.1, copyDoubleToDouble1[0]);
    EXPECT_DOUBLE_EQ(2.2, copyDoubleToDouble1[1]);
    EXPECT_DOUBLE_EQ(3.3, copyDoubleToDouble1[2]);

    EXPECT_EQ(1, copyIntToInt1[0]);
    EXPECT_EQ(2, copyIntToInt1[1]);
    EXPECT_EQ(3, copyIntToInt1[2]);

    EXPECT_DOUBLE_EQ(-2.0, copyIntToDouble1[0]);
    EXPECT_DOUBLE_EQ( 1.0, copyIntToDouble1[1]);
    EXPECT_DOUBLE_EQ( 0.0, copyIntToDouble1[2]);

    EXPECT_EQ(-2, copyDoubleToInt1[0]);
    EXPECT_EQ( 1, copyDoubleToInt1[1]);
    EXPECT_EQ( 0, copyDoubleToInt1[2]);

    EXPECT_DOUBLE_EQ(1.1, copyDoubleToDouble2[0]);
    EXPECT_DOUBLE_EQ(2.2, copyDoubleToDouble2[1]);
    EXPECT_DOUBLE_EQ(3.3, copyDoubleToDouble2[2]);

    EXPECT_EQ(1, copyIntToInt2[0]);
    EXPECT_EQ(2, copyIntToInt2[1]);
    EXPECT_EQ(3, copyIntToInt2[2]);

    EXPECT_DOUBLE_EQ(-2.0, copyIntToDouble2[0]);
    EXPECT_DOUBLE_EQ( 1.0, copyIntToDouble2[1]);
    EXPECT_DOUBLE_EQ( 0.0, copyIntToDouble2[2]);

    EXPECT_EQ(-2, copyDoubleToInt2[0]);
    EXPECT_EQ( 1, copyDoubleToInt2[1]);
    EXPECT_EQ( 0, copyDoubleToInt2[2]);
}
Exemplo n.º 5
0
TEST_F(Zone_Test, absolute_height) {
    zone->addHeightRangeQuick(1.0, -1.0, 2.0, 5.0, 6.0);

    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, -10.0, 0.0), VECTOR_UP), 0.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, -2.0, 0.0), VECTOR_UP), 0.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, -1.0, 0.0), VECTOR_UP), 0.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, -0.5, 0.0), VECTOR_UP), 1.0 / 6.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 0.0, 0.0), VECTOR_UP), 1.0 / 3.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 0.5, 0.0), VECTOR_UP), 0.5);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 2.0, 0.0), VECTOR_UP), 1.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 2.1, 0.0), VECTOR_UP), 1.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 3.5, 0.0), VECTOR_UP), 1.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 4.9, 0.0), VECTOR_UP), 1.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 5.0, 0.0), VECTOR_UP), 1.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 5.2, 0.0), VECTOR_UP), 0.8);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 5.7, 0.0), VECTOR_UP), 0.3);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 6.0, 0.0), VECTOR_UP), 0.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 15.0, 0.0), VECTOR_UP), 0.0);
    EXPECT_DOUBLE_EQ(zone->getValue(Vector3(0.0, 150.0, 0.0), VECTOR_UP), 0.0);
}
Exemplo n.º 6
0
TEST_F(test_dvector, reallocate)
{
  dvector v(1, 4);
  v(1) = 0.5;
  v(2) = 1.5;
  v(3) = 2.5;
  v(4) = -4.5;
  EXPECT_DOUBLE_EQ(1, v.indexmin());
  EXPECT_DOUBLE_EQ(4, v.indexmax());
  EXPECT_DOUBLE_EQ(4, v.size());
  v.reallocate(2.5);
  EXPECT_DOUBLE_EQ(1, v.indexmin());
  EXPECT_DOUBLE_EQ(10, v.indexmax());
  EXPECT_DOUBLE_EQ(10, v.size());
  EXPECT_DOUBLE_EQ(0.5, v(1));
  EXPECT_DOUBLE_EQ(1.5, v(2));
  EXPECT_DOUBLE_EQ(2.5, v(3));
  EXPECT_DOUBLE_EQ(-4.5, v(4));
  EXPECT_DOUBLE_EQ(0, v(5));
  EXPECT_DOUBLE_EQ(0, v(6));
  EXPECT_DOUBLE_EQ(0, v(7));
  EXPECT_DOUBLE_EQ(0, v(8));
  EXPECT_DOUBLE_EQ(0, v(9));
  EXPECT_DOUBLE_EQ(0, v(10));
  v.reallocate(0.2);
  EXPECT_DOUBLE_EQ(1, v.indexmin());
  EXPECT_DOUBLE_EQ(2, v.indexmax());
  EXPECT_DOUBLE_EQ(2, v.size());
  EXPECT_DOUBLE_EQ(0.5, v(1));
  EXPECT_DOUBLE_EQ(1.5, v(2));
}
Exemplo n.º 7
0
/* Test the method 'splitAt'*/
TEST_F(PositionVectorTest, test_method_splitAt) {
    PositionVector vec;
    vec.push_back(Position(0,0));
    vec.push_back(Position(2,0));
    vec.push_back(Position(5,0));
    double smallDiff = POSITION_EPS / 2;
    std::pair<PositionVector, PositionVector> result;
    // split in first segment
    result = vec.splitAt(1);
    EXPECT_EQ(2, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(1., result.first[1].x());
    EXPECT_EQ(3, (int)result.second.size());
    EXPECT_DOUBLE_EQ(1., result.second[0].x());
    EXPECT_DOUBLE_EQ(2., result.second[1].x());
    EXPECT_DOUBLE_EQ(5., result.second[2].x());
    // split in second segment
    result = vec.splitAt(4);
    EXPECT_EQ(3, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(2., result.first[1].x());
    EXPECT_DOUBLE_EQ(4., result.first[2].x());
    EXPECT_EQ(2, (int)result.second.size());
    EXPECT_DOUBLE_EQ(4., result.second[0].x());
    EXPECT_DOUBLE_EQ(5., result.second[1].x());
    // split close before inner point
    result = vec.splitAt(2 - smallDiff);
    EXPECT_EQ(2, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(2., result.first[1].x());
    EXPECT_EQ(2, (int)result.second.size());
    EXPECT_DOUBLE_EQ(2., result.second[0].x());
    EXPECT_DOUBLE_EQ(5., result.second[1].x());
    // split close after inner point
    result = vec.splitAt(2 + smallDiff);
    EXPECT_EQ(2, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(2., result.first[1].x());
    EXPECT_EQ(2, (int)result.second.size());
    EXPECT_DOUBLE_EQ(2., result.second[0].x());
    EXPECT_DOUBLE_EQ(5., result.second[1].x());

    // catch a bug
    vec.push_back(Position(6,0));
    vec.push_back(Position(8,0));
    // split at inner point
    result = vec.splitAt(5);
    EXPECT_EQ(3, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(2., result.first[1].x());
    EXPECT_DOUBLE_EQ(5., result.first[2].x());
    EXPECT_EQ(3, (int)result.second.size());
    EXPECT_DOUBLE_EQ(5., result.second[0].x());
    EXPECT_DOUBLE_EQ(6., result.second[1].x());
    EXPECT_DOUBLE_EQ(8., result.second[2].x());

    // split short vector
    PositionVector vec2;
    vec2.push_back(Position(0,0));
    vec2.push_back(Position(2,0));
    result = vec2.splitAt(1);
    EXPECT_EQ(2, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(1., result.first[1].x());
    EXPECT_EQ(2, (int)result.second.size());
    EXPECT_DOUBLE_EQ(1., result.second[0].x());
    EXPECT_DOUBLE_EQ(2. ,result.second[1].x());

    // split very short vector
    PositionVector vec3;
    vec3.push_back(Position(0,0));
    vec3.push_back(Position(POSITION_EPS,0));
    // supress expected warning
    MsgHandler::getWarningInstance()->removeRetriever(&OutputDevice::getDevice("stderr"));
    result = vec3.splitAt(smallDiff);
    MsgHandler::getWarningInstance()->addRetriever(&OutputDevice::getDevice("stderr"));

    EXPECT_EQ(2, (int)result.first.size());
    EXPECT_DOUBLE_EQ(0., result.first[0].x());
    EXPECT_DOUBLE_EQ(smallDiff, result.first[1].x());
    EXPECT_EQ(2, (int)result.second.size());
    EXPECT_DOUBLE_EQ(smallDiff, result.second[0].x());
    EXPECT_DOUBLE_EQ(POSITION_EPS, result.second[1].x());
}
Exemplo n.º 8
0
TEST(VectorTest, Angle) {
  Vector_d p1(4, 4);

  EXPECT_DOUBLE_EQ(M_PI / 4.0, p1.angle());
}
Exemplo n.º 9
0
TEST_F(SettingsTest, AddSettingDouble)
{
    settings.add("test_setting", "1234567.890");
    EXPECT_DOUBLE_EQ(double(1234567.89), settings.get<double>("test_setting"));
}
Exemplo n.º 10
0
/* Test the method 'getPolygonCenter'.*/
TEST_F(PositionVectorTest, test_method_getPolygonCenter) {
       Position pos = vectorPolygon->getPolygonCenter();
       EXPECT_DOUBLE_EQ(2, pos.x());
       EXPECT_DOUBLE_EQ(1.6, pos.y());
       Position pos2 = vectorLine->getPolygonCenter();
}
Exemplo n.º 11
0
TEST_F(SettingsTest, AddSettingRatio)
{
    settings.add("test_setting", "1.618");
    EXPECT_DOUBLE_EQ(Ratio(0.01618), settings.get<Ratio>("test_setting")) << "With ratios, the input is interpreted in percentages.";
}
Exemplo n.º 12
0
TEST_F(SettingsTest, AddSettingTemperature)
{
    settings.add("test_setting", "245.5");
    EXPECT_DOUBLE_EQ(Temperature(245.5), settings.get<Temperature>("test_setting"));
}
Exemplo n.º 13
0
//---------------------------------------------------------------------------//
// Test distance to next surface or vertex for various directions
TEST_F(FluDAGTest, GFireGoodPropStep)
{
  // std::cout << "Calling g_fire. Start in middle of leftmost cube" << std::endl;  
  oldReg   = 2;
  point[2] = 5.0;
  // Set prepStep to something more realistic than 0.0 
  propStep = 1e38;
  
  // +z direction
  dir[2]   = 1.0;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  std::cout << "newReg is " << newReg << std::endl;
  // Start in middle of 10x10x10 cube, expect 10/2 to be dist. to next surface
  EXPECT_EQ(5.0, retStep);
  // -z direction
  dir[2] = -dir[2];
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_EQ(5.0, retStep);
  // +y direction
  dir[2] = 0.0;
  dir[1] = 1.0;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_EQ(5.0, retStep);
  // -y direction
  dir[1] = -dir[1];
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_EQ(5.0, retStep);
  // +x direction
  dir[1] = 0.0;
  dir[0] = 1.0;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_EQ(5.0, retStep);
  // -x direction
  dir[0] = -dir[0];
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_EQ(5.0, retStep);

  // +++
  dir[0] = +dir_norm;
  dir[1] = +dir_norm;
  dir[2] = +dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_NEAR(8.660254, retStep, 1e-6);

  // ++-
  // Not Lost Particle!
  dir[0] = +dir_norm;
  dir[1] = +dir_norm;
  dir[2] = -dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_NEAR(8.660254, retStep, 1e-6);
  
  // +-+
  dir[0] = +dir_norm;
  dir[1] = -dir_norm;
  dir[2] = +dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_NEAR(8.660254, retStep, 1e-6);

  // +--
  // Not Lost Particle!
  dir[0] = +dir_norm;
  dir[1] = -dir_norm;
  dir[2] = -dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_NEAR(8.660254, retStep, 1e-6);

  // -++
  dir[0] = -dir_norm;
  dir[1] = +dir_norm;
  dir[2] = +dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_DOUBLE_EQ(5.0/dir_norm, retStep);

  // -+-
  // Not Lost Particle!
  dir[0] = -dir_norm;
  dir[1] = +dir_norm;
  dir[2] = -dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_DOUBLE_EQ(5.0/dir_norm, retStep);

  // --+
  dir[0] = -dir_norm;
  dir[1] = -dir_norm;
  dir[2] = +dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_DOUBLE_EQ(5.0/dir_norm, retStep);

  // ---
  // Not Lost Particle!
  dir[0] = -dir_norm;
  dir[1] = -dir_norm;
  dir[2] = -dir_norm;
  g_fire(oldReg, point, dir, propStep, retStep, safety, newReg);
  EXPECT_DOUBLE_EQ(5.0/dir_norm, retStep);
}
Exemplo n.º 14
0
TEST_F(VectorTest, ProdTest) {
    EXPECT_DOUBLE_EQ(7.986, vDouble1.prod());
    EXPECT_DOUBLE_EQ(0.345, vDouble2.prod());
    EXPECT_EQ(6, vInt1.prod());
    EXPECT_EQ(0, vInt2.prod());
}
Exemplo n.º 15
0
// 检查浮点数
TEST(casename, testname5)
{
    EXPECT_FLOAT_EQ(expected, actual);
    EXPECT_DOUBLE_EQ(expected, actual);
}
Exemplo n.º 16
0
TEST_F(KeyframeEffectModelTest, EvenlyDistributed3)
{
    KeyframeEffectModel::KeyframeVector keyframes(12);
    keyframes[0] = Keyframe::create();
    keyframes[0]->setOffset(0);
    keyframes[1] = Keyframe::create();
    keyframes[2] = Keyframe::create();
    keyframes[3] = Keyframe::create();
    keyframes[4] = Keyframe::create();
    keyframes[4]->setOffset(0.5);
    keyframes[5] = Keyframe::create();
    keyframes[6] = Keyframe::create();
    keyframes[7] = Keyframe::create();
    keyframes[7]->setOffset(0.8);
    keyframes[8] = Keyframe::create();
    keyframes[9] = Keyframe::create();
    keyframes[10] = Keyframe::create();
    keyframes[11] = Keyframe::create();

    const KeyframeVector result = normalizedKeyframes(keyframes);
    EXPECT_EQ(12U, result.size());
    EXPECT_DOUBLE_EQ(0.0, result[0]->offset());
    EXPECT_DOUBLE_EQ(0.125, result[1]->offset());
    EXPECT_DOUBLE_EQ(0.25, result[2]->offset());
    EXPECT_DOUBLE_EQ(0.375, result[3]->offset());
    EXPECT_DOUBLE_EQ(0.5, result[4]->offset());
    EXPECT_DOUBLE_EQ(0.6, result[5]->offset());
    EXPECT_DOUBLE_EQ(0.7, result[6]->offset());
    EXPECT_DOUBLE_EQ(0.8, result[7]->offset());
    EXPECT_DOUBLE_EQ(0.85, result[8]->offset());
    EXPECT_DOUBLE_EQ(0.9, result[9]->offset());
    EXPECT_DOUBLE_EQ(0.95, result[10]->offset());
    EXPECT_DOUBLE_EQ(1.0, result[11]->offset());
}
Exemplo n.º 17
0
TEST(evaluate_baselines, cpu_gpu)
{
    oskar_Mem *u, *v, *w, *uu, *vv, *ww;
    oskar_Mem *u_gpu, *v_gpu, *w_gpu, *uu_gpu, *vv_gpu, *ww_gpu;
    int num_baselines, num_stations = 50, status = 0, type, location;
    double *u_, *v_, *w_, *uu_, *vv_, *ww_;

    num_baselines = num_stations * (num_stations - 1) / 2;

    type = OSKAR_DOUBLE;

    // Allocate host memory.
    location = OSKAR_CPU;
    u = oskar_mem_create(type, location, num_stations, &status);
    v = oskar_mem_create(type, location, num_stations, &status);
    w = oskar_mem_create(type, location, num_stations, &status);
    uu = oskar_mem_create(type, location, num_baselines, &status);
    vv = oskar_mem_create(type, location, num_baselines, &status);
    ww = oskar_mem_create(type, location, num_baselines, &status);
    u_ = oskar_mem_double(u, &status);
    v_ = oskar_mem_double(v, &status);
    w_ = oskar_mem_double(w, &status);
    uu_ = oskar_mem_double(uu, &status);
    vv_ = oskar_mem_double(vv, &status);
    ww_ = oskar_mem_double(ww, &status);
    ASSERT_EQ(0, status) << oskar_get_error_string(status);

    // Fill station coordinates with test data.
    for (int i = 0; i < num_stations; ++i)
    {
        u_[i] = (double)(i + 1);
        v_[i] = (double)(i + 2);
        w_[i] = (double)(i + 3);
    }

    // Evaluate baseline coordinates on CPU.
    oskar_convert_station_uvw_to_baseline_uvw(num_stations,
            0, u, v, w, 0, uu, vv, ww, &status);
    ASSERT_EQ(0, status) << oskar_get_error_string(status);

    // Check results are correct.
    for (int s1 = 0, b = 0; s1 < num_stations; ++s1)
    {
        for (int s2 = s1 + 1; s2 < num_stations; ++s2, ++b)
        {
            EXPECT_DOUBLE_EQ(u_[s2] - u_[s1], uu_[b]);
            EXPECT_DOUBLE_EQ(v_[s2] - v_[s1], vv_[b]);
            EXPECT_DOUBLE_EQ(w_[s2] - w_[s1], ww_[b]);
        }
    }

    // Allocate device memory and copy input data.
#ifdef OSKAR_HAVE_CUDA
    location = OSKAR_GPU;
#endif
    u_gpu = oskar_mem_create_copy(u, location, &status);
    v_gpu = oskar_mem_create_copy(v, location, &status);
    w_gpu = oskar_mem_create_copy(w, location, &status);
    uu_gpu = oskar_mem_create(type, location, num_baselines, &status);
    vv_gpu = oskar_mem_create(type, location, num_baselines, &status);
    ww_gpu = oskar_mem_create(type, location, num_baselines, &status);
    ASSERT_EQ(0, status) << oskar_get_error_string(status);

    // Evaluate baseline coordinates on device.
    oskar_convert_station_uvw_to_baseline_uvw(num_stations,
            0, u_gpu, v_gpu, w_gpu, 0, uu_gpu, vv_gpu, ww_gpu, &status);
    ASSERT_EQ(0, status) << oskar_get_error_string(status);

    // Check results are consistent.
    double max_, avg;
    oskar_mem_evaluate_relative_error(uu_gpu, uu, 0, &max_, &avg, 0, &status);
    ASSERT_LT(max_, 1e-12);
    ASSERT_LT(avg, 1e-12);
    oskar_mem_evaluate_relative_error(vv_gpu, vv, 0, &max_, &avg, 0, &status);
    ASSERT_LT(max_, 1e-12);
    ASSERT_LT(avg, 1e-12);
    oskar_mem_evaluate_relative_error(ww_gpu, ww, 0, &max_, &avg, 0, &status);
    ASSERT_LT(max_, 1e-12);
    ASSERT_LT(avg, 1e-12);

    // Free memory.
    oskar_mem_free(u, &status);
    oskar_mem_free(v, &status);
    oskar_mem_free(w, &status);
    oskar_mem_free(uu, &status);
    oskar_mem_free(vv, &status);
    oskar_mem_free(ww, &status);
    oskar_mem_free(u_gpu, &status);
    oskar_mem_free(v_gpu, &status);
    oskar_mem_free(w_gpu, &status);
    oskar_mem_free(uu_gpu, &status);
    oskar_mem_free(vv_gpu, &status);
    oskar_mem_free(ww_gpu, &status);

    ASSERT_EQ(0, status) << oskar_get_error_string(status);
}
TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
  v8::Isolate::Scope isolate_scope(isolate());
  v8::HandleScope handle_scope(isolate());
  v8::Context::Scope context_scope(GetV8Context());
  bool bWrongFormat;
  double date;

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1968
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(-47865600000, date);
  EXPECT_FALSE(bWrongFormat);

  // 1985
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(504835200000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2085, the other '85.
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(3660595200000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 1995
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(791596800000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2095, the other '95.
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(3947356800000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2005
  bWrongFormat = false;
  date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy",
                                            &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(1107216000000.0, date);
  EXPECT_FALSE(bWrongFormat);

  // 2005
  bWrongFormat = false;
  date =
      CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", &bWrongFormat);
  date = RoundDownDate(date);
  EXPECT_DOUBLE_EQ(1107216000000.0, date);
  EXPECT_FALSE(bWrongFormat);
}
Exemplo n.º 19
0
TEST_F(CueControlTest, OutroCue_SetStartEnd_ClearStartEnd) {
    TrackPointer pTrack = createAndLoadFakeTrack();

    // Set outro start cue
    setCurrentSample(750.0);
    m_pOutroStartSet->slotSet(1);
    m_pOutroStartSet->slotSet(0);
    EXPECT_DOUBLE_EQ(750.0, m_pOutroStartPosition->get());
    EXPECT_TRUE(m_pOutroStartEnabled->toBool());
    EXPECT_DOUBLE_EQ(-1.0, m_pOutroEndPosition->get());
    EXPECT_FALSE(m_pOutroEndEnabled->toBool());

    CuePointer pCue = pTrack->findCueByType(Cue::OUTRO);
    EXPECT_NE(nullptr, pCue);
    if (pCue != nullptr) {
        EXPECT_DOUBLE_EQ(750.0, pCue->getPosition());
        EXPECT_DOUBLE_EQ(0.0, pCue->getLength());
        EXPECT_DOUBLE_EQ(Cue::MANUAL, pCue->getSource());
    }

    // Set outro end cue
    setCurrentSample(1000.0);
    m_pOutroEndSet->slotSet(1);
    m_pOutroEndSet->slotSet(0);
    EXPECT_DOUBLE_EQ(750.0, m_pOutroStartPosition->get());
    EXPECT_TRUE(m_pOutroStartEnabled->toBool());
    EXPECT_DOUBLE_EQ(1000.0, m_pOutroEndPosition->get());
    EXPECT_TRUE(m_pOutroEndEnabled->toBool());

    pCue = pTrack->findCueByType(Cue::OUTRO);
    EXPECT_NE(nullptr, pCue);
    if (pCue != nullptr) {
        EXPECT_DOUBLE_EQ(750.0, pCue->getPosition());
        EXPECT_DOUBLE_EQ(250.0, pCue->getLength());
        EXPECT_DOUBLE_EQ(Cue::MANUAL, pCue->getSource());
    }

    // Clear outro start cue
    m_pOutroStartClear->slotSet(1);
    m_pOutroStartClear->slotSet(0);
    EXPECT_DOUBLE_EQ(-1.0, m_pOutroStartPosition->get());
    EXPECT_FALSE(m_pOutroStartEnabled->toBool());
    EXPECT_DOUBLE_EQ(1000.0, m_pOutroEndPosition->get());
    EXPECT_TRUE(m_pOutroEndEnabled->toBool());

    pCue = pTrack->findCueByType(Cue::OUTRO);
    EXPECT_NE(nullptr, pCue);
    if (pCue != nullptr) {
        EXPECT_DOUBLE_EQ(-1.0, pCue->getPosition());
        EXPECT_DOUBLE_EQ(1000.0, pCue->getLength());
        EXPECT_DOUBLE_EQ(Cue::MANUAL, pCue->getSource());
    }

    // Clear outro end cue
    m_pOutroEndClear->slotSet(1);
    m_pOutroEndClear->slotSet(0);
    EXPECT_DOUBLE_EQ(-1.0, m_pOutroStartPosition->get());
    EXPECT_FALSE(m_pOutroStartEnabled->toBool());
    EXPECT_DOUBLE_EQ(-1.0, m_pOutroEndPosition->get());
    EXPECT_FALSE(m_pOutroEndEnabled->toBool());

    EXPECT_EQ(nullptr, pTrack->findCueByType(Cue::OUTRO));
}