From 1366e8ec218595ca9c4b259cc5e3f14397e125c2 Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:54:22 +0100 Subject: [PATCH] Added test for select operator --- tests/queryTests.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/queryTests.cpp b/tests/queryTests.cpp index 956648a..daaa9c3 100644 --- a/tests/queryTests.cpp +++ b/tests/queryTests.cpp @@ -316,6 +316,60 @@ TEST_F(QueryTestFixture, test_query_join) } +TEST_F(QueryTestFixture, test_query_select) +{ + filter_check_t conditions1[1] = {check_filter}; + filter_check_t conditions2[1] = {check_filter3}; + join_check_t conditions3[1] = {check_join}; + uint8_t predicates[1] = {PREDICATE_HAS_SKILL}; + + operator_t filter_has_skill = { + .type = FILTER, + .left = nullptr, + .right = nullptr, + .params = {.filter = {.size = 1, .checks = conditions1}} + }; + + operator_t filter_req_skill = { + .type = FILTER, + .left = nullptr, + .right = nullptr, + .params = {.filter = {.size = 1, .checks = conditions2}} + }; + + operator_t join_op = { + .type = JOIN, + .left = &filter_has_skill, + .right = &filter_req_skill, + .params = {.join = {.size = 1, .checks = conditions3}} + }; + + operator_t select_op = { + .type = SELECT, + .left = &join_op, + .right = nullptr, + .params = {.select = {.size = 1, .colums = predicates}} + }; + + query_t query = {.root = &select_op}; + + execute_query(&query, gsource, gsink); + + triple_t expected[5] = { + {SUBJECT_ALICE, PREDICATE_HAS_SKILL, OBJECT_PROGRAMMING}, + + {SUBJECT_BOB, PREDICATE_HAS_SKILL, OBJECT_DATA_ANALYSIS}, + + {SUBJECT_CHARLIE, PREDICATE_HAS_SKILL, OBJECT_PROGRAMMING}, + + {SUBJECT_DAVID, PREDICATE_HAS_SKILL, OBJECT_PROGRAMMING}, + + {SUBJECT_EMILY, PREDICATE_HAS_SKILL, OBJECT_PROGRAMMING}, + }; + ASSERT_TRUE(ARR_EQ(gsink->buffer.data, expected, 5)); +} + + bool check_filter4(const triple_t in) { return in.predicate == PREDICATE_HAS_AGE;