Skip to content

Commit

Permalink
Extended constant tests with vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mcopik committed Sep 5, 2017
1 parent 531f98d commit 5994adc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/generator/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ GENERATE_LOWER_TRIANGULAR_TEST(constant_test, small, test_settings<>::small_sq_s
GENERATE_LOWER_TRIANGULAR_TEST(constant_test, medium, test_settings<>::medium_sq_sizes, generator::property::constant(3.14))
GENERATE_DIAGONAL_TEST(constant_test, small, test_settings<>::small_sq_sizes, generator::property::constant(3.14))
GENERATE_DIAGONAL_TEST(constant_test, medium, test_settings<>::medium_sq_sizes, generator::property::constant(3.14))
GENERATE_ROW_VECTOR_TEST(constant_test, small, test_settings<>::row_vector_sizes, generator::property::constant(3.14))
GENERATE_COL_VECTOR_TEST(constant_test, medium, test_settings<>::col_vector_sizes, generator::property::constant(3.14))

template<typename Types>
struct zeros_test : public testing::Test
Expand All @@ -54,6 +56,8 @@ GENERATE_LOWER_TRIANGULAR_TEST(zeros_test, small, test_settings<>::small_sq_size
GENERATE_LOWER_TRIANGULAR_TEST(zeros_test, medium, test_settings<>::medium_sq_sizes, generator::property::zeros())
GENERATE_DIAGONAL_TEST(zeros_test, small, test_settings<>::small_sq_sizes, generator::property::zeros())
GENERATE_DIAGONAL_TEST(zeros_test, medium, test_settings<>::medium_sq_sizes, generator::property::zeros())
GENERATE_ROW_VECTOR_TEST(zeros_test, small, test_settings<>::row_vector_sizes, generator::property::zeros())
GENERATE_COL_VECTOR_TEST(zeros_test, medium, test_settings<>::col_vector_sizes, generator::property::zeros())

template<typename Types>
struct ones_test : public testing::Test
Expand All @@ -75,6 +79,8 @@ GENERATE_LOWER_TRIANGULAR_TEST(ones_test, small, test_settings<>::small_sq_sizes
GENERATE_LOWER_TRIANGULAR_TEST(ones_test, medium, test_settings<>::medium_sq_sizes, generator::property::ones())
GENERATE_DIAGONAL_TEST(ones_test, small, test_settings<>::small_sq_sizes, generator::property::ones())
GENERATE_DIAGONAL_TEST(ones_test, medium, test_settings<>::medium_sq_sizes, generator::property::ones())
GENERATE_ROW_VECTOR_TEST(ones_test, small, test_settings<>::row_vector_sizes, generator::property::ones())
GENERATE_COL_VECTOR_TEST(ones_test, medium, test_settings<>::col_vector_sizes, generator::property::ones())


int main(int argc, char **argv) {
Expand Down
44 changes: 44 additions & 0 deletions tests/generator/test_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,20 @@ struct test_settings<>
static constexpr std::array< std::tuple<uint32_t, uint32_t>, 3> medium_sq_sizes{
{make_tuple(100, 100), make_tuple(103, 103), std::make_tuple(125, 125)}
};
static constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> row_vector_sizes{
{make_tuple(1, 1), make_tuple(1, 2), make_tuple(1, 53), make_tuple(1, 200)}
};
static constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> col_vector_sizes{
{make_tuple(1, 1), make_tuple(2, 1), make_tuple(53, 1), make_tuple(200, 1)}
};
};

constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> test_settings<>::small_sizes;
constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> test_settings<>::small_sq_sizes;
constexpr std::array< std::tuple<uint32_t, uint32_t>, 2> test_settings<>::medium_sizes;
constexpr std::array< std::tuple<uint32_t, uint32_t>, 3> test_settings<>::medium_sq_sizes;
constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> test_settings<>::row_vector_sizes;
constexpr std::array< std::tuple<uint32_t, uint32_t>, 4> test_settings<>::col_vector_sizes;

/// The additional template parameter is used because matrix access operator() may return
/// an object with type other than a usual floating-point type. Example is DiagonalProxy in
Expand Down Expand Up @@ -236,6 +244,36 @@ void verify_diagonal(MatType && mat, uint32_t rows, uint32_t, Properties &&... p
}
}

template<typename MatType, typename ... Properties>
void verify_row_vec(MatType && mat, uint32_t, uint32_t cols, Properties &&... props)
{
typedef traits::matrix_traits< std::remove_reference_t<MatType> > traits_t;
typedef typename traits_t::value_t value_t;

EXPECT_EQ(traits_t::rows(mat), 1);
EXPECT_EQ(traits_t::columns(mat), cols);

for(uint32_t i = 0; i < cols; ++i) {
// the existence of traits method taking only one index verifies that MatType is indeed a vector
verify<value_t>(traits_t::get(mat, i), std::forward<Properties>(props)...);
}
}

template<typename MatType, typename ... Properties>
void verify_col_vec(MatType && mat, uint32_t rows, uint32_t, Properties &&... props)
{
typedef traits::matrix_traits< std::remove_reference_t<MatType> > traits_t;
typedef typename traits_t::value_t value_t;

EXPECT_EQ(traits_t::rows(mat), rows);
EXPECT_EQ(traits_t::columns(mat), 1);

for(uint32_t i = 0; i < rows; ++i) {
// the existence of traits method taking only one index verifies that MatType is indeed a vector
verify<value_t>(traits_t::get(mat, i), std::forward<Properties>(props)...);
}
}

#define GENERATE_MATRIX_TEST(test_case_name, shape, verify_func, name_type, name, sizes_obj, ...) \
TYPED_TEST(test_case_name, name_type##_test_##name) { \
for(auto & sizes : sizes_obj) \
Expand Down Expand Up @@ -272,5 +310,11 @@ TYPED_TEST(test_case_name, name_type##_test_##name) { \
#define GENERATE_DIAGONAL_TEST(test_case_name, name, sizes_obj, ...) \
GENERATE_MATRIX_TEST(test_case_name, generator::shape::diagonal, verify_diagonal, diagonal, name, sizes_obj, __VA_ARGS__)

#define GENERATE_ROW_VECTOR_TEST(test_case_name, name, sizes_obj, ...) \
GENERATE_MATRIX_TEST(test_case_name, generator::shape::row_vector, verify_row_vec, row_vec, name, sizes_obj, __VA_ARGS__)

#define GENERATE_COL_VECTOR_TEST(test_case_name, name, sizes_obj, ...) \
GENERATE_MATRIX_TEST(test_case_name, generator::shape::col_vector, verify_col_vec, col_vec, name, sizes_obj, __VA_ARGS__)


#endif

0 comments on commit 5994adc

Please sign in to comment.