Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Jesus committed Sep 26, 2024
1 parent b5a85fd commit 7f460ee
Show file tree
Hide file tree
Showing 26 changed files with 142 additions and 191 deletions.
15 changes: 9 additions & 6 deletions cmake/Pagoda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,13 @@ set(PAGODA_GTEST_LIBS GTest::gtest GTest::gtest_main)
#
# param unit_test_src: the source file.
function (add_unit_test unit_test_src)
#[[
get_filename_component(unit_test_base_name ${unit_test_src} NAME)
string(REPLACE ".test.cpp" "_test" test_name ${unit_test_base_name})
set(unit_test_libs GTest::gtest GTest::gtest_main)

add_pagoda_executable(
NAME ${test_name}
SOURCES ${unit_test_src}
DEPENDENCIES ${unit_test_libs}
)

Expand All @@ -415,10 +418,10 @@ function (add_unit_test unit_test_src)

add_test(NAME ${test_name} COMMAND ${test_name})

add_custom_command(
TARGET ${test_name} POST_BUILD
COMMAND ${test_name}
COMMENT "Running ${test_name} unit test"
add_custom_target(
"run_${test_name}"
ALL
COMMAND $<TARGET_FILE:${test_name}>
DEPENDS ${test_name}
)
]]
endfunction()
54 changes: 27 additions & 27 deletions src/pagoda/graph/graph.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using namespace pagoda;
using namespace pagoda::graph;

class DISABLED_GraphSimpleOperationsTest : public ::testing::Test {
class GraphSimpleOperationsTest : public ::testing::Test {
protected:
virtual void SetUp() {
graph = std::make_shared<Graph>(m_pagoda.GetNodeFactory());
Expand All @@ -33,21 +33,21 @@ class DISABLED_GraphSimpleOperationsTest : public ::testing::Test {
Pagoda m_pagoda;
};

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_creating_nodes_their_id_should_be_incremental) {
EXPECT_EQ(m_inputInterfaceNode->GetId(), 0u);
EXPECT_EQ(m_outputInterfaceNode->GetId(), 1u);
EXPECT_EQ(m_operationNode->GetId(), 2u);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_a_node_should_remove_it_from_the_graph) {
this->graph->DestroyNode(this->m_operationNode->GetName());

EXPECT_EQ(this->graph->GetNodeCount(), 2u);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_a_node_should_remove_all_of_its_links) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -64,7 +64,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
0u);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_an_input_node_should_remove_it_from_the_input_nodes) {
this->graph->DestroyNode(this->m_operationNode->GetName());
NodeSet inNodes;
Expand All @@ -75,7 +75,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
std::end(inNodes));
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_an_output_node_should_remove_it_from_the_output_nodes) {
this->graph->DestroyNode(this->m_operationNode->GetName());
NodeSet outNodes;
Expand All @@ -86,15 +86,15 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
std::end(outNodes));
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_creating_an_edge_should_return_true_created) {
EXPECT_EQ(this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName()),
Graph::EdgeCreated::Created);
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_creating_an_edge_between_same_nodes_twice_should_return_edge_exists) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -103,7 +103,7 @@ TEST_F(
Graph::EdgeCreated::EdgeExists);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_an_existing_edge_should_return_edge_destroyed) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -112,14 +112,14 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
Graph::EdgeDestroyed::Destroyed);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_destroying_an_non_existing_edge_should_return_edge_doesnt_exist) {
EXPECT_EQ(this->graph->DestroyEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName()),
Graph::EdgeDestroyed::EdgeDoesntExist);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_retrieving_adjacent_nodes_should_return_all_linked_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -138,7 +138,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
std::end(all_nodes));
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_retrieving_in_adjacent_nodes_should_return_only_the_in_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -152,7 +152,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
EXPECT_EQ(*in_nodes.begin(), this->m_inputInterfaceNode);
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_retrieving_out_adjacent_nodes_should_return_only_the_out_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -166,7 +166,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
EXPECT_EQ(*out_nodes.begin(), this->m_outputInterfaceNode);
}

TEST_F(DISABLED_GraphSimpleOperationsTest, when_unlinking_nodes_should_remove_links) {
TEST_F(GraphSimpleOperationsTest, when_unlinking_nodes_should_remove_links) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
this->graph->DestroyEdge(this->m_inputInterfaceNode->GetName(),
Expand All @@ -178,7 +178,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest, when_unlinking_nodes_should_remove_li
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_retrieving_a_graphs_input_nodes_should_return_all_nodes_that_dont_have_inputs) {
NodeSet input_nodes;
query::InputNode q(*graph, input_nodes);
Expand All @@ -190,7 +190,7 @@ TEST_F(
}
}

TEST_F(DISABLED_GraphSimpleOperationsTest,
TEST_F(GraphSimpleOperationsTest,
when_linking_a_node_to_an_input_node_should_remove_it_from_input_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -208,7 +208,7 @@ TEST_F(DISABLED_GraphSimpleOperationsTest,
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_unlinking_a_node_making_it_an_input_node_should_add_it_to_input_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -222,7 +222,7 @@ TEST_F(
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_retrieving_a_graphs_output_nodes_should_return_all_nodes_that_dont_have_outputs) {
NodeSet output_nodes;
query::OutputNode q(*graph, output_nodes);
Expand All @@ -235,7 +235,7 @@ TEST_F(
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_linking_a_node_to_an_output_node_should_remove_it_from_output_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -253,7 +253,7 @@ TEST_F(
}

TEST_F(
DISABLED_GraphSimpleOperationsTest,
GraphSimpleOperationsTest,
when_unlinking_a_node_making_it_an_output_node_should_add_it_to_output_nodes) {
this->graph->CreateEdge(this->m_inputInterfaceNode->GetName(),
this->m_operationNode->GetName());
Expand All @@ -266,7 +266,7 @@ TEST_F(
ASSERT_EQ(output_nodes.size(), 3u);
}

class DISABLED_GraphNodeCreationByName : public ::testing::Test {
class GraphNodeCreationByName : public ::testing::Test {
protected:
virtual void SetUp() {
m_graph = std::make_shared<Graph>(m_pagoda.GetNodeFactory());
Expand All @@ -276,27 +276,27 @@ class DISABLED_GraphNodeCreationByName : public ::testing::Test {
Pagoda m_pagoda;
};

TEST_F(DISABLED_GraphNodeCreationByName,
TEST_F(GraphNodeCreationByName,
when_creating_nodes_with_name_should_set_the_node_name) {
auto node = m_graph->GetNode(m_graph->CreateNode<OperationNode>("operation"));
EXPECT_EQ(node->GetName(), "operation");
}

TEST_F(DISABLED_GraphNodeCreationByName,
TEST_F(GraphNodeCreationByName,
when_creating_multiple_nodes_with_the_same_name_should_add_an_index) {
auto node1 = m_graph->CreateNode<OperationNode>("operation");
auto node2 = m_graph->CreateNode<OperationNode>("operation");
EXPECT_EQ(node1, "operation");
EXPECT_EQ(node2, "operation1");
}

TEST_F(DISABLED_GraphNodeCreationByName,
TEST_F(GraphNodeCreationByName,
when_creating_nodes_without_a_name_should_use_node_type_as_default) {
auto node = m_graph->CreateNode<OperationNode>();
EXPECT_EQ(node, OperationNode::name);
}

TEST_F(DISABLED_GraphNodeCreationByName,
TEST_F(GraphNodeCreationByName,
when_creating_node_by_name_should_be_able_to_get_by_name) {
auto node = m_graph->GetNode(m_graph->CreateNode<OperationNode>("operation"));
EXPECT_EQ(m_graph->GetNode("operation"), node);
Expand All @@ -305,7 +305,7 @@ TEST_F(DISABLED_GraphNodeCreationByName,
EXPECT_EQ(m_graph->GetNode(InputInterfaceNode::name), node);
}

class DISABLED_GraphNodeRenaming : public ::testing::Test {
class GraphNodeRenaming : public ::testing::Test {
protected:
virtual void SetUp() {
m_graph = std::make_shared<Graph>(m_pagoda.GetNodeFactory());
Expand All @@ -323,7 +323,7 @@ class DISABLED_GraphNodeRenaming : public ::testing::Test {
Pagoda m_pagoda;
};

TEST_F(DISABLED_GraphNodeRenaming, test_rename_without_adjacencies)
TEST_F(GraphNodeRenaming, test_rename_without_adjacencies)
{
const auto opNodeName = m_operationNode->GetName();
m_graph->RenameNode(opNodeName, "newName");
Expand Down
22 changes: 3 additions & 19 deletions src/pagoda/graph/io/ast_interpreter.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ using namespace pagoda::graph;
using namespace pagoda::graph::io;
using namespace pagoda::dynamic;

class DISABLED_AstInterpreterTest : public ::testing::Test
class AstInterpreterTest : public ::testing::Test
{
protected:
void SetUp()
Expand All @@ -36,7 +36,7 @@ class DISABLED_AstInterpreterTest : public ::testing::Test
std::shared_ptr<AstInterpreter> m_interpreter;
};

TEST_F(DISABLED_AstInterpreterTest,
TEST_F(AstInterpreterTest,
when_visiting_a_node_definition_node_should_create_a_node_in_the_graph)
{
NodeDefinitionNode::ExecutionArgumentContainer_t executionArgs = {
Expand All @@ -48,7 +48,7 @@ TEST_F(DISABLED_AstInterpreterTest,
EXPECT_NE(m_graph->GetNode("name"), nullptr);
}

TEST_F(DISABLED_AstInterpreterTest,
TEST_F(AstInterpreterTest,
when_visiting_a_node_link_node_should_create_a_link_in_the_graph)
{
NodeLinkNode link;
Expand All @@ -65,19 +65,3 @@ TEST_F(DISABLED_AstInterpreterTest,
m_interpreter->Visit(&link);
EXPECT_EQ(m_graph->CreateEdge("n1", "n2"), Graph::EdgeCreated::EdgeExists);
}

TEST_F(
DISABLED_AstInterpreterTest,
when_visiting_a_node_link_definition_should_create_in_out_interface_nodes)
{
m_graph->CreateNode<OperationNode>("node");
NodeLinkDefinition def("node", "in", "out");

m_interpreter->Visit(&def);
EXPECT_NE(m_graph->GetNode("node_in"), nullptr);
EXPECT_NE(m_graph->GetNode("node_out"), nullptr);
EXPECT_EQ(m_graph->CreateEdge("node_in", "node"),
Graph::EdgeCreated::EdgeExists);
EXPECT_EQ(m_graph->CreateEdge("node", "node_out"),
Graph::EdgeCreated::EdgeExists);
}
32 changes: 14 additions & 18 deletions src/pagoda/graph/io/writer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using namespace pagoda::dynamic;
using namespace pagoda::graph;
using namespace pagoda::graph::io;

class DISABLED_GraphWriterTest : public ::testing::Test
class GraphWriterTest : public ::testing::Test
{
protected:
void SetUp() override
Expand All @@ -46,12 +46,12 @@ class DISABLED_GraphWriterTest : public ::testing::Test
std::shared_ptr<GraphReader> m_reader;
};

TEST_F(DISABLED_GraphWriterTest, test_empty_graph)
TEST_F(GraphWriterTest, test_empty_graph)
{
EXPECT_EQ(getAsString(), "");
}

TEST_F(DISABLED_GraphWriterTest, test_single_operation)
TEST_F(GraphWriterTest, test_single_operation)
{
m_graph->CreateNode<OperationNode>("op");
NodePtr opNode =
Expand All @@ -62,45 +62,41 @@ TEST_F(DISABLED_GraphWriterTest, test_single_operation)
EXPECT_EQ(getAsString(), R"(op = CreateRectGeometry {
height: 1.000000,
plane: "z",
posX: 0.000000,
posY: 0.000000,
width: 1.000000
}
)");

EXPECT_NE(m_reader->Read(getAsString()), nullptr);
}

TEST_F(DISABLED_GraphWriterTest, test_links)
TEST_F(GraphWriterTest, test_links)
{
m_graph->CreateNode<OperationNode>("op");
m_graph->CreateNode<OperationNode>("op2");
m_graph->CreateNode<InputInterfaceNode>("in");
m_graph->CreateNode<OutputInterfaceNode>("out");
m_graph->CreateEdge("op", "out");
m_graph->CreateEdge("out", "in");
m_graph->CreateEdge("in", "op2");
auto opNode =
std::dynamic_pointer_cast<OperationNode>(m_graph->GetNode("op"));
opNode->SetOperation(
m_pagoda.GetOperationFactory()->Create("CreateRectGeometry"));
auto opNode2 =
std::dynamic_pointer_cast<OperationNode>(m_graph->GetNode("op2"));
opNode2->SetOperation(
m_pagoda.GetOperationFactory()->Create("CreateRectGeometry"));
m_pagoda.GetOperationFactory()->Create("ExtrudeGeometry"));

std::dynamic_pointer_cast<InputInterfaceNode>(m_graph->GetNode("in"))
->SetInterfaceName("in");
std::dynamic_pointer_cast<OutputInterfaceNode>(m_graph->GetNode("out"))
->SetInterfaceName("out");
m_graph->CreateEdge("op_out", "op2_in");

EXPECT_EQ(getAsString(), R"(op = CreateRectGeometry {
height: 1.000000,
plane: "z",
posX: 0.000000,
posY: 0.000000,
width: 1.000000
}
op2 = CreateRectGeometry {
height: 1.000000,
plane: "z",
width: 1.000000
op2 = ExtrudeGeometry {
amount: 1.000000,
posX: 0.000000,
posY: 0.000000
}
op>out -> in<op2;
)");
Expand Down
Loading

0 comments on commit 7f460ee

Please sign in to comment.