Skip to content

Commit

Permalink
Adds tests for initial node attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrosz committed Jul 27, 2024
1 parent fe20311 commit e8343d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
24 changes: 17 additions & 7 deletions graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@ void Graph_free(Graph *graph)

Node *Node_new()
{
return climblib_malloc(sizeof(Node));
Node *node;

if ((node = climblib_malloc(sizeof(Node)))) {
node->next = NULL;
node->edges = NULL;
node->type = NodeType_UNDEFINED;
}

return node;
}

Node *Node_new_formation(Formation *formation)
{
Node *node;

node = Node_new();
node->type = NodeType_FORMATION;
node->data.formation = formation;
if ((node = Node_new())) {
node->type = NodeType_FORMATION;
node->data.formation = formation;
}

return node;
}
Expand All @@ -59,9 +68,10 @@ Node *Node_new_climb(Climb *climb)

Node *node;

node = Node_new();
node->type = NodeType_CLIMB;
node->data.climb = climb;
if ((node = Node_new())) {
node->type = NodeType_CLIMB;
node->data.climb = climb;
}

return node;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ START_TEST(test_nodes)
Graph *graph;
Node *a, *b, *c, *n;

climblib_set_alloc(bad_malloc, NULL, NULL);
a = Node_new();
ck_assert_ptr_null(a);
climblib_set_alloc(NULL, NULL, NULL);

graph = Graph_new();

a = Node_new();
Expand Down Expand Up @@ -70,6 +75,11 @@ START_TEST(test_formation_node)
Formation *formation;
Node *formation_node;

climblib_set_alloc(bad_malloc, NULL, NULL);
formation_node = Node_new_formation(NULL);
ck_assert_ptr_null(formation_node);
climblib_set_alloc(NULL, NULL, NULL);

formation = Formation_new();
ck_assert_ptr_nonnull(formation_node = Node_new_formation(formation));

Expand All @@ -86,6 +96,11 @@ START_TEST(test_climb_node)
Climb *climb;
Node *climb_node;

climblib_set_alloc(bad_malloc, NULL, NULL);
climb_node = Node_new_climb(NULL);
ck_assert_ptr_null(climb_node);
climblib_set_alloc(NULL, NULL, NULL);

climb = Climb_new();
ck_assert_ptr_nonnull(climb_node = Node_new_climb(climb));

Expand Down

0 comments on commit e8343d2

Please sign in to comment.