Skip to content

Commit

Permalink
[DYOD] Team 1 - Sprint 4 (#2575)
Browse files Browse the repository at this point in the history
Add tests for LQP nodes and operators.

Co-authored-by: Finn Schoellkopf <schoellkopf.finn@gmail.com>
Co-authored-by: Daniel Lindner <27929897+dey4ss@users.noreply.github.com>
  • Loading branch information
3 people authored and nikriek committed Oct 28, 2023
1 parent 6c9f97b commit 328c115
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/test/lib/logical_query_plan/alias_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,31 @@ class AliasNodeTest : public BaseTest {
b = mock_node->get_column("b");

aliases = {"x", "y"};
partial_aliases = {"b", "z"};
expressions = {b, a};
alias_node = AliasNode::make(expressions, aliases, mock_node);
partial_alias_node = AliasNode::make(expressions, partial_aliases, mock_node);
}

std::vector<std::string> aliases;
std::vector<std::string> partial_aliases;
std::vector<std::shared_ptr<AbstractExpression>> expressions;
std::shared_ptr<MockNode> mock_node;

std::shared_ptr<AbstractExpression> a, b;
std::shared_ptr<AbstractExpression> a;
std::shared_ptr<AbstractExpression> b;
std::shared_ptr<AbstractExpression> c;
std::shared_ptr<AliasNode> alias_node;
std::shared_ptr<AliasNode> partial_alias_node;
};

TEST_F(AliasNodeTest, NodeDescription) {
EXPECT_EQ(alias_node->description(), "[Alias] b AS x, a AS y");
EXPECT_EQ(partial_alias_node->description(), "[Alias] b, a AS z");
}

TEST_F(AliasNodeTest, NodeExpressions) {
ASSERT_EQ(alias_node->node_expressions.size(), 2u);
ASSERT_EQ(alias_node->node_expressions.size(), 2);
EXPECT_EQ(alias_node->node_expressions.at(0), b);
EXPECT_EQ(alias_node->node_expressions.at(1), a);
}
Expand Down
36 changes: 34 additions & 2 deletions src/test/lib/logical_query_plan/except_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "base_test.hpp"

#include "logical_query_plan/data_dependencies/functional_dependency.hpp"
#include "logical_query_plan/except_node.hpp"
#include "logical_query_plan/lqp_utils.hpp"
#include "logical_query_plan/mock_node.hpp"
Expand All @@ -23,17 +24,48 @@ class ExceptNodeTest : public BaseTest {
_except_node = ExceptNode::make(SetOperationMode::Positions);
_except_node->set_left_input(_mock_node1);
_except_node->set_right_input(_mock_node1);

_except_node_without_right_input = ExceptNode::make(SetOperationMode::Positions);
_except_node_without_right_input->set_left_input(_mock_node1);
}

std::shared_ptr<MockNode> _mock_node1, _mock_node2, _mock_node3;
std::shared_ptr<MockNode> _mock_node1;
std::shared_ptr<MockNode> _mock_node2;
std::shared_ptr<MockNode> _mock_node3;
std::shared_ptr<ExceptNode> _except_node;
std::shared_ptr<LQPColumnExpression> _a, _b, _c;
std::shared_ptr<ExceptNode> _except_node_without_right_input;
std::shared_ptr<LQPColumnExpression> _a;
std::shared_ptr<LQPColumnExpression> _b;
std::shared_ptr<LQPColumnExpression> _c;
};

TEST_F(ExceptNodeTest, Description) {
EXPECT_EQ(_except_node->description(), "[ExceptNode] Mode: Positions");
}

TEST_F(ExceptNodeTest, IsColumnNullable) {
// Columns of a MockNode are never nullable.
const auto column_count = _mock_node1->column_definitions().size();
for (auto column_id = ColumnID{0}; column_id < column_count; ++column_id) {
EXPECT_FALSE(_except_node->is_column_nullable(column_id));
}

// Both left_input and right_input need to be set.
EXPECT_THROW(_except_node_without_right_input->is_column_nullable(ColumnID{0}), std::logic_error);
}

TEST_F(ExceptNodeTest, NonTrivialFunctionalDependencies) {
const auto fd_a = FunctionalDependency({_a}, {_b, _c});
const auto fd_b_two_dependents = FunctionalDependency({_b}, {_a, _c});

const auto non_trivial_dependencies = FunctionalDependencies{fd_a, fd_b_two_dependents};
_mock_node1->set_non_trivial_functional_dependencies(non_trivial_dependencies);

EXPECT_EQ(_except_node->non_trivial_functional_dependencies(), non_trivial_dependencies);
// Also works if right_input is not set.
EXPECT_EQ(_except_node_without_right_input->non_trivial_functional_dependencies(), non_trivial_dependencies);
}

TEST_F(ExceptNodeTest, OutputColumnExpressions) {
EXPECT_TRUE(_except_node->output_expressions() == _mock_node1->output_expressions());
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/lib/operators/aggregate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@

namespace hyrise {

class OperatorsAggregateHashTest : public BaseTest {};

TEST_F(OperatorsAggregateHashTest, EmptyHash) {
// Notably, both the `EmptyAggregateKey` and the empty `AggregateKeySmallVector` have the same hash, so a hash
// comparison is consistent with comparing all contained keys.
EXPECT_EQ(std::hash<EmptyAggregateKey>()(EmptyAggregateKey{}), 0);
EXPECT_EQ(std::hash<AggregateKeySmallVector>()(AggregateKeySmallVector{}), 0);
}

template <typename T>
void test_output(const std::shared_ptr<AbstractOperator> in,
const std::vector<std::pair<ColumnID, AggregateFunction>>& aggregate_definitions,
Expand Down
13 changes: 13 additions & 0 deletions src/test/lib/operators/limit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,17 @@ TEST_F(OperatorsLimitTest, ForwardSortedByFlag) {
}
}

TEST_F(OperatorsLimitTest, OnlyIntegralTypes) {
const auto limit_string = std::make_shared<Limit>(_table_wrapper, value_("test_string"));
EXPECT_THROW(limit_string->execute(), std::logic_error);

const auto limit_float = std::make_shared<Limit>(_table_wrapper, value_(2.0f));
EXPECT_THROW(limit_float->execute(), std::logic_error);
}

TEST_F(OperatorsLimitTest, Name) {
const auto limit = std::make_shared<Limit>(_table_wrapper, value_(2));
EXPECT_EQ(limit->name(), std::string{"Limit"});
}

} // namespace hyrise

0 comments on commit 328c115

Please sign in to comment.