Skip to content

Commit

Permalink
Merge branch '21-tests' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Tests für 1. Arbeitspaket"

Closes #21

See merge request !10
  • Loading branch information
mrks committed Oct 11, 2016
2 parents 73c6abc + e0e5398 commit c127012
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/test/operators/get_table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(opossum::Table(2));
opossum::StorageManager::get().add_table("aNiceTestTable", test_table);
Expand All @@ -19,14 +19,14 @@ class operators_get_table : public ::testing::Test {
std::shared_ptr<opossum::Table> test_table;
};

TEST_F(operators_get_table, get_output_returns_correct_table) {
TEST_F(OperatorsGetTableTest, GetOutput) {
auto gt = std::make_shared<opossum::GetTable>("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<opossum::GetTable>("anUglyTestTable");
gt->execute();

Expand Down
8 changes: 4 additions & 4 deletions src/test/operators/print_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(opossum::Table(chunk_size));
Expand Down Expand Up @@ -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<opossum::Print>(gt, output);
pr->execute();

Expand All @@ -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'
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/test/operators/projection_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Table>(opossum::Table(2));

Expand All @@ -37,7 +37,7 @@ class operators_projection : public ::testing::Test {
std::shared_ptr<opossum::GetTable> gt;
};

TEST_F(operators_projection, project_single_column) {
TEST_F(OperatorsProjectionTest, SingleColumn) {
std::vector<std::string> column_filter = {"a"};
auto projection = std::make_shared<Projection>(gt, column_filter);
projection->execute();
Expand All @@ -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<std::string> column_filter = {"a"};
auto projection1 = std::make_shared<Projection>(gt, column_filter);
projection1->execute();
Expand All @@ -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<std::string> column_filter = {"a", "b"};
auto projection = std::make_shared<Projection>(gt, column_filter);
projection->execute();
Expand Down
8 changes: 4 additions & 4 deletions src/test/operators/sort_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(opossum::Table(2));

Expand All @@ -36,7 +36,7 @@ class operators_sort : public ::testing::Test {
std::shared_ptr<opossum::GetTable> _gt;
};

TEST_F(operators_sort, test_ascending_sort_of_one_column) {
TEST_F(OperatorsSortTest, AscendingSortOfOneColumn) {
auto sort = std::make_shared<Sort>(_gt, "a");
sort->execute();

Expand All @@ -45,7 +45,7 @@ TEST_F(operators_sort, test_ascending_sort_of_one_column) {
EXPECT_EQ(type_cast<int>((*(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<Sort>(_gt, "a", false);
sort1->execute();

Expand All @@ -57,7 +57,7 @@ TEST_F(operators_sort, test_double_sort_of_one_column) {
EXPECT_EQ(type_cast<int>((*(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<Sort>(_gt, "a", false);
sort->execute();

Expand Down
12 changes: 6 additions & 6 deletions src/test/operators/table_scan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(opossum::Table(2));

Expand All @@ -37,7 +37,7 @@ class operators_table_scan : public ::testing::Test {
std::shared_ptr<opossum::GetTable> _gt;
};

TEST_F(operators_table_scan, double_scan_test) {
TEST_F(OperatorsTableScanTest, DoubleScan) {
auto scan_1 = std::make_shared<opossum::TableScan>(_gt, "a", ">=", 1234);
scan_1->execute();

Expand All @@ -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>(opossum::Table(2));

Expand All @@ -72,7 +72,7 @@ class operators_table_scan_impl : public ::testing::Test {
std::shared_ptr<opossum::GetTable> _gt;
};

TEST_F(operators_table_scan_impl, single_scan_returns_correct_row_count) {
TEST_F(OperatorsTableScanImplTest, SingleScanReturnsCorrectRowCount) {
std::unique_ptr<AbstractOperatorImpl> scan(
make_unique_by_column_type<AbstractOperatorImpl, TableScanImpl>("int", _gt, "a", ">=", 1234));
scan->execute();
Expand All @@ -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<AbstractOperatorImpl> scan(
make_unique_by_column_type<AbstractOperatorImpl, TableScanImpl>("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<opossum::Table> test_ref_table = std::make_shared<opossum::Table>(opossum::Table(2));

std::shared_ptr<PosList> pos_list = std::make_shared<PosList>();
Expand Down
54 changes: 54 additions & 0 deletions src/test/storage/chunk_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <memory>

#include "gtest/gtest.h"

#include "../../lib/common.hpp"
#include "../../lib/storage/base_column.hpp"
#include "../../lib/storage/chunk.hpp"
#include "../../lib/types.hpp"

class StorageChunkTest : public ::testing::Test {
protected:
virtual void SetUp() {
vc_int = opossum::make_shared_by_column_type<opossum::BaseColumn, opossum::ValueColumn>("int");
vc_int->append(4);
vc_int->append(6);
vc_int->append(3);

vc_str = opossum::make_shared_by_column_type<opossum::BaseColumn, opossum::ValueColumn>("string");
vc_str->append("Hello,");
vc_str->append("world");
vc_str->append("!");
}

opossum::Chunk c;
std::shared_ptr<opossum::BaseColumn> vc_int = nullptr;
std::shared_ptr<opossum::BaseColumn> vc_str = nullptr;
};

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(StorageChunkTest, 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(StorageChunkTest, 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);
}
39 changes: 39 additions & 0 deletions src/test/storage/storage_manager_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <memory>

#include "gtest/gtest.h"

#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"

class StorageStorageManagerTest : public ::testing::Test {
protected:
virtual void SetUp() {
auto &sm = opossum::StorageManager::get();
auto t1 = std::make_shared<opossum::Table>();
auto t2 = std::make_shared<opossum::Table>(4);

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) {
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(StorageStorageManagerTest, 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);
}
58 changes: 56 additions & 2 deletions src/test/storage/table_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,61 @@

#include "../../lib/storage/table.hpp"

TEST(storage_table, has_one_chunk_after_creation) {
opossum::Table t(2);
class StorageTableTest : public ::testing::Test {
protected:
virtual void SetUp() {
t.add_column("col_1", "int");
t.add_column("col_2", "string");
}

opossum::Table t{2};
};

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, 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, ColCount) { EXPECT_EQ(t.col_count(), 2u); }

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_F(StorageTableTest, GetColumnName) {
EXPECT_EQ(t.get_column_name(0), "col_1");
EXPECT_EQ(t.get_column_name(1), "col_2");
// 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_F(StorageTableTest, GetChunkSize) { EXPECT_EQ(t.get_chunk_size(), 2u); }
Loading

0 comments on commit c127012

Please sign in to comment.