From 7905d787da9c506bf309efd56ed08ceff26a34a0 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Thu, 6 Oct 2016 15:59:01 +0200 Subject: [PATCH 1/9] Added tests for Opossum Table --- src/test/storage/table_test.cpp | 61 ++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/test/storage/table_test.cpp b/src/test/storage/table_test.cpp index a8d643b3c4..fc202f1a88 100644 --- a/src/test/storage/table_test.cpp +++ b/src/test/storage/table_test.cpp @@ -2,7 +2,66 @@ #include "../../lib/storage/table.hpp" -TEST(storage_table, has_one_chunk_after_creation) { +TEST(StorageTable, HasOneChunkAfterCreation) { opossum::Table t(2); EXPECT_EQ(t.chunk_count(), 1u); } + +class TableTest : public ::testing::Test { + protected: + virtual void SetUp() { + t = std::make_shared(opossum::Table(chunk_size)); + t->add_column("col_1", "int"); + t->add_column("col_2", "string"); + } + + uint32_t chunk_size = 2; + std::shared_ptr t = nullptr; +}; + +TEST_F(TableTest, AppendToTable) { + t->append({4, "Hello,"}); + t->append({6, "world"}); + t->append({3, "!"}); +} + +TEST_F(TableTest, Getters) { + // test col count + EXPECT_EQ(t->col_count(), 2u); + + // test row count + EXPECT_EQ(t->row_count(), 0u); + t->append({4, "Hello,"}); + t->append({6, "world"}); + t->append({3, "!"}); + EXPECT_EQ(t->row_count(), 3u); + + // test chunk count after append + EXPECT_EQ(t->chunk_count(), 2u); + + // test get_column* + std::string column_name = t->get_column_name(0); + EXPECT_EQ(column_name, "col_1"); + std::string column_type = t->get_column_type(0); + EXPECT_EQ(column_type, "int"); + + column_name = t->get_column_name(1); + EXPECT_EQ(column_name, "col_2"); + column_type = t->get_column_type(1); + EXPECT_EQ(column_type, "string"); + + // TODO: Do we want checks here? + // EXPECT_THROW(t->get_column_name(2), std::exception); + // EXPECT_THROW(t->get_column_type(2), std::exception); + + size_t column_id = t->get_column_id_by_name("col_2"); + EXPECT_EQ(column_id, 1u); + + EXPECT_THROW(t->get_column_id_by_name("no_column_name"), std::exception); + + // test get_chunk_size + size_t chunk_size = t->get_chunk_size(); + EXPECT_EQ(chunk_size, 2u); +} + +TEST_F(TableTest, CannotCopyTable) { EXPECT_THROW(opossum::Table t_copy(*t), std::exception); } From 70f1804a411327e7533ecc7e5dfb43cdde6cc8bf Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Thu, 6 Oct 2016 16:36:02 +0200 Subject: [PATCH 2/9] Simplified table tests --- src/test/storage/table_test.cpp | 61 +++++++++++++-------------------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/src/test/storage/table_test.cpp b/src/test/storage/table_test.cpp index fc202f1a88..ccb4902237 100644 --- a/src/test/storage/table_test.cpp +++ b/src/test/storage/table_test.cpp @@ -2,66 +2,53 @@ #include "../../lib/storage/table.hpp" -TEST(StorageTable, HasOneChunkAfterCreation) { - opossum::Table t(2); - EXPECT_EQ(t.chunk_count(), 1u); -} - class TableTest : public ::testing::Test { protected: virtual void SetUp() { - t = std::make_shared(opossum::Table(chunk_size)); - t->add_column("col_1", "int"); - t->add_column("col_2", "string"); + t.add_column("col_1", "int"); + t.add_column("col_2", "string"); } - uint32_t chunk_size = 2; - std::shared_ptr t = nullptr; + opossum::Table t{2}; }; +TEST_F(TableTest, HasOneChunkAfterCreation) { EXPECT_EQ(t.chunk_count(), 1u); } + TEST_F(TableTest, AppendToTable) { - t->append({4, "Hello,"}); - t->append({6, "world"}); - t->append({3, "!"}); + t.append({4, "Hello,"}); + t.append({6, "world"}); + t.append({3, "!"}); } TEST_F(TableTest, Getters) { // test col count - EXPECT_EQ(t->col_count(), 2u); + EXPECT_EQ(t.col_count(), 2u); // test row count - EXPECT_EQ(t->row_count(), 0u); - t->append({4, "Hello,"}); - t->append({6, "world"}); - t->append({3, "!"}); - EXPECT_EQ(t->row_count(), 3u); + EXPECT_EQ(t.row_count(), 0u); + t.append({4, "Hello,"}); + t.append({6, "world"}); + t.append({3, "!"}); + EXPECT_EQ(t.row_count(), 3u); // test chunk count after append - EXPECT_EQ(t->chunk_count(), 2u); + EXPECT_EQ(t.chunk_count(), 2u); // test get_column* - std::string column_name = t->get_column_name(0); - EXPECT_EQ(column_name, "col_1"); - std::string column_type = t->get_column_type(0); - EXPECT_EQ(column_type, "int"); + EXPECT_EQ(t.get_column_name(0), "col_1"); + EXPECT_EQ(t.get_column_type(0), "int"); - column_name = t->get_column_name(1); - EXPECT_EQ(column_name, "col_2"); - column_type = t->get_column_type(1); - EXPECT_EQ(column_type, "string"); + EXPECT_EQ(t.get_column_name(1), "col_2"); + EXPECT_EQ(t.get_column_type(1), "string"); // TODO: Do we want checks here? - // EXPECT_THROW(t->get_column_name(2), std::exception); - // EXPECT_THROW(t->get_column_type(2), std::exception); + // EXPECT_THROW(t.get_column_name(2), std::exception); + // EXPECT_THROW(t.get_column_type(2), std::exception); - size_t column_id = t->get_column_id_by_name("col_2"); - EXPECT_EQ(column_id, 1u); + EXPECT_EQ(t.get_column_id_by_name("col_2"), 1u); - EXPECT_THROW(t->get_column_id_by_name("no_column_name"), std::exception); + EXPECT_THROW(t.get_column_id_by_name("no_column_name"), std::exception); // test get_chunk_size - size_t chunk_size = t->get_chunk_size(); - EXPECT_EQ(chunk_size, 2u); + EXPECT_EQ(t.get_chunk_size(), 2u); } - -TEST_F(TableTest, CannotCopyTable) { EXPECT_THROW(opossum::Table t_copy(*t), std::exception); } From d3cc095fd72f5a58b667bd853700a75f57ef4fa8 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Thu, 6 Oct 2016 18:08:36 +0200 Subject: [PATCH 3/9] Added tests for Opossum Chunk --- src/test/storage/chunk_test.cpp | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/test/storage/chunk_test.cpp diff --git a/src/test/storage/chunk_test.cpp b/src/test/storage/chunk_test.cpp new file mode 100644 index 0000000000..1c694882e1 --- /dev/null +++ b/src/test/storage/chunk_test.cpp @@ -0,0 +1,52 @@ +#include "gtest/gtest.h" + +#include "../../lib/common.hpp" +#include "../../lib/storage/base_column.hpp" +#include "../../lib/storage/chunk.hpp" +#include "../../lib/types.hpp" + +class ChunkTest : public ::testing::Test { + protected: + virtual void SetUp() { + vc_int = opossum::make_shared_by_column_type("int"); + vc_int->append(4); + vc_int->append(6); + vc_int->append(3); + + vc_str = opossum::make_shared_by_column_type("string"); + vc_str->append("Hello,"); + vc_str->append("world"); + vc_str->append("!"); + } + + opossum::Chunk c; + std::shared_ptr vc_int = nullptr; + std::shared_ptr vc_str = nullptr; +}; + +TEST_F(ChunkTest, AddColumnToChunk) { + EXPECT_EQ(c.size(), 0u); + c.add_column(vc_int); + c.add_column(vc_str); + EXPECT_EQ(c.size(), 3u); +} + +TEST_F(ChunkTest, AddValuesToChunk) { + c.add_column(vc_int); + c.add_column(vc_str); + c.append({2, "two"}); + EXPECT_EQ(c.size(), 4u); + + EXPECT_THROW(c.append({}), std::exception); + EXPECT_THROW(c.append({4, "val", 3}), std::exception); + EXPECT_EQ(c.size(), 4u); +} + +TEST_F(ChunkTest, RetrieveColumn) { + c.add_column(vc_int); + c.add_column(vc_str); + c.append({2, "two"}); + + auto base_col = c.get_column(0); + EXPECT_EQ(base_col->size(), 4u); +} From b0c337fa84a4647a673076d090e3b6902c5eef42 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 17:05:32 +0200 Subject: [PATCH 4/9] Added tests for Opossum ValueColumn Fixed linting errors: missing includes --- src/test/storage/chunk_test.cpp | 2 ++ src/test/storage/table_test.cpp | 2 +- src/test/storage/value_column_test.cpp | 40 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/test/storage/value_column_test.cpp diff --git a/src/test/storage/chunk_test.cpp b/src/test/storage/chunk_test.cpp index 1c694882e1..44ddc210be 100644 --- a/src/test/storage/chunk_test.cpp +++ b/src/test/storage/chunk_test.cpp @@ -1,3 +1,5 @@ +#include + #include "gtest/gtest.h" #include "../../lib/common.hpp" diff --git a/src/test/storage/table_test.cpp b/src/test/storage/table_test.cpp index ccb4902237..81c953936b 100644 --- a/src/test/storage/table_test.cpp +++ b/src/test/storage/table_test.cpp @@ -41,7 +41,7 @@ TEST_F(TableTest, Getters) { EXPECT_EQ(t.get_column_name(1), "col_2"); EXPECT_EQ(t.get_column_type(1), "string"); - // TODO: Do we want checks here? + // TODO(anyone): Do we want checks here? // EXPECT_THROW(t.get_column_name(2), std::exception); // EXPECT_THROW(t.get_column_type(2), std::exception); diff --git a/src/test/storage/value_column_test.cpp b/src/test/storage/value_column_test.cpp new file mode 100644 index 0000000000..291ac740cc --- /dev/null +++ b/src/test/storage/value_column_test.cpp @@ -0,0 +1,40 @@ +#include + +#include "gtest/gtest.h" + +#include "../../lib/storage/value_column.hpp" + +TEST(ValueColumnTest, CreateColumn) { + // create column of different types + opossum::ValueColumn vc_int; + EXPECT_EQ(vc_int.size(), 0u); + + opossum::ValueColumn vc_str; + EXPECT_EQ(vc_str.size(), 0u); + + opossum::ValueColumn vc_double; + EXPECT_EQ(vc_double.size(), 0u); + + // add value of same type + vc_int.append(3); + EXPECT_EQ(vc_int.size(), 1u); + + vc_str.append("Hello"); + EXPECT_EQ(vc_str.size(), 1u); + + vc_double.append(3.14); + EXPECT_EQ(vc_double.size(), 1u); + + // add value of different type + vc_int.append(3.14); + EXPECT_EQ(vc_int.size(), 2u); + EXPECT_THROW(vc_int.append("Hi"), std::exception); + + vc_str.append(3); + vc_str.append(4.44); + EXPECT_EQ(vc_str.size(), 3u); + + vc_double.append(4); + EXPECT_EQ(vc_double.size(), 2u); + EXPECT_THROW(vc_double.append("Hi"), std::exception); +} From 46cc4099ae1c1bd096eabd2648a41991eb5f850c Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 17:49:21 +0200 Subject: [PATCH 5/9] Added tests for Opossum StorageManager --- src/test/storage/storage_manager_test.cpp | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/test/storage/storage_manager_test.cpp diff --git a/src/test/storage/storage_manager_test.cpp b/src/test/storage/storage_manager_test.cpp new file mode 100644 index 0000000000..873ad61273 --- /dev/null +++ b/src/test/storage/storage_manager_test.cpp @@ -0,0 +1,33 @@ +#include + +#include "gtest/gtest.h" + +#include "../../lib/storage/storage_manager.hpp" +#include "../../lib/storage/table.hpp" + +class StorageManagerTest : public ::testing::Test { + protected: + virtual void SetUp() { + auto &sm = opossum::StorageManager::get(); + auto t1 = std::make_shared(); + auto t2 = std::make_shared(4); + + sm.add_table("first_table", t1); + sm.add_table("second_table", t2); + } +}; + +TEST_F(StorageManagerTest, GetTable) { + auto &sm = opossum::StorageManager::get(); + auto t3 = sm.get_table("first_table"); + auto t4 = sm.get_table("second_table"); + EXPECT_THROW(sm.get_table("third_table"), std::exception); +} + +TEST_F(StorageManagerTest, DropTable) { + auto &sm = opossum::StorageManager::get(); + sm.drop_table("first_table"); + EXPECT_THROW(sm.get_table("first_table"), std::exception); + // TODO(MB): Should the StorageManager catch exceptions for get_table executed with unknown name? + // EXPECT_THROW(sm.drop_table("first_table"), std::exception); +} From 40c615bba761284beb7bdf6afcfe29ef7bf2a543 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 19:51:06 +0200 Subject: [PATCH 6/9] Unified testcase and test naming: CamelCase; testcases start with library name and end with "Test" --- src/test/operators/get_table_test.cpp | 6 +++--- src/test/operators/print_test.cpp | 8 ++++---- src/test/operators/projection_test.cpp | 8 ++++---- src/test/operators/sort_test.cpp | 8 ++++---- src/test/operators/table_scan_test.cpp | 12 ++++++------ src/test/storage/chunk_test.cpp | 8 ++++---- src/test/storage/storage_manager_test.cpp | 6 +++--- src/test/storage/table_test.cpp | 8 ++++---- src/test/storage/value_column_test.cpp | 2 +- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/test/operators/get_table_test.cpp b/src/test/operators/get_table_test.cpp index 4107266f3a..6e6e8c0df6 100644 --- a/src/test/operators/get_table_test.cpp +++ b/src/test/operators/get_table_test.cpp @@ -8,7 +8,7 @@ namespace opossum { // The fixture for testing class GetTable. -class operators_get_table : public ::testing::Test { +class OperatorsGetTableTest : public ::testing::Test { virtual void SetUp() { test_table = std::make_shared(opossum::Table(2)); opossum::StorageManager::get().add_table("aNiceTestTable", test_table); @@ -19,14 +19,14 @@ class operators_get_table : public ::testing::Test { std::shared_ptr test_table; }; -TEST_F(operators_get_table, get_output_returns_correct_table) { +TEST_F(OperatorsGetTableTest, GetOutput) { auto gt = std::make_shared("aNiceTestTable"); gt->execute(); EXPECT_EQ(gt->get_output(), test_table); } -TEST_F(operators_get_table, get_output_throwns_on_unknown_table_name) { +TEST_F(OperatorsGetTableTest, ThrowsUnknownTableName) { auto gt = std::make_shared("anUglyTestTable"); gt->execute(); diff --git a/src/test/operators/print_test.cpp b/src/test/operators/print_test.cpp index 88e5336a78..12e31bcd54 100644 --- a/src/test/operators/print_test.cpp +++ b/src/test/operators/print_test.cpp @@ -9,7 +9,7 @@ #include "../../lib/storage/storage_manager.hpp" #include "../../lib/storage/table.hpp" -class PrintOperatorTest : public ::testing::Test { +class OperatorsPrintTest : public ::testing::Test { protected: virtual void SetUp() { t = std::make_shared(opossum::Table(chunk_size)); @@ -41,7 +41,7 @@ class PrintWrapper : public opossum::Print { } }; -TEST_F(PrintOperatorTest, check_print_output_empty_table) { +TEST_F(OperatorsPrintTest, EmptyTable) { auto pr = std::make_shared(gt, output); pr->execute(); @@ -59,7 +59,7 @@ TEST_F(PrintOperatorTest, check_print_output_empty_table) { EXPECT_TRUE(output_str.find("Empty chunk.") != std::string::npos); } -TEST_F(PrintOperatorTest, check_print_output_filled_table) { +TEST_F(OperatorsPrintTest, FilledTable) { auto tab = opossum::StorageManager::get().get_table(table_name); for (size_t i = 0; i < chunk_size * 2; i++) { // char 97 is an 'a' @@ -88,7 +88,7 @@ TEST_F(PrintOperatorTest, check_print_output_filled_table) { // EXPECT_TRUE(output_str.find("Empty chunk.") != std::string::npos); } -TEST_F(PrintOperatorTest, get_column_widths) { +TEST_F(OperatorsPrintTest, GetColumnWidths) { uint16_t min = 8; uint16_t max = 20; diff --git a/src/test/operators/projection_test.cpp b/src/test/operators/projection_test.cpp index 650fd98fc3..91b74c8209 100644 --- a/src/test/operators/projection_test.cpp +++ b/src/test/operators/projection_test.cpp @@ -14,7 +14,7 @@ #include "../../lib/types.hpp" namespace opossum { -class operators_projection : public ::testing::Test { +class OperatorsProjectionTest : public ::testing::Test { virtual void SetUp() { test_table = std::make_shared(opossum::Table(2)); @@ -37,7 +37,7 @@ class operators_projection : public ::testing::Test { std::shared_ptr gt; }; -TEST_F(operators_projection, project_single_column) { +TEST_F(OperatorsProjectionTest, SingleColumn) { std::vector column_filter = {"a"}; auto projection = std::make_shared(gt, column_filter); projection->execute(); @@ -47,7 +47,7 @@ TEST_F(operators_projection, project_single_column) { EXPECT_THROW(projection->get_output()->get_column_id_by_name("b"), std::exception); } -TEST_F(operators_projection, double_project_single_column) { +TEST_F(OperatorsProjectionTest, DoubleProject) { std::vector column_filter = {"a"}; auto projection1 = std::make_shared(gt, column_filter); projection1->execute(); @@ -60,7 +60,7 @@ TEST_F(operators_projection, double_project_single_column) { EXPECT_THROW(projection2->get_output()->get_column_id_by_name("b"), std::exception); } -TEST_F(operators_projection, project_all_columns) { +TEST_F(OperatorsProjectionTest, AllColumns) { std::vector column_filter = {"a", "b"}; auto projection = std::make_shared(gt, column_filter); projection->execute(); diff --git a/src/test/operators/sort_test.cpp b/src/test/operators/sort_test.cpp index ddbc4350ea..6a6cb7d062 100644 --- a/src/test/operators/sort_test.cpp +++ b/src/test/operators/sort_test.cpp @@ -13,7 +13,7 @@ namespace opossum { -class operators_sort : public ::testing::Test { +class OperatorsSortTest : public ::testing::Test { virtual void SetUp() { _test_table = std::make_shared(opossum::Table(2)); @@ -36,7 +36,7 @@ class operators_sort : public ::testing::Test { std::shared_ptr _gt; }; -TEST_F(operators_sort, test_ascending_sort_of_one_column) { +TEST_F(OperatorsSortTest, AscendingSortOfOneColumn) { auto sort = std::make_shared(_gt, "a"); sort->execute(); @@ -45,7 +45,7 @@ TEST_F(operators_sort, test_ascending_sort_of_one_column) { EXPECT_EQ(type_cast((*(sort->get_output()->get_chunk(0).get_column(0)))[2]), 12345); } -TEST_F(operators_sort, test_double_sort_of_one_column) { +TEST_F(OperatorsSortTest, DoubleSortOfOneColumn) { auto sort1 = std::make_shared(_gt, "a", false); sort1->execute(); @@ -57,7 +57,7 @@ TEST_F(operators_sort, test_double_sort_of_one_column) { EXPECT_EQ(type_cast((*(sort2->get_output()->get_chunk(0).get_column(0)))[2]), 12345); } -TEST_F(operators_sort, test_descending_sort_of_one_column) { +TEST_F(OperatorsSortTest, DescendingSortOfOneColumn) { auto sort = std::make_shared(_gt, "a", false); sort->execute(); diff --git a/src/test/operators/table_scan_test.cpp b/src/test/operators/table_scan_test.cpp index 46f51f8533..aad9a5f3ce 100644 --- a/src/test/operators/table_scan_test.cpp +++ b/src/test/operators/table_scan_test.cpp @@ -14,7 +14,7 @@ namespace opossum { -class operators_table_scan : public ::testing::Test { +class OperatorsTableScanTest : public ::testing::Test { virtual void SetUp() { _test_table = std::make_shared(opossum::Table(2)); @@ -37,7 +37,7 @@ class operators_table_scan : public ::testing::Test { std::shared_ptr _gt; }; -TEST_F(operators_table_scan, double_scan_test) { +TEST_F(OperatorsTableScanTest, DoubleScan) { auto scan_1 = std::make_shared(_gt, "a", ">=", 1234); scan_1->execute(); @@ -49,7 +49,7 @@ TEST_F(operators_table_scan, double_scan_test) { EXPECT_EQ(scan_2->get_output()->row_count(), (u_int)1); } -class operators_table_scan_impl : public ::testing::Test { +class OperatorsTableScanImplTest : public ::testing::Test { virtual void SetUp() { _test_table = std::make_shared(opossum::Table(2)); @@ -72,7 +72,7 @@ class operators_table_scan_impl : public ::testing::Test { std::shared_ptr _gt; }; -TEST_F(operators_table_scan_impl, single_scan_returns_correct_row_count) { +TEST_F(OperatorsTableScanImplTest, SingleScanReturnsCorrectRowCount) { std::unique_ptr scan( make_unique_by_column_type("int", _gt, "a", ">=", 1234)); scan->execute(); @@ -83,14 +83,14 @@ TEST_F(operators_table_scan_impl, single_scan_returns_correct_row_count) { EXPECT_EQ(scan->get_output()->row_count(), (uint32_t)2); } -TEST_F(operators_table_scan_impl, unknown_operator_throws_exception) { +TEST_F(OperatorsTableScanImplTest, UnknownOperatorThrowsException) { std::unique_ptr scan( make_unique_by_column_type("int", _gt, "a", "xor", 10)); EXPECT_THROW(scan->execute(), std::exception); } -TEST_F(operators_table_scan_impl, unsorted_pos_list_in_reference_column) { +TEST_F(OperatorsTableScanImplTest, UnsortedPosListInReferenceColumn) { std::shared_ptr test_ref_table = std::make_shared(opossum::Table(2)); std::shared_ptr pos_list = std::make_shared(); diff --git a/src/test/storage/chunk_test.cpp b/src/test/storage/chunk_test.cpp index 44ddc210be..5e6f55027d 100644 --- a/src/test/storage/chunk_test.cpp +++ b/src/test/storage/chunk_test.cpp @@ -7,7 +7,7 @@ #include "../../lib/storage/chunk.hpp" #include "../../lib/types.hpp" -class ChunkTest : public ::testing::Test { +class StorageChunkTest : public ::testing::Test { protected: virtual void SetUp() { vc_int = opossum::make_shared_by_column_type("int"); @@ -26,14 +26,14 @@ class ChunkTest : public ::testing::Test { std::shared_ptr vc_str = nullptr; }; -TEST_F(ChunkTest, AddColumnToChunk) { +TEST_F(StorageChunkTest, AddColumnToChunk) { EXPECT_EQ(c.size(), 0u); c.add_column(vc_int); c.add_column(vc_str); EXPECT_EQ(c.size(), 3u); } -TEST_F(ChunkTest, AddValuesToChunk) { +TEST_F(StorageChunkTest, AddValuesToChunk) { c.add_column(vc_int); c.add_column(vc_str); c.append({2, "two"}); @@ -44,7 +44,7 @@ TEST_F(ChunkTest, AddValuesToChunk) { EXPECT_EQ(c.size(), 4u); } -TEST_F(ChunkTest, RetrieveColumn) { +TEST_F(StorageChunkTest, RetrieveColumn) { c.add_column(vc_int); c.add_column(vc_str); c.append({2, "two"}); diff --git a/src/test/storage/storage_manager_test.cpp b/src/test/storage/storage_manager_test.cpp index 873ad61273..91c03bfd43 100644 --- a/src/test/storage/storage_manager_test.cpp +++ b/src/test/storage/storage_manager_test.cpp @@ -5,7 +5,7 @@ #include "../../lib/storage/storage_manager.hpp" #include "../../lib/storage/table.hpp" -class StorageManagerTest : public ::testing::Test { +class StorageStorageManagerTest : public ::testing::Test { protected: virtual void SetUp() { auto &sm = opossum::StorageManager::get(); @@ -17,14 +17,14 @@ class StorageManagerTest : public ::testing::Test { } }; -TEST_F(StorageManagerTest, GetTable) { +TEST_F(StorageStorageManagerTest, GetTable) { auto &sm = opossum::StorageManager::get(); auto t3 = sm.get_table("first_table"); auto t4 = sm.get_table("second_table"); EXPECT_THROW(sm.get_table("third_table"), std::exception); } -TEST_F(StorageManagerTest, DropTable) { +TEST_F(StorageStorageManagerTest, DropTable) { auto &sm = opossum::StorageManager::get(); sm.drop_table("first_table"); EXPECT_THROW(sm.get_table("first_table"), std::exception); diff --git a/src/test/storage/table_test.cpp b/src/test/storage/table_test.cpp index 81c953936b..e10941533a 100644 --- a/src/test/storage/table_test.cpp +++ b/src/test/storage/table_test.cpp @@ -2,7 +2,7 @@ #include "../../lib/storage/table.hpp" -class TableTest : public ::testing::Test { +class StorageTableTest : public ::testing::Test { protected: virtual void SetUp() { t.add_column("col_1", "int"); @@ -12,15 +12,15 @@ class TableTest : public ::testing::Test { opossum::Table t{2}; }; -TEST_F(TableTest, HasOneChunkAfterCreation) { EXPECT_EQ(t.chunk_count(), 1u); } +TEST_F(StorageTableTest, HasOneChunkAfterCreation) { EXPECT_EQ(t.chunk_count(), 1u); } -TEST_F(TableTest, AppendToTable) { +TEST_F(StorageTableTest, AppendToTable) { t.append({4, "Hello,"}); t.append({6, "world"}); t.append({3, "!"}); } -TEST_F(TableTest, Getters) { +TEST_F(StorageTableTest, Getters) { // test col count EXPECT_EQ(t.col_count(), 2u); diff --git a/src/test/storage/value_column_test.cpp b/src/test/storage/value_column_test.cpp index 291ac740cc..d5bc34d669 100644 --- a/src/test/storage/value_column_test.cpp +++ b/src/test/storage/value_column_test.cpp @@ -4,7 +4,7 @@ #include "../../lib/storage/value_column.hpp" -TEST(ValueColumnTest, CreateColumn) { +TEST(StorageValueColumnTest, CreateColumn) { // create column of different types opossum::ValueColumn vc_int; EXPECT_EQ(vc_int.size(), 0u); From 666a8d16322e1b59091e887c8af781ebe9558379 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 20:19:07 +0200 Subject: [PATCH 7/9] Splitted up StorageTableTest into multiple testcases --- src/test/storage/table_test.cpp | 44 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/test/storage/table_test.cpp b/src/test/storage/table_test.cpp index e10941533a..93b5619023 100644 --- a/src/test/storage/table_test.cpp +++ b/src/test/storage/table_test.cpp @@ -12,43 +12,51 @@ class StorageTableTest : public ::testing::Test { opossum::Table t{2}; }; -TEST_F(StorageTableTest, HasOneChunkAfterCreation) { EXPECT_EQ(t.chunk_count(), 1u); } +TEST_F(StorageTableTest, ChunkCount) { + EXPECT_EQ(t.chunk_count(), 1u); + t.append({4, "Hello,"}); + t.append({6, "world"}); + t.append({3, "!"}); + EXPECT_EQ(t.chunk_count(), 2u); +} -TEST_F(StorageTableTest, AppendToTable) { +TEST_F(StorageTableTest, GetChunk) { + t.get_chunk(0); + // TODO(anyone): Do we want checks here? + // EXPECT_THROW(t.get_chunk(1), std::exception); t.append({4, "Hello,"}); t.append({6, "world"}); t.append({3, "!"}); + t.get_chunk(1); } -TEST_F(StorageTableTest, Getters) { - // test col count - EXPECT_EQ(t.col_count(), 2u); +TEST_F(StorageTableTest, ColCount) { EXPECT_EQ(t.col_count(), 2u); } - // test row count +TEST_F(StorageTableTest, RowCount) { EXPECT_EQ(t.row_count(), 0u); t.append({4, "Hello,"}); t.append({6, "world"}); t.append({3, "!"}); EXPECT_EQ(t.row_count(), 3u); +} - // test chunk count after append - EXPECT_EQ(t.chunk_count(), 2u); - - // test get_column* +TEST_F(StorageTableTest, GetColumnName) { EXPECT_EQ(t.get_column_name(0), "col_1"); - EXPECT_EQ(t.get_column_type(0), "int"); - EXPECT_EQ(t.get_column_name(1), "col_2"); - EXPECT_EQ(t.get_column_type(1), "string"); - // TODO(anyone): Do we want checks here? // EXPECT_THROW(t.get_column_name(2), std::exception); +} + +TEST_F(StorageTableTest, GetColumnType) { + EXPECT_EQ(t.get_column_type(0), "int"); + EXPECT_EQ(t.get_column_type(1), "string"); + // TODO(anyone): Do we want checks here? // EXPECT_THROW(t.get_column_type(2), std::exception); +} +TEST_F(StorageTableTest, GetColumnIdByName) { EXPECT_EQ(t.get_column_id_by_name("col_2"), 1u); - EXPECT_THROW(t.get_column_id_by_name("no_column_name"), std::exception); - - // test get_chunk_size - EXPECT_EQ(t.get_chunk_size(), 2u); } + +TEST_F(StorageTableTest, GetChunkSize) { EXPECT_EQ(t.get_chunk_size(), 2u); } From ee74cfcfae9eb4f71545523c95269a6a0faf18aa Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 20:25:56 +0200 Subject: [PATCH 8/9] Added TearDown for StorageStorageManagerTest --- src/test/storage/storage_manager_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/storage/storage_manager_test.cpp b/src/test/storage/storage_manager_test.cpp index 91c03bfd43..322ab2d701 100644 --- a/src/test/storage/storage_manager_test.cpp +++ b/src/test/storage/storage_manager_test.cpp @@ -15,6 +15,12 @@ class StorageStorageManagerTest : public ::testing::Test { sm.add_table("first_table", t1); sm.add_table("second_table", t2); } + + virtual void TearDown() { + auto &sm = opossum::StorageManager::get(); + sm.drop_table("first_table"); + sm.drop_table("second_table"); + } }; TEST_F(StorageStorageManagerTest, GetTable) { From e0e53982143495a490db3d732259c532b8857e55 Mon Sep 17 00:00:00 2001 From: Stefan Klauck Date: Fri, 7 Oct 2016 20:56:15 +0200 Subject: [PATCH 9/9] Splitted up StorageValueColumnTest into multiple testcases --- src/test/storage/value_column_test.cpp | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/test/storage/value_column_test.cpp b/src/test/storage/value_column_test.cpp index d5bc34d669..592bf74c43 100644 --- a/src/test/storage/value_column_test.cpp +++ b/src/test/storage/value_column_test.cpp @@ -1,21 +1,24 @@ #include +#include #include "gtest/gtest.h" #include "../../lib/storage/value_column.hpp" -TEST(StorageValueColumnTest, CreateColumn) { - // create column of different types +class StorageValueColumnTest : public ::testing::Test { + protected: opossum::ValueColumn vc_int; - EXPECT_EQ(vc_int.size(), 0u); - opossum::ValueColumn vc_str; - EXPECT_EQ(vc_str.size(), 0u); - opossum::ValueColumn vc_double; +}; + +TEST_F(StorageValueColumnTest, GetSize) { + EXPECT_EQ(vc_int.size(), 0u); + EXPECT_EQ(vc_str.size(), 0u); EXPECT_EQ(vc_double.size(), 0u); +} - // add value of same type +TEST_F(StorageValueColumnTest, AddValueOfSameType) { vc_int.append(3); EXPECT_EQ(vc_int.size(), 1u); @@ -24,17 +27,29 @@ TEST(StorageValueColumnTest, CreateColumn) { vc_double.append(3.14); EXPECT_EQ(vc_double.size(), 1u); +} - // add value of different type +TEST_F(StorageValueColumnTest, AddValueOfDifferentType) { vc_int.append(3.14); - EXPECT_EQ(vc_int.size(), 2u); + EXPECT_EQ(vc_int.size(), 1u); EXPECT_THROW(vc_int.append("Hi"), std::exception); vc_str.append(3); vc_str.append(4.44); - EXPECT_EQ(vc_str.size(), 3u); + EXPECT_EQ(vc_str.size(), 2u); vc_double.append(4); - EXPECT_EQ(vc_double.size(), 2u); + EXPECT_EQ(vc_double.size(), 1u); EXPECT_THROW(vc_double.append("Hi"), std::exception); } + +TEST_F(StorageValueColumnTest, RetrieveValue) { + vc_int.append(3); + EXPECT_EQ(vc_int.get_values()[0], 3); + + vc_str.append("Hello"); + EXPECT_EQ(vc_str.get_values()[0], "Hello"); + + vc_double.append(3.14); + EXPECT_EQ(vc_double.get_values()[0], 3.14); +}