2004-12-23 15:16:30 +02:00
|
|
|
#include "../src/graph.h"
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
#include "../src/debug.h"
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
graph_iterator_t it;
|
2005-01-21 23:14:55 +02:00
|
|
|
cmph_uint32 i, neighbor;
|
2005-10-10 20:43:21 +03:00
|
|
|
graph_t *g = graph_new(5, 10);
|
2004-12-23 15:16:30 +02:00
|
|
|
|
|
|
|
fprintf(stderr, "Building random graph\n");
|
|
|
|
for (i = 0; i < 10; ++i)
|
|
|
|
{
|
2005-01-21 23:14:55 +02:00
|
|
|
cmph_uint32 v1 = i % 5;
|
|
|
|
cmph_uint32 v2 = (i*2) % 5;
|
2004-12-23 15:16:30 +02:00
|
|
|
if (v1 == v2) continue;
|
|
|
|
graph_add_edge(g, v1, v2);
|
|
|
|
DEBUGP("Added edge %u %u\n", v1, v2);
|
|
|
|
}
|
|
|
|
graph_print(g);
|
|
|
|
graph_del_edge(g, 4, 3);
|
|
|
|
graph_print(g);
|
|
|
|
graph_clear_edges(g);
|
|
|
|
graph_print(g);
|
|
|
|
graph_destroy(g);
|
|
|
|
|
|
|
|
fprintf(stderr, "Building cyclic graph\n");
|
2005-10-10 20:43:21 +03:00
|
|
|
g = graph_new(4, 5);
|
2004-12-23 15:16:30 +02:00
|
|
|
graph_add_edge(g, 0, 3);
|
|
|
|
graph_add_edge(g, 0, 1);
|
|
|
|
graph_add_edge(g, 1, 2);
|
|
|
|
graph_add_edge(g, 2, 0);
|
|
|
|
if (!graph_is_cyclic(g))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
graph_destroy(g);
|
|
|
|
|
|
|
|
fprintf(stderr, "Building non-cyclic graph\n");
|
2005-10-10 20:43:21 +03:00
|
|
|
g = graph_new(5, 4);
|
2004-12-23 15:16:30 +02:00
|
|
|
graph_add_edge(g, 0, 1);
|
|
|
|
graph_add_edge(g, 1, 2);
|
|
|
|
graph_add_edge(g, 2, 3);
|
|
|
|
graph_add_edge(g, 3, 4);
|
|
|
|
|
|
|
|
if (graph_is_cyclic(g))
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "Checking neighbors iterator\n");
|
|
|
|
it = graph_neighbors_it(g, 1);
|
|
|
|
neighbor = graph_next_neighbor(g, &it);
|
|
|
|
DEBUGP("Neighbor is %u\n", neighbor);
|
|
|
|
if (neighbor != 0 && neighbor != 2) return 1;
|
|
|
|
neighbor = graph_next_neighbor(g, &it);
|
|
|
|
DEBUGP("Neighbor is %u\n", neighbor);
|
|
|
|
if (neighbor != 0 && neighbor != 2) return 1;
|
|
|
|
neighbor = graph_next_neighbor(g, &it);
|
|
|
|
DEBUGP("Neighbor is %u\n", neighbor);
|
|
|
|
if (neighbor != GRAPH_NO_NEIGHBOR) return 1;
|
|
|
|
|
|
|
|
|
|
|
|
graph_destroy(g);
|
|
|
|
return 0;
|
|
|
|
}
|