From dbdc2b9e8168f214e6622efecc7172c55bfac9e0 Mon Sep 17 00:00:00 2001 From: Francisco Montoto Date: Tue, 23 Aug 2016 18:45:19 -0300 Subject: [PATCH] add testing for k=3 --- test/k2_tree_test.cpp | 161 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 154 insertions(+), 7 deletions(-) diff --git a/test/k2_tree_test.cpp b/test/k2_tree_test.cpp index 65675828e..07e0a0209 100644 --- a/test/k2_tree_test.cpp +++ b/test/k2_tree_test.cpp @@ -1,10 +1,8 @@ #include "sdsl/k2_tree.hpp" #include "gtest/gtest.h" -// #include -// #include -// #include -// #include // for std::min. std::sort -// #include + +#include +#include namespace { @@ -18,7 +16,7 @@ template class k2_tree_test_k_2 : public ::testing::Test { }; template -class k2_tree_test_k_5 : public ::testing::Test { }; +class k2_tree_test_k_3 : public ::testing::Test { }; using testing::Types; @@ -40,6 +38,9 @@ namespace k2_tree_test_nm typedef Types< k2_tree<2, bit_vector, rank_support_v<>>> k_2_implementations; +typedef Types< + k2_tree<3, bit_vector, rank_support_v<>>> k_3_implementations; + TYPED_TEST_CASE(k2_tree_test_k_2, k_2_implementations); TYPED_TEST(k2_tree_test_k_2, build_from_matrix_test) @@ -118,7 +119,140 @@ TYPED_TEST(k2_tree_test_k_2, build_from_edges_array) { typedef std::tuple t_tuple; - vector> e; + vector> e; + + t_tuple a{0, 0}; + t_tuple b{0, 1}; + t_tuple c{1, 0}; + t_tuple d{1, 1}; + e.push_back(t_tuple {1, 2}); + TypeParam tree(e, 4); + + k2_tree_test_nm::check_t_l(tree, {0, 1, 0 ,0}, {0, 0, 1, 0}); + + tree = TypeParam(e, 3); + k2_tree_test_nm::check_t_l(tree, {0, 1, 0 ,0}, {0, 0, 1, 0}); + + e.push_back(t_tuple {1, 2}); + tree = TypeParam(e, 3); + k2_tree_test_nm::check_t_l(tree, {0, 1, 0 ,0}, {0, 0, 1, 0}); + + e.clear(); + e.push_back(t_tuple {0, 0}); + tree = TypeParam(e, 1); + k2_tree_test_nm::check_t_l(tree, {}, {1, 0, 0, 0}); + + e.push_back(t_tuple {0, 1}); + e.push_back(t_tuple {1, 0}); + e.push_back(t_tuple {1, 1}); + tree = TypeParam(e, 2); + k2_tree_test_nm::check_t_l(tree, {}, {1, 1, 1, 1}); + + e.push_back(t_tuple {2, 2}); + tree = TypeParam(e, 3); + k2_tree_test_nm::check_t_l(tree, {1, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 0, 0}); +} + + +TYPED_TEST_CASE(k2_tree_test_k_3, k_3_implementations); + +TYPED_TEST(k2_tree_test_k_3, build_from_matrix_test) +{ + vector> mat({{1, 1, 0, 0, 1}, + {0, 1, 0, 0, 0}, + {0, 0, 1, 1, 0}, + {1, 1, 0, 1, 0}, + {0, 0, 1, 0, 0}}); + + TypeParam tree(mat); + vector expected_t = {1, 1, 0, 1, 1, 0, 0, 0, 0}; + vector expected_l = {1, 1, 0, 0, 1, 0, 0, 0, 1, + 0, 1, 0, 0, 0, 0, 1, 0, 0, + 1, 1, 0, 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0}; + k2_tree_test_nm::check_t_l(tree, expected_t, expected_l); + + mat = vector>({{1, 1, 1, 0}, + {1, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}}); + + tree = TypeParam(mat); + expected_t = {1, 0, 0, 1, 0, 0, 0, 0, 0}; + expected_l = {1, 1, 1, 1, 0, 0, 0, 0, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 0}; + k2_tree_test_nm::check_t_l(tree, expected_t, expected_l); + + mat = vector>({{0, 0, 0}, + {0, 0, 0}, + {0, 0, 0}}); + tree = TypeParam(mat); + k2_tree_test_nm::check_t_l(tree, {}, {}); + + // Size is minor than k: + mat = vector>({{0}}); + tree = TypeParam(mat); + k2_tree_test_nm::check_t_l(tree, {}, {}); + + mat = vector>({{1}}); + tree = TypeParam(mat); + k2_tree_test_nm::check_t_l(tree, {}, {1, 0, 0, 0, 0, 0, 0, 0 ,0}); + + mat = vector>({{1, 0}, + {0, 1}}); + tree = TypeParam(mat); + k2_tree_test_nm::check_t_l(tree, {}, {1, 0, 0, 0, 1, 0, 0, 0 ,0}); + + // Size is a power of k: + mat = vector>({{0, 0, 1, 0, 0, 0, 0, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 1, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 0, 0, 0, 0, 0, 0}}); + tree = TypeParam(mat); + expected_t = {1, 0, 0, 0, 0, 0, 1, 0, 0}; + expected_l = {0, 0, 1, 1, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1}; + k2_tree_test_nm::check_t_l(tree, expected_t, expected_l); + + mat = vector>({{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}, + {0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1}, + {0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}}); + tree = TypeParam(mat); + expected_t = {1, 1, 0, 1, 1, 0, 0, 0, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0}; + + expected_l = {0, 1, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, + 1, 0, 1, 1, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 0, 0, 0, 0}; + k2_tree_test_nm::check_t_l(tree, expected_t, expected_l); +} +/* +TYPED_TEST(k2_tree_test_k_3, build_from_edges_array) +{ + typedef std::tuple t_tuple; + vector> e; t_tuple a{0, 0}; t_tuple b{0, 1}; @@ -140,7 +274,20 @@ TYPED_TEST(k2_tree_test_k_2, build_from_edges_array) e.push_back(t_tuple {0, 0}); tree = TypeParam(e, 1); k2_tree_test_nm::check_t_l(tree, {}, {1, 0, 0, 0}); + + e.push_back(t_tuple {0, 1}); + e.push_back(t_tuple {1, 0}); + e.push_back(t_tuple {1, 1}); + tree = TypeParam(e, 2); + k2_tree_test_nm::check_t_l(tree, {}, {1, 1, 1, 1}); + + e.push_back(t_tuple {2, 2}); + tree = TypeParam(e, 3); + k2_tree_test_nm::check_t_l(tree, {1, 0, 0, 1}, {1, 1, 1, 1, 1, 0, 0, 0}); } +*/ + + TYPED_TEST(k2_tree_test_k_2, neighbors_test) {