Skip to content

Commit

Permalink
Use assert_eq, use matrix instead of raw array
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored and vigsterkr committed Jul 11, 2018
1 parent c492857 commit d53dc1c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/unit/preprocessor/NormOne_unittest.cc
Expand Up @@ -17,15 +17,17 @@ class NormOne : public ::testing::Test
: feats(Some<CDenseFeatures<float64_t>>::from_raw(nullptr)),
transformer(some<CNormOne>())
{
SGMatrix<float64_t> m(data, num_features, num_vectors, false);
m = m.clone();
feats = some<CDenseFeatures<float64_t>>(m);
matrix = SGMatrix<float64_t>(data, num_features, num_vectors, false);
auto cloned_matrix = matrix.clone();
feats = some<CDenseFeatures<float64_t>>(cloned_matrix);
}

protected:
float64_t data[6] = {1, 2, 3, 4, 5, 6};
float64_t norm[2] = {std::sqrt(1 + 2 * 2 + 3 * 3),
std::sqrt(4 * 4 + 5 * 5 + 6 * 6)};
SGMatrix<float64_t> matrix;

int32_t num_vectors = 2;
int32_t num_features = 3;

Expand All @@ -39,15 +41,15 @@ TEST_F(NormOne, transform)
feats =
wrap(transformer->transform(feats)->as<CDenseFeatures<float64_t>>());

EXPECT_EQ(feats->get_num_vectors(), num_vectors);
ASSERT_EQ(feats->get_num_vectors(), num_vectors);

for (auto i : range(num_vectors))
{
SGVector<float64_t> v = feats->get_feature_vector(i);
EXPECT_EQ(v.vlen, num_features);
ASSERT_EQ(v.vlen, num_features);
for (auto j : range(v.vlen))
{
EXPECT_DOUBLE_EQ(v[j], data[num_features * i + j] / norm[i]);
EXPECT_DOUBLE_EQ(v[j], matrix(j, i) / norm[i]);
}
}
}
Expand All @@ -60,10 +62,10 @@ TEST_F(NormOne, apply_to_vector)
{
SGVector<float64_t> v = feats->get_feature_vector(i);
auto result = transformer->apply_to_feature_vector(v);
EXPECT_EQ(result.vlen, num_features);
ASSERT_EQ(result.vlen, num_features);
for (auto j : range(v.vlen))
{
EXPECT_DOUBLE_EQ(result[j], data[num_features * i + j] / norm[i]);
EXPECT_DOUBLE_EQ(result[j], matrix(j, i) / norm[i]);
}
}
}

0 comments on commit d53dc1c

Please sign in to comment.