Example #1
0
TEST(YogaTest, all_overridden) {
  const YGNodeRef root = YGNodeNew();
  YGNodeStyleSetFlexDirection(root, YGFlexDirectionColumn);
  YGNodeStyleSetWidth(root, 100);
  YGNodeStyleSetHeight(root, 100);

  const YGNodeRef root_child0 = YGNodeNew();
  YGNodeStyleSetFlexGrow(root_child0, 1);
  YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 10);
  YGNodeStyleSetMargin(root_child0, YGEdgeTop, 10);
  YGNodeStyleSetMargin(root_child0, YGEdgeRight, 10);
  YGNodeStyleSetMargin(root_child0, YGEdgeBottom, 10);
  YGNodeStyleSetMargin(root_child0, YGEdgeAll, 20);
  YGNodeInsertChild(root, root_child0, 0);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetTop(root_child0));
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetBottom(root_child0));

  YGNodeFreeRecursive(root);
}
Example #2
0
TEST(YogaTest, end_overrides) {
  const YGNodeRef root = YGNodeNew();
  YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
  YGNodeStyleSetWidth(root, 100);
  YGNodeStyleSetHeight(root, 100);

  const YGNodeRef root_child0 = YGNodeNew();
  YGNodeStyleSetFlexGrow(root_child0, 1);
  YGNodeStyleSetMargin(root_child0, YGEdgeEnd, 10);
  YGNodeStyleSetMargin(root_child0, YGEdgeLeft, 20);
  YGNodeStyleSetMargin(root_child0, YGEdgeRight, 20);
  YGNodeInsertChild(root, root_child0, 0);

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
  ASSERT_FLOAT_EQ(20, YGNodeLayoutGetLeft(root_child0));
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetRight(root_child0));

  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
  ASSERT_FLOAT_EQ(10, YGNodeLayoutGetLeft(root_child0));
  ASSERT_FLOAT_EQ(20, YGNodeLayoutGetRight(root_child0));

  YGNodeFreeRecursive(root);
}
Example #3
0
TEST(TestISTLMatrix, AssembleMPI)
{
  InspectMatrixSIM sim(1);
  sim.read("src/LinAlg/Test/refdata/petsc_test.xinp");
  sim.opt.solver = SystemMatrix::ISTL;
  sim.preprocess();
  sim.initSystem(SystemMatrix::ISTL);

  Matrix stencil(4,4);
  stencil(1,1) = stencil(2,2) = stencil(3,3) = stencil(4,4) = 1.0;

  for (int iel = 1; iel <= sim.getSAM()->getNoElms(); ++iel)
    sim.getMatrix()->assemble(stencil, *sim.getSAM(), iel);

  sim.getMatrix()->beginAssembly();
  sim.getMatrix()->endAssembly();

  // now inspect the matrix
  const ProcessAdm& adm = sim.getProcessAdm();
  ISTL::Mat& mat = static_cast<ISTLMatrix*>(sim.getMatrix())->getMatrix();
  ISTL::Vec b(mat.N()), b2(mat.N());

  try {
    Dune::OwnerOverlapCopyCommunication<int,int> comm(*adm.getCommunicator());
    comm.indexSet().beginResize();
    typedef Dune::ParallelLocalIndex<Dune::OwnerOverlapCopyAttributeSet::AttributeSet> LI;
    for (size_t i = 0; i < adm.dd.getMLGEQ().size(); ++i) {
      int gid = adm.dd.getGlobalEq(i+1);
      comm.indexSet().add(gid-1, LI(i, gid >= adm.dd.getMinEq() ?
                                       Dune::OwnerOverlapCopyAttributeSet::owner :
                                       Dune::OwnerOverlapCopyAttributeSet::overlap));
    }
    comm.indexSet().endResize();
    comm.remoteIndices().setIncludeSelf(true);
    comm.remoteIndices().template rebuild<false>();

    ISTL::ParMatrixAdapter op(mat, comm);

    b = 1.0;
    op.apply(b, b2);
  } catch (Dune::ISTLError& e) {
    std::cerr << e << std::endl;
    ASSERT_TRUE(false);
  }

  IntVec v = readIntVector("src/LinAlg/Test/refdata/petsc_matrix_diagonal.ref");
  for (size_t i = 1; i <= adm.dd.getMLGEQ().size(); ++i)
    ASSERT_FLOAT_EQ(v[adm.dd.getGlobalEq(i)-1], b2[i-1]);
}
Example #4
0
TEST(FloatTest, SaveLoadTest)
{
	INIT_DONUT;
	std::string providerName;
	XValue data;
	{
		Handler<FloatObject> obj( heap->createFloatObject(10.1) );
		ASSERT_ANY_THROW(obj->toBool(heap));
		ASSERT_ANY_THROW(obj->toInt(heap));
		ASSERT_ANY_THROW(obj->toString(heap));
		ASSERT_FLOAT_EQ(10.1, obj->toFloat(heap));
		data = Handler<HeapObject>(obj)->save(heap);
		providerName = obj->providerName(heap);
	}
	{
		Handler<HeapObject> obj(new FloatObject(heap->findHeapProvider(providerName).get()));
		obj->load(heap, data);
		ASSERT_NO_THROW(obj.cast<FloatObject>());
		ASSERT_ANY_THROW(obj->toBool(heap));
		ASSERT_ANY_THROW(obj->toInt(heap));
		ASSERT_ANY_THROW(obj->toString(heap));
		ASSERT_FLOAT_EQ(10.1, obj->toFloat(heap));
	}
}
Example #5
0
  void testit () {
    d_results = Kokkos::View<Kokkos::complex<double>*,ExecSpace>("TestComplexSpecialFunctions",20);
    h_results = Kokkos::create_mirror_view(d_results);

    Kokkos::parallel_for(Kokkos::RangePolicy<ExecSpace>(0,1), *this);
    Kokkos::fence();
    Kokkos::deep_copy(h_results,d_results);

    std::complex<double> a(1.5,2.5);
    double c = 9.3;

    std::complex<double> r;
    r = a;             ASSERT_FLOAT_EQ(h_results(0).real(),  r.real()); ASSERT_FLOAT_EQ(h_results(0).imag(),  r.imag());
    r = std::sqrt(a);  ASSERT_FLOAT_EQ(h_results(1).real(),  r.real()); ASSERT_FLOAT_EQ(h_results(1).imag(),  r.imag());
    r = std::pow(a,c); ASSERT_FLOAT_EQ(h_results(2).real(),  r.real()); ASSERT_FLOAT_EQ(h_results(2).imag(),  r.imag());
    r = std::abs(a);   ASSERT_FLOAT_EQ(h_results(3).real(),  r.real()); ASSERT_FLOAT_EQ(h_results(3).imag(),  r.imag());
  }
TEST_F(TrapezoidalTesting, DiagonalValue){

	ASSERT_FLOAT_EQ(0.5, rect_left.CalculateMembership(5.5));
	ASSERT_FLOAT_EQ(0.25, rect_left.CalculateMembership(5.75));
	ASSERT_FLOAT_EQ(0.75, rect_left.CalculateMembership(5.25));

	ASSERT_FLOAT_EQ(0.75, rect_right.CalculateMembership(2.75));
	ASSERT_FLOAT_EQ(0.25, rect_right.CalculateMembership(2.25));
	ASSERT_FLOAT_EQ(0.5, rect_right.CalculateMembership(2.5));
	float m1 = 1.0 - 1.0 / 3.0;
	float m2 = 1.0 - 2.0/ 3.0;

	ASSERT_FLOAT_EQ(m1, normal.CalculateMembership(3));
	ASSERT_FLOAT_EQ(m2, normal.CalculateMembership(4));


}
Example #7
0
TEST (AudioDataTest, DiscardFromFront) {
  KeyFinder::AudioData a;

  a.setChannels(1);
  a.setFrameRate(1);

  ASSERT_THROW(a.discardFramesFromFront(1), KeyFinder::Exception);
  a.addToFrameCount(10);
  ASSERT_THROW(a.discardFramesFromFront(11), KeyFinder::Exception);
  ASSERT_NO_THROW(a.discardFramesFromFront(0));
  a.setSampleByFrame(5, 0, 10.0);
  ASSERT_NO_THROW(a.discardFramesFromFront(5));
  ASSERT_EQ(5, a.getFrameCount());
  ASSERT_FLOAT_EQ(10.0, a.getSampleByFrame(0, 0));
}
Example #8
0
TEST(CircularBufferSingle, TestMultiWriteRead)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0,0,0,0};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 2);
    CircularBufferWrite(buffer, data + 2, 2);
    CircularBufferRead(buffer, out, 4);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], data[i]);
    }
}
TEST_F(TrapezoidalTesting , BoundariesOut){

	ASSERT_FLOAT_EQ(1, rect_left.CalculateMembership(2));
	ASSERT_FLOAT_EQ(0, rect_left.CalculateMembership(6));
	ASSERT_FLOAT_EQ(0, rect_right.CalculateMembership(2));
	ASSERT_FLOAT_EQ(1, rect_right.CalculateMembership(5));
	ASSERT_FLOAT_EQ(0, normal.CalculateMembership(-2));
	ASSERT_FLOAT_EQ(0, normal.CalculateMembership(5));

}
TEST_F(TrapezoidalTesting, OutOfBoundaries){

	ASSERT_FLOAT_EQ(0,rect_left.CalculateMembership(0));
	ASSERT_FLOAT_EQ(0,rect_left.CalculateMembership(10));
	ASSERT_FLOAT_EQ(0,rect_left.CalculateMembership(-10));

	ASSERT_FLOAT_EQ(0,normal.CalculateMembership(25));
	ASSERT_FLOAT_EQ(0,rect_left.CalculateMembership(-11));
	ASSERT_FLOAT_EQ(0,rect_left.CalculateMembership(6));
}
Example #11
0
TEST(Quaternion, Normalize) {
	narf::Quaternion<float> q1(3, -1, 4, 3);
	ASSERT_FLOAT_EQ(q1.norm(), 5.91608f);
	auto q2 = q1.normalize();
	ASSERT_FLOAT_EQ(q2.norm(), 1.0f);
	ASSERT_FLOAT_EQ(q2.w, 0.50709254f);
	ASSERT_FLOAT_EQ(q2.v.x, -0.16903085f);
	ASSERT_FLOAT_EQ(q2.v.y, 0.67612338f);
	ASSERT_FLOAT_EQ(q2.v.z, 0.50709254f);
}
Example #12
0
TEST_F(VCFReaderTest, QualField) {
	const char* value = nullptr;
	sph_umich_edu::QualField field;

	value = "";
	ASSERT_THROW(field.parse(value, value + strlen(value)), sph_umich_edu::VCFException);
	ASSERT_TRUE(field.is_empty());

	value = ".";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_TRUE(field.is_empty());
	ASSERT_TRUE(std::isnan(field.get_value()));

	value = "0";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(0.0, field.get_value());

	value = "30";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(30.0, field.get_value());

	value = "-30";
	ASSERT_THROW(field.parse(value, value + strlen(value)), sph_umich_edu::VCFException);
	ASSERT_TRUE(field.is_empty());

	value = "12.2";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(12.2, field.get_value());

	value = "12.0";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(12.0, field.get_value());

	value = "0.0";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(0.0, field.get_value());

	value = "0.12";
	ASSERT_NO_THROW(field.parse(value, value + strlen(value)));
	ASSERT_FALSE(field.is_empty());
	ASSERT_FLOAT_EQ(0.12, field.get_value());

	value = ".12";
	ASSERT_THROW(field.parse(value, value + strlen(value)), sph_umich_edu::VCFException);
	ASSERT_TRUE(field.is_empty());

	value = "aBc";
	ASSERT_THROW(field.parse(value, value + strlen(value)), sph_umich_edu::VCFException);
	ASSERT_TRUE(field.is_empty());
}
Example #13
0
/// tests Matrix4 array getter
TEST_F(Math_Matrix4Tests, ArrayGetter)
{
    float in_array[] = {5,-71,-13,86,-86,-8,-62,8,-69,-106,81,125,-1,-52,84,47};
    const float* out_array;
    
    for(int i=0; i < 4; i++)
    {
        for (int j=0; j < 4; j++)
            m1.set(i, j, in_array[i*4 + j]);
    }
    
    out_array = m1.getArray();
    
    for(int i=0; i < 16; i++)
        ASSERT_FLOAT_EQ(in_array[i], out_array[i]);
}
Example #14
0
TEST_F(TabuAlgorithmTest, BigTestOnRealData)
{
    std::shared_ptr<Vrp::CvrpFile> l_file = std::make_shared<Vrp::CvrpFile>("../../dairyProblem/data/A-n69-k9.vrp");
    Vrp::PolarCoordinatesMatrixConverter l_polarConv(Vrp::CvrpFileReader(l_file).getData());
    TabuAlgorithm l_algorithm(l_polarConv.convertAndSortByAngle());

    DairyPath l_result;
    l_result.distance = 1281.9614;
    l_result.path = {1, 30, 16, 28, 23, 10, 25, 19, 9, 15, 1,
                     12, 5, 29, 24, 7, 4, 3, 27, 1, 14, 8, 18,
                     20, 31, 32, 1, 17, 22, 2, 13, 21, 1, 26, 6, 11, 1};

    //ASSERT_EQ(l_algorithm.compute().path, l_result.path);
ASSERT_FLOAT_EQ(l_algorithm.compute().distance, l_result.distance);
    //ASSERT_FLOAT_EQ(l_algorithm.getDistance(), l_result.distance);
}
Example #15
0
TEST_P(MatricesToVtk_Grid3D_ptest, loadGrid3D_vector3)
{
    const auto & param = GetParam();

    io::ReadDataSet readDataSet;
    readDataSet.type = io::DataSetType::vectorGrid3D;
    auto & data = readDataSet.data;
    data = generateGrid(param, 3u);

    auto dataObject = MatricesToVtk::loadGrid3D("AGrid", { readDataSet });
    ASSERT_TRUE(dataObject);
    auto image = vtkImageData::SafeDownCast(dataObject->dataSet());
    ASSERT_TRUE(image);

    std::array<int, 3> dimensions;
    image->GetDimensions(dimensions.data());
    ASSERT_EQ(2, dimensions[0]);
    ASSERT_EQ(2, dimensions[1]);
    ASSERT_EQ(2, dimensions[2]);

    auto vectors = image->GetPointData()->GetVectors();
    ASSERT_TRUE(vectors);

    std::array<int, 3> refIncrements;
    refIncrements[static_cast<size_t>(param._0)] = 1;
    refIncrements[static_cast<size_t>(param._1)] = dimensions[0];
    refIncrements[static_cast<size_t>(param._2)] = dimensions[0] * dimensions[1];

    for (int z = 0; z < dimensions[2]; ++z)
    {
        for (int y = 0; y < dimensions[1]; ++y)
        {
            for (int x = 0; x < dimensions[0]; ++x)
            {
                const size_t refIndex = static_cast<size_t>(
                    refIncrements[0] * x + refIncrements[1] * y + refIncrements[2] * z);
                for (int c = 0; c < 3; ++c)
                {
                    const auto expected = static_cast<float>(
                        data[3u + static_cast<size_t>(c)][refIndex]);
                    const auto parsedComponent = image->GetScalarComponentAsFloat(x, y, z, c);
                    ASSERT_FLOAT_EQ(expected, parsedComponent);
                }
            }
        }
    }
}
Example #16
0
TEST(CircularBufferSingle, TestRewind)
{
    const float data[4] = {1,2,3,4};
    float out[4] = {0, 0, 0, 0};
    float expected[4] = {3, 4, 3, 4};
    CircularBuffer *buffer = CircularBufferInit(7);
    CircularBufferWrite(buffer, data, 4);
    CircularBufferRead(buffer, out, 4);
    CircularBufferRewind(buffer, 2);
    CircularBufferRead(buffer, out, 2);
    CircularBufferFlush(buffer);
    CircularBufferFree(buffer);
    
    for (unsigned i = 0; i < 4; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], expected[i]);
    }
}
Example #17
0
TEST(DSP, FloatDoubleConversion)
{
    float in[10] = {1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0};
    double out[10];
    float fout[10];
    
    FloatToDouble(out, in, 10);
    for (unsigned i = 0; i < 10; ++i)
    {
        ASSERT_DOUBLE_EQ((double)in[i], out[i]);
    }
    
    DoubleToFloat(fout, out, 10);
    for (unsigned i = 0; i < 10; ++i)
    {
        ASSERT_FLOAT_EQ(in[i], fout[i]);
    }
}
Example #18
0
TEST_F(CConfigFileTest, ReadTest)
{
    m_configFile.SetUseCurrentDirectory(true);

    ASSERT_TRUE(m_configFile.Init()); // load colobot.ini file

    std::string result;
    ASSERT_TRUE(m_configFile.GetStringProperty("test_string", "string_value", result));
    ASSERT_STREQ("Hello world", result.c_str());

    int int_value;
    ASSERT_TRUE(m_configFile.GetIntProperty("test_int", "int_value", int_value));
    ASSERT_EQ(42, int_value);

    float float_value;
    ASSERT_TRUE(m_configFile.GetFloatProperty("test_float", "float_value", float_value));
    ASSERT_FLOAT_EQ(1.5, float_value);
}
Example #19
0
TEST_F(DEMImageNormals_test, NormalsAreNormalized)
{
    auto demNormalFilter = vtkSmartPointer<DEMImageNormals>::New();
    demNormalFilter->SetCoordinatesUnitScale(1.0);
    demNormalFilter->SetElevationUnitScale(1.0);
    demNormalFilter->SetInputData(dem);
    ASSERT_TRUE(demNormalFilter->GetExecutive()->Update());
    auto normals = demNormalFilter->GetOutput()->GetPointData()->GetNormals();
    ASSERT_TRUE(normals);
    ASSERT_EQ(dem->GetNumberOfPoints(), normals->GetNumberOfTuples());

    for (vtkIdType i = 0; i < normals->GetNumberOfTuples(); ++i)
    {
        vtkVector3d normal;
        normals->GetTuple(i, normal.GetData());
        ASSERT_FLOAT_EQ(1.f, static_cast<float>(normal.Norm()));
    }
}
    TEST(xphoto_DenoisingBm3dKaiserWindow, regression_4)
    {
        float beta = 2.0f;
        int N = 4;

        cv::Mat kaiserWindow;
        calcKaiserWindow1D(kaiserWindow, N, beta);

        float kaiser4[] = {
            0.43869004f,
            0.92432547f,
            0.92432547f,
            0.43869004f
        };

        for (int i = 0; i < N; ++i)
            ASSERT_FLOAT_EQ(kaiser4[i], kaiserWindow.at<float>(i));
    }
Example #21
0
TEST(TestISTLPETScMatrix, SchurComplement)
{
  ASMmxBase::Type = ASMmxBase::FULL_CONT_RAISE_BASIS1;
  ASMmxBase::geoBasis = 2;

  Matrix stencil(13,13);
  for (size_t i = 1; i<= 13; ++i)
    for (size_t j = 1; j <= 13; ++j)
      stencil(i,j) = 1.0;

  std::array<InspectMatrixSIM,2> sim;
  for (size_t i = 0; i < 2; ++i) {
    sim[i].read("src/LinAlg/Test/refdata/petsc_test_blocks_basis.xinp");
    sim[i].opt.solver = i == 0 ? SystemMatrix::PETSC : SystemMatrix::ISTL;
    sim[i].preprocess();
    sim[i].initSystem(i == 0 ? SystemMatrix::PETSC : SystemMatrix::ISTL);

    for (int iel = 1; iel <= sim[i].getSAM()->getNoElms(); ++iel)
      sim[i].getMatrix()->assemble(stencil, *sim[i].getSAM(), iel);

    sim[i].getMatrix()->beginAssembly();
    sim[i].getMatrix()->endAssembly();
  }

  const ProcessAdm& adm = sim[1].getProcessAdm();
  ISTL::Mat& A = static_cast<ISTLMatrix*>(sim[1].getMatrix())->getMatrix();
  ISTL::BlockPreconditioner block(A, adm.dd, "upper");

  ISTL::Mat& S = block.getBlock(1);
  PETScSolParams params(LinSolParams(), adm);
  params.setupSchurComplement(static_cast<PETScMatrix*>(sim[0].getMatrix())->getBlockMatrices());

  // check that matrices are the same
  for (size_t r = 0; r < S.N(); ++r) {
    const PetscInt* cols;
    PetscInt ncols;
    const PetscScalar* vals;
    MatGetRow(params.getSchurComplement(), r, &ncols, &cols, &vals);
    for (PetscInt i = 0; i < ncols; ++i)
      ASSERT_FLOAT_EQ(vals[i], S[r][cols[i]]);
    MatRestoreRow(params.getSchurComplement(), r, &ncols, &cols, &vals);
  }
}
Example #22
0
TEST (AudioDataTest, Iterators) {
  KeyFinder::AudioData a;
  a.setChannels(1);
  a.setFrameRate(1);
  a.addToSampleCount(10);

  a.setSample(0, 10.0);
  a.setSample(1, 20.0);
  a.setSample(3, 50.0);

  a.resetIterators(); // this is required before each use

  ASSERT_FLOAT_EQ(10.0, a.getSampleAtReadIterator());
  a.setSampleAtWriteIterator(15.0);
  ASSERT_FLOAT_EQ(15.0, a.getSampleAtReadIterator());

  a.advanceReadIterator();
  a.advanceWriteIterator();
  ASSERT_FLOAT_EQ(20.0, a.getSampleAtReadIterator());
  a.setSampleAtWriteIterator(25.0);
  ASSERT_FLOAT_EQ(25.0, a.getSampleAtReadIterator());

  a.advanceReadIterator(2);
  a.advanceWriteIterator(2);
  ASSERT_FLOAT_EQ(50.0, a.getSampleAtReadIterator());
  a.setSampleAtWriteIterator(55.0);
  ASSERT_FLOAT_EQ(55.0, a.getSampleAtReadIterator());

  a.resetIterators();
  ASSERT_FLOAT_EQ(15.0, a.getSampleAtReadIterator());
  a.setSampleAtWriteIterator(150.0);
  ASSERT_FLOAT_EQ(150.0, a.getSampleAtReadIterator());

  ASSERT_TRUE(a.readIteratorWithinUpperBound());
  ASSERT_TRUE(a.writeIteratorWithinUpperBound());
  a.advanceReadIterator(10);
  a.advanceWriteIterator(10);
  ASSERT_FALSE(a.readIteratorWithinUpperBound());
  ASSERT_FALSE(a.writeIteratorWithinUpperBound());
}
Example #23
0
TEST(RMSEstimatorSingle, TestRMSEstimatorSetTime)
{
    float sinewave[10000];
    float out[10000];
    float out2[10000];
    for (unsigned i = 0; i < 10000; ++i)
    {
        sinewave[i] = sinf((6000 * M_PI * i)/10000); // 3000Hz sinewave at 44100
    }
    RMSEstimator * rms = RMSEstimatorInit(0.01, 10000);
    RMSEstimator * rms2 = RMSEstimatorInit(0.05, 10000);
    RMSEstimatorSetAvgTime(rms2, 0.01);
    RMSEstimatorProcess(rms, out, sinewave, 10000);
    RMSEstimatorProcess(rms2, out2, sinewave, 10000);
    RMSEstimatorFree(rms);
    RMSEstimatorFree(rms2);
    for (unsigned i = 250; i < 10000; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], out2[i]);
    }
}
TEST (WindowFunctionTest, AllTemporalWindowsAreSymmetricalAndRangeFrom0To1) {
  KeyFinder::WindowFunction win;
  unsigned int evenWidth = 24;
  unsigned int oddWidth = 25;
  for (unsigned int w = 0; w < 6; w++) {
    KeyFinder::temporal_window_t type;
    if (w % 3 == 0) type = KeyFinder::WINDOW_HANN;
    else if (w % 3 == 1) type = KeyFinder::WINDOW_HAMMING;
    else type = KeyFinder::WINDOW_BLACKMAN;
    unsigned int width;
    if (w % 2 == 0) width = evenWidth;
    else width = oddWidth;

    ASSERT_NEAR(0.0, win.window(type,         0, width), 0.1);
    ASSERT_NEAR(1.0, win.window(type, width / 2, width), 0.1);
    ASSERT_NEAR(0.0, win.window(type, width - 1, width), 0.1);
    for (unsigned int n = 0; n < width / 2; n++) {
      ASSERT_FLOAT_EQ(win.window(type, n, width), win.window(type, width - 1 - n, width));
    }
  }
}
Example #25
0
TEST(PanLawSingle, TestLinearPan)
{
    float left = 0.0;
    float right = 0.0;
    linear_pan(0, &left, &right);
    ASSERT_FLOAT_EQ(1.0, left);
    ASSERT_FLOAT_EQ(0.0, right);
    
    linear_pan(0.5, &left, &right);
    ASSERT_FLOAT_EQ(0.5, left);
    ASSERT_FLOAT_EQ(0.5, right);
    
    linear_pan(1.0, &left, &right);
    ASSERT_FLOAT_EQ(0.0, left);
    ASSERT_FLOAT_EQ(1.0, right);
}
TEST(RMDCuTests, deviceImageCopyFloat)
{
  rmd::test::Dataset dataset;
  if(!dataset.loadPathFromEnv())
  {
    FAIL() << "could not retrieve dataset path from the environment variable '"
           << rmd::test::Dataset::getDataPathEnvVar();
  }
  cv::Mat img;
  if(!dataset.readImage(img, "scene_000.png"))
  {
    FAIL() << "could not could not load test image from dataset";
  }

  cv::Mat img_flt;
  img.convertTo(img_flt, CV_32F, 1./255.);

  const size_t w = img_flt.cols;
  const size_t h = img_flt.rows;

  // upload data to gpu memory
  rmd::DeviceImage<float> in_img(w, h);
  in_img.setDevData(reinterpret_cast<float*>(img_flt.data));

  // create copy on device
  rmd::DeviceImage<float> out_img(w, h);
  rmd::copy(in_img, out_img);

  float * cu_img = new float[w*h];
  out_img.getDevData(cu_img);

  for(size_t y=0; y<h; ++y)
  {
    for(size_t x=0; x<w; ++x)
    {
      ASSERT_FLOAT_EQ(img_flt.at<float>(y, x), cu_img[y*w+x]);
    }
  }
  delete cu_img;
}
Example #27
0
TEST_F(CProfileTest, ReadTest)
{
    m_profile.SetUseCurrentDirectory(true);

    ASSERT_TRUE(m_profile.Init()); // load colobot.ini file

    std::string result;
    ASSERT_TRUE(m_profile.GetStringProperty("test_string", "string_value", result));
    ASSERT_STREQ("Hello world", result.c_str());

    int int_value;
    ASSERT_TRUE(m_profile.GetIntProperty("test_int", "int_value", int_value));
    ASSERT_EQ(42, int_value);

    float float_value;
    ASSERT_TRUE(m_profile.GetFloatProperty("test_float", "float_value", float_value));
    ASSERT_FLOAT_EQ(1.5, float_value);

    std::vector<std::string> list;
    list = m_profile.GetSection("test_multi", "entry");
    ASSERT_EQ(5u, list.size());
}
Example #28
0
TEST(RMSEstimatorDouble, TestRMSEstimatorSetAvgTime)
{
    double sinewave[10000];
    double out[10000];
    double out2[10000];
    for (unsigned i = 0; i < 10000; ++i)
    {
        sinewave[i] = sin((6000 * M_PI * i)/10000); // 3000Hz sinewave at 44100
    }
    RMSEstimatorD * rms = RMSEstimatorInitD(0.01, 10000);
    RMSEstimatorD * rms2 = RMSEstimatorInitD(0.05, 10000);
    RMSEstimatorSetAvgTimeD(rms2, 0.01);
    RMSEstimatorProcessD(rms, out, sinewave, 10000);
    RMSEstimatorProcessD(rms2, out2, sinewave, 10000);
    RMSEstimatorFreeD(rms);
    RMSEstimatorFreeD(rms2);
    for (unsigned i = 250; i < 10000; ++i)
    {
        ASSERT_FLOAT_EQ(out[i], out2[i]);
    }
    
}
    TEST(xphoto_DenoisingBm3dKaiserWindow, regression_8)
    {
        float beta = 2.0f;
        int N = 8;

        cv::Mat kaiserWindow;
        calcKaiserWindow1D(kaiserWindow, N, beta);

        float kaiser8[] = {
            0.43869004f,
            0.68134475f,
            0.87685609f,
            0.98582518f,
            0.98582518f,
            0.87685609f,
            0.68134463f,
            0.43869004f
        };

        for (int i = 0; i < N; ++i)
            ASSERT_FLOAT_EQ(kaiser8[i], kaiserWindow.at<float>(i));
    }
Example #30
0
TEST(util, crc) {
	ASSERT_EQ(4, efiRound(4.4, 1));
	ASSERT_FLOAT_EQ(1.2, efiRound(1.2345, 0.1));

	print("*************************************** testCrc\r\n");

	const char * A = "A";

	ASSERT_EQ( 168,  calc_crc((const crc_t *) A, 1)) << "crc8";
	uint32_t c = crc32(A, 1);
	printf("crc32(A)=%x\r\n", c);
	assertEqualsM("crc32 1", 0xd3d99e8b, c);

	const char * line = "AbcDEFGF";
	c = crc32(line, 8);
	printf("crc32(line)=%x\r\n", c);
	assertEqualsM("crc32 line", 0x4775a7b1, c);

	c = crc32(line, 1);
	c = crc32inc(line + 1, c, 8 - 1);
	assertEqualsM("crc32 line inc", 0x4775a7b1, c);
}