Ejemplo n.º 1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, CopyData)
{
    DoubleArray a;

    a.resize(6);

    a[0] = 1.23;
    a[1] = 4.56;
    a[2] = 7.89;

    double data[] = { 3.2, 1.0, 0.0 };
    
    a.copyData(data, 3, 3);

    ASSERT_DOUBLE_EQ(3.2, a[3]);
    ASSERT_DOUBLE_EQ(1.0, a[4]);
    ASSERT_DOUBLE_EQ(0.0, a[5]);

    DoubleArray b;
    b.resize(3);
    b[0] = 10.0;
    b[1] = 20.0;
    b[2] = 30.0;

    a.copyData(b, b.size(), 2, 0);

    ASSERT_DOUBLE_EQ(1.23, a[0]);
    ASSERT_DOUBLE_EQ(4.56, a[1]);
    ASSERT_DOUBLE_EQ(10.0, a[2]);
    ASSERT_DOUBLE_EQ(20.0, a[3]);
    ASSERT_DOUBLE_EQ(30.0, a[4]);
    ASSERT_DOUBLE_EQ(0.0, a[5]);
}
Ejemplo n.º 2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, CopyConvertedData)
{
    // Double array to float
    {
        DoubleArray ad;
        ad.resize(4);
        ad[0] = 0.0;
        ad[1] = 1.0;
        ad[2] = 2.0;
        ad[3] = 3.0;

        // Copy full array
        FloatArray af;
        af.resize(4);
        af.copyConvertedData(ad, 4, 0, 0);
        EXPECT_FLOAT_EQ(0.0f, af[0]);
        EXPECT_FLOAT_EQ(1.0f, af[1]);
        EXPECT_FLOAT_EQ(2.0f, af[2]);
        EXPECT_FLOAT_EQ(3.0f, af[3]);

        // Copy partial array to float array
        af.resize(2);
        af.setAll(0);
        af.copyConvertedData(ad, 2, 0, 1);

        EXPECT_FLOAT_EQ(1.0f, af[0]);
        EXPECT_FLOAT_EQ(2.0f, af[1]);
    }

    // Vec3d to Vec3f and Vec3i
    {
        Vec3dArray ad;
        ad.resize(2);
        ad[0].set(1.1, 2.5, 3.9);
        ad[1].set(11.1, 12.5, 13.9);

        Vec3fArray af;
        af.resize(2);
        af.copyConvertedData(ad, 2, 0, 0);
        EXPECT_FLOAT_EQ(1.1f,  af[0].x());
        EXPECT_FLOAT_EQ(2.5f,  af[0].y());
        EXPECT_FLOAT_EQ(3.9f,  af[0].z());
        EXPECT_FLOAT_EQ(11.1f, af[1].x());
        EXPECT_FLOAT_EQ(12.5f, af[1].y());
        EXPECT_FLOAT_EQ(13.9f, af[1].z());

        Array<Vec3i> ai;
        ai.resize(2);
        ai.copyConvertedData(ad, 2, 0, 0);
        EXPECT_EQ(1,  ai[0].x());
        EXPECT_EQ(2,  ai[0].y());
        EXPECT_EQ(3,  ai[0].z());
        EXPECT_EQ(11, ai[1].x());
        EXPECT_EQ(12, ai[1].y());
        EXPECT_EQ(13, ai[1].z());
    }
}