58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
#include "c_Test.h"
|
|||
|
|
#include "c_Digraph.h"
|
||
|
|
#include "c_NonrecursiveTopological.h"
|
||
|
|
#include "c_VertexIdList.h"
|
||
|
|
|
||
|
|
TEST_CASE(test_nonrecursive_topological_sort) {
|
||
|
|
c_Digraph_t g;
|
||
|
|
c_Digraph_Init(&g, 4, NULL);
|
||
|
|
|
||
|
|
/* Construct a simple dependency layout DAG:
|
||
|
|
* 0 -> 1 -> 3
|
||
|
|
* 0 -> 2 -> 3
|
||
|
|
*/
|
||
|
|
c_Digraph_AddEdge(&g, 0, 1);
|
||
|
|
c_Digraph_AddEdge(&g, 1, 3);
|
||
|
|
c_Digraph_AddEdge(&g, 0, 2);
|
||
|
|
c_Digraph_AddEdge(&g, 2, 3);
|
||
|
|
|
||
|
|
c_NonrecursiveTopological_t topo;
|
||
|
|
c_err_t err = c_NonrecursiveTopological_Init(&topo, &g, 0);
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
ASSERT_TRUE(c_NonrecursiveTopological_HasOrder(&topo));
|
||
|
|
|
||
|
|
c_VertexIdList_t result;
|
||
|
|
c_VertexIdList_Init(&result, 0, 0);
|
||
|
|
|
||
|
|
err = c_NonrecursiveTopological_GetOrder(&topo, &result);
|
||
|
|
ASSERT_INT_EQ(C_SUCCESS, err);
|
||
|
|
ASSERT_INT_EQ(4, c_VertexIdList_GetSize(&result));
|
||
|
|
|
||
|
|
/* Verify basic topological layout constraints:
|
||
|
|
* 1. 0 must always appear first (no incoming dependencies).
|
||
|
|
* 2. 3 must always appear last (depends on everyone else).
|
||
|
|
*/
|
||
|
|
c_uint_t first_v = 0, last_v = 0;
|
||
|
|
c_VertexIdList_Get(&result, 0, &first_v);
|
||
|
|
c_VertexIdList_Get(&result, 3, &last_v);
|
||
|
|
|
||
|
|
ASSERT_LL_EQ(0, first_v);
|
||
|
|
ASSERT_LL_EQ(3, last_v);
|
||
|
|
|
||
|
|
c_VertexIdList_Destroy(&result);
|
||
|
|
c_NonrecursiveTopological_Destroy(&topo);
|
||
|
|
c_Digraph_Destroy(&g);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char** argv){
|
||
|
|
|
||
|
|
TEST_START(Component Tests);
|
||
|
|
|
||
|
|
// Execution list configurations
|
||
|
|
RUN_TEST(test_nonrecursive_topological_sort);
|
||
|
|
|
||
|
|
TEST_REPORT();
|
||
|
|
|
||
|
|
RETURN_TEST_STATUS;
|
||
|
|
}
|