Skip to content

Commit

Permalink
Merge pull request #1151 from lambday/develop
Browse files Browse the repository at this point in the history
complex64_t unit-tests added for TParameter
  • Loading branch information
iglesias committed Jun 6, 2013
2 parents e496115 + 43c4b4e commit 44c8ae8
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 7 deletions.
141 changes: 137 additions & 4 deletions tests/unit/base/Parameter_unittest.cc
Expand Up @@ -118,6 +118,18 @@ TEST(TParameter,compare_ptype_null2)
EXPECT_FALSE(TParameter::compare_ptype(PT_FLOAT64, &a, NULL));
}

TEST(TParameter,compare_ptype_null3)
{
complex64_t a(0.0);
EXPECT_FALSE(TParameter::compare_ptype(PT_COMPLEX64, &a, NULL));
}

TEST(TParameter,compare_ptype_null4)
{
complex64_t a(0.0);
EXPECT_FALSE(TParameter::compare_ptype(PT_COMPLEX64, NULL, &a));
}

TEST(TParameter,compare_ptype_BOOL)
{
bool a=true;
Expand Down Expand Up @@ -209,6 +221,13 @@ TEST(TParameter,compare_ptype_FLOATMAX)
EXPECT_FALSE(TParameter::compare_ptype(PT_FLOATMAX, &a, &b));
}

TEST(TParameter,compare_ptype_COMPLEX64)
{
complex64_t a(1.0);
complex64_t b(2.0);
EXPECT_FALSE(TParameter::compare_ptype(PT_COMPLEX64, &a, &b));
}

TEST(TParameter,compare_ptype_SGOBJECT)
{
CBinaryLabels* a=new CBinaryLabels(10);
Expand Down Expand Up @@ -251,6 +270,22 @@ TEST(TParameter,equals_scalar_different2)
delete param2;
}

TEST(TParameter,equals_scalar_different3)
{
complex64_t a(1.0, 1.0);
complex64_t b(1.5, 1.5);
float64_t accuracy=0.2;

TSGDataType type(CT_SCALAR, ST_NONE, PT_COMPLEX64);
TParameter* param1=new TParameter(&type, &a, "", "");
TParameter* param2=new TParameter(&type, &b, "", "");

EXPECT_FALSE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_scalar_equal1)
{
int32_t a=1;
Expand Down Expand Up @@ -282,7 +317,23 @@ TEST(TParameter,equals_scalar_equal2)
delete param2;
}

TEST(TParameter,equals_vector_different)
TEST(TParameter,equals_scalar_equal3)
{
complex64_t a(1.0, 1.0);
complex64_t b(1.2, 1.2);
float64_t accuracy=0.2;

TSGDataType type(CT_SCALAR, ST_NONE, PT_COMPLEX64);
TParameter* param1=new TParameter(&type, &a, "", "");
TParameter* param2=new TParameter(&type, &b, "", "");

EXPECT_TRUE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_vector_different1)
{
SGVector<float64_t> a(2);
SGVector<float64_t> b(2);
Expand All @@ -303,7 +354,28 @@ TEST(TParameter,equals_vector_different)
delete param2;
}

TEST(TParameter,equals_vector_equal)
TEST(TParameter,equals_vector_different2)
{
SGVector<complex64_t> a(2);
SGVector<complex64_t> b(2);
float64_t accuracy=0.1;

a[0]=complex64_t(1.0, 1.0);
b[0]=complex64_t(1.0, 1.0);
a[1]=complex64_t(1.0, 1.0);
b[1]=complex64_t(1.11, 1.11);

TSGDataType type(CT_SGVECTOR, ST_NONE, PT_COMPLEX64, &a.vlen);
TParameter* param1=new TParameter(&type, &a.vector, "", "");
TParameter* param2=new TParameter(&type, &b.vector, "", "");

EXPECT_FALSE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_vector_equal1)
{
SGVector<float64_t> a(2);
SGVector<float64_t> b(2);
Expand All @@ -324,7 +396,28 @@ TEST(TParameter,equals_vector_equal)
delete param2;
}

TEST(TParameter,equals_matrix_different)
TEST(TParameter,equals_vector_equal2)
{
SGVector<complex64_t> a(2);
SGVector<complex64_t> b(2);
float64_t accuracy=0.1;

a[0]=complex64_t(1.0, 1.0);
b[0]=complex64_t(1.0, 1.0);
a[1]=complex64_t(1.0, 1.0);
b[1]=complex64_t(1.01, 1.01);

TSGDataType type(CT_SGVECTOR, ST_NONE, PT_COMPLEX64, &a.vlen);
TParameter* param1=new TParameter(&type, &a.vector, "", "");
TParameter* param2=new TParameter(&type, &b.vector, "", "");

EXPECT_TRUE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_matrix_different1)
{
SGMatrix<float64_t> a(2,2);
SGMatrix<float64_t> b(2,2);
Expand All @@ -344,7 +437,27 @@ TEST(TParameter,equals_matrix_different)
delete param2;
}

TEST(TParameter,equals_matrix_equal)
TEST(TParameter,equals_matrix_different2)
{
SGMatrix<complex64_t> a(2,2);
SGMatrix<complex64_t> b(2,2);
float64_t accuracy=0.1;

a.set_const(complex64_t(1.0, 1.0));
b.set_const(complex64_t(1.0, 1.0));
b(1,1)=complex64_t(1.11, 1.11);

TSGDataType type(CT_SGMATRIX, ST_NONE, PT_COMPLEX64, &a.num_rows, &a.num_cols);
TParameter* param1=new TParameter(&type, &a.matrix, "", "");
TParameter* param2=new TParameter(&type, &b.matrix, "", "");

EXPECT_FALSE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_matrix_equal1)
{
SGMatrix<float64_t> a(2,2);
SGMatrix<float64_t> b(2,2);
Expand All @@ -364,6 +477,26 @@ TEST(TParameter,equals_matrix_equal)
delete param2;
}

TEST(TParameter,equals_matrix_equal2)
{
SGMatrix<complex64_t> a(2,2);
SGMatrix<complex64_t> b(2,2);
float64_t accuracy=0.1;

a.set_const(complex64_t(1.0, 1.0));
b.set_const(complex64_t(1.0, 1.0));
b(1,1)=complex64_t(1.01, 1.01);

TSGDataType type(CT_SGMATRIX, ST_NONE, PT_COMPLEX64, &a.num_rows, &a.num_cols);
TParameter* param1=new TParameter(&type, &a.matrix, "", "");
TParameter* param2=new TParameter(&type, &b.matrix, "", "");

EXPECT_TRUE(param1->equals(param2, accuracy));

delete param1;
delete param2;
}

TEST(TParameter,equals_string_scalar_different)
{
SGVector<float64_t> a(2);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/mathematics/Math_unittest.cc
Expand Up @@ -86,14 +86,14 @@ TEST(CMath, float64_tests)

float64_t a=5.78123516567856743364;
// x^2, x^(1/2)
EXPECT_NEAR(CMath::sq(a), 33.42268004087848964900, 1E-15);
EXPECT_NEAR(CMath::sq(a), 33.42268004087848964900, 1E-15);
EXPECT_NEAR(CMath::sqrt(33.42268004087848964900), a, 1E-15);
EXPECT_NEAR(CMath::pow(a, 2), 33.42268004087848964900, 1E-15);
EXPECT_NEAR(CMath::pow(a, 2), 33.42268004087848964900, 1E-15);
EXPECT_NEAR(CMath::pow(33.42268004087848964900, 0.5), a, 1E-15);

// e^x, log_{b}(x)
EXPECT_NEAR(CMath::exp(a), 324.15933372813628920994, 1E-15);
EXPECT_NEAR(CMath::log2(a), 2.53137775864743908016, 1E-15);
EXPECT_NEAR(CMath::log2(a), 2.53137775864743908016, 1E-15);
EXPECT_NEAR(CMath::log10(a), 0.76202063570953693095, 1E-15);

// exp and log identities
Expand Down

0 comments on commit 44c8ae8

Please sign in to comment.