-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unittests for VertexST and remove the topological order attribute
- Loading branch information
Aymane Lotfi
committed
Apr 11, 2024
1 parent
360ee39
commit 6085b03
Showing
4 changed files
with
76 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <gtest/gtest.h> | ||
#include "../graph_utils/VertexST.h" | ||
|
||
TEST(VertexSTTest, Constructor) { | ||
// Test default constructor | ||
VertexST v1; | ||
EXPECT_EQ(v1.get_id(), -1); | ||
EXPECT_EQ(v1.get_id_in_graph(), -1); | ||
EXPECT_EQ(v1.get_time(), -1); | ||
|
||
// Test constructor with parameters | ||
VertexST v2(10, 5); | ||
EXPECT_EQ(v2.get_id(), 0); | ||
EXPECT_EQ(v2.get_id_in_graph(), 10); | ||
EXPECT_EQ(v2.get_time(), 5); | ||
} | ||
|
||
TEST(VertexSTTest, CopyConstructor) { | ||
VertexST v1(10, 5); | ||
v1.add_neighbour_out(1, 2); | ||
|
||
// Create a copy of v1 | ||
VertexST v2(v1); | ||
|
||
// Verify that the copies are equal | ||
EXPECT_EQ(v2.get_id(), v1.get_id()); | ||
EXPECT_EQ(v2.get_id_in_graph(), v1.get_id_in_graph()); | ||
EXPECT_EQ(v2.get_time(), v1.get_time()); | ||
EXPECT_EQ(v2.get_adjacency_list_out(), v1.get_adjacency_list_out()); | ||
} | ||
|
||
TEST(VertexSTTest, AssignmentOperator) { | ||
VertexST v1(10, 5); | ||
v1.add_neighbour_out(1, 2); | ||
|
||
// Create a new vertex | ||
VertexST v2; | ||
|
||
// Assign v1 to v2 | ||
v2 = v1; | ||
|
||
// Verify that the assignment was successful | ||
EXPECT_EQ(v2.get_id(), v1.get_id()); | ||
EXPECT_EQ(v2.get_id_in_graph(), v1.get_id_in_graph()); | ||
EXPECT_EQ(v2.get_time(), v1.get_time()); | ||
EXPECT_EQ(v2.get_adjacency_list_out(), v1.get_adjacency_list_out()); | ||
} | ||
|
||
TEST(VertexSTTest, AddNeighbourOut) { | ||
VertexST v; | ||
v.add_neighbour_out(1, 2); | ||
v.add_neighbour_out(1, 3); | ||
v.add_neighbour_out(2, 4); | ||
|
||
// Verify that the neighbours were added correctly | ||
EXPECT_EQ(v.get_adjacency_list_out().size(), 2); | ||
EXPECT_TRUE(v.get_adjacency_list_out().count(1) > 0); | ||
EXPECT_TRUE(v.get_adjacency_list_out().count(2) > 0); | ||
EXPECT_EQ(v.get_adjacency_list_out().at(1).size(), 2); | ||
EXPECT_EQ(v.get_adjacency_list_out().at(2).size(), 1); | ||
} | ||
|
||
TEST(VertexSTTest, AddNeighbourIn) { | ||
VertexST v; | ||
v.add_neighbour_in(1, 2); | ||
v.add_neighbour_in(1, 3); | ||
v.add_neighbour_in(2, 4); | ||
|
||
// Verify that the neighbours were added correctly | ||
EXPECT_EQ(v.get_adjacency_list_in().size(), 2); | ||
EXPECT_TRUE(v.get_adjacency_list_in().count(1) > 0); | ||
EXPECT_TRUE(v.get_adjacency_list_in().count(2) > 0); | ||
EXPECT_EQ(v.get_adjacency_list_in().at(1).size(), 2); | ||
EXPECT_EQ(v.get_adjacency_list_in().at(2).size(), 1); | ||
} |