From 70414b611b29349ff3bb0fa7fa3b1ab520f7f20f Mon Sep 17 00:00:00 2001 From: Shunsuke Kanda Date: Sun, 11 Jul 2021 13:06:23 +0900 Subject: [PATCH] add exception tests --- tests/test_bc_vector.cpp | 8 ++++++-- tests/test_trie.cpp | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/tests/test_bc_vector.cpp b/tests/test_bc_vector.cpp index cdcf98e..b543582 100644 --- a/tests/test_bc_vector.cpp +++ b/tests/test_bc_vector.cpp @@ -12,12 +12,16 @@ #ifdef BC_VECTOR_7 using bc_vector_type = xcdat::bc_vector_7; +#define BC_NAME "xcdat::bc_vector_7" #elif BC_VECTOR_8 using bc_vector_type = xcdat::bc_vector_8; +#define BC_NAME "xcdat::bc_vector_8" #elif BC_VECTOR_15 using bc_vector_type = xcdat::bc_vector_15; +#define BC_NAME "xcdat::bc_vector_15" #elif BC_VECTOR_16 using bc_vector_type = xcdat::bc_vector_16; +#define BC_NAME "xcdat::bc_vector_16" #endif struct bc_unit { @@ -66,14 +70,14 @@ void test_bc_vector(const std::vector& bc_units, const std::vector load_strings(const std::string& filepath, char delim = '\n') { @@ -148,7 +152,7 @@ void test_io(const trie_type& trie, const std::vector& keys, const std::remove(tmp_filepath); } -TEST_CASE("Test trie_type (tiny)") { +TEST_CASE("Test " TRIE_NAME " (tiny)") { std::vector keys = { "AirPods", "AirTag", "Mac", "MacBook", "MacBook_Air", "MacBook_Pro", "Mac_Mini", "Mac_Pro", "iMac", "iPad", "iPhone", "iPhone_SE", @@ -195,7 +199,27 @@ TEST_CASE("Test trie_type (tiny)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (real)") { +TEST_CASE("Test " TRIE_NAME " (unsort)") { + std::vector keys = { + "AirPods", "AirTag", "Mac", "MacBook", "MacBook_Pro", "MacBook_Air", + "Mac_Mini", "Mac_Pro", "iMac", "iPad", "iPhone", "iPhone_SE", + }; + + auto func = [&]() { auto trie = trie_type(keys); }; + REQUIRE_THROWS_AS(func(), const xcdat::exception&); +} + +TEST_CASE("Test " TRIE_NAME " (not unique)") { + std::vector keys = { + "AirPods", "AirTag", "Mac", "MacBook", "MacBook", "MacBook_Pro", + "Mac_Mini", "Mac_Pro", "iMac", "iPad", "iPhone", "iPhone_SE", + }; + + auto func = [&]() { auto trie = trie_type(keys); }; + REQUIRE_THROWS_AS(func(), const xcdat::exception&); +} + +TEST_CASE("Test " TRIE_NAME " (real)") { auto keys = xcdat::test::to_unique_vec(load_strings("keys.txt")); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 100); @@ -210,7 +234,7 @@ TEST_CASE("Test trie_type (real)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (random 10K, A--B)") { +TEST_CASE("Test " TRIE_NAME " (random 10K, A--B)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(10000, 1, 30, 'A', 'B')); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 100); @@ -225,7 +249,7 @@ TEST_CASE("Test trie_type (random 10K, A--B)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (random 10K, A--Z)") { +TEST_CASE("Test " TRIE_NAME " (random 10K, A--Z)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(10000, 1, 30, 'A', 'Z')); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 100); @@ -240,7 +264,7 @@ TEST_CASE("Test trie_type (random 10K, A--Z)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (random 10K, 0x00--0xFF)") { +TEST_CASE("Test " TRIE_NAME " (random 10K, 0x00--0xFF)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(10000, 1, 30, INT8_MIN, INT8_MAX)); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 100); @@ -256,7 +280,7 @@ TEST_CASE("Test trie_type (random 10K, 0x00--0xFF)") { } #ifdef NDEBUG -TEST_CASE("Test trie_type (random 100K, A--B)") { +TEST_CASE("Test " TRIE_NAME " (random 100K, A--B)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(100000, 1, 30, 'A', 'B')); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 1000); @@ -271,7 +295,7 @@ TEST_CASE("Test trie_type (random 100K, A--B)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (random 100K, A--Z)") { +TEST_CASE("Test " TRIE_NAME " (random 100K, A--Z)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(100000, 1, 30, 'A', 'Z')); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 1000); @@ -286,7 +310,7 @@ TEST_CASE("Test trie_type (random 100K, A--Z)") { test_io(trie, keys, others); } -TEST_CASE("Test trie_type (random 100K, 0x00--0xFF)") { +TEST_CASE("Test " TRIE_NAME " (random 100K, 0x00--0xFF)") { auto keys = xcdat::test::to_unique_vec(xcdat::test::make_random_keys(100000, 1, 30, INT8_MIN, INT8_MAX)); auto others = xcdat::test::extract_keys(keys); auto queries = xcdat::test::sample_keys(keys, 1000);