Ejemplo n.º 1
0
END_TEST

/* Testeo de funcionalidad */
START_TEST(test_network_get_edges)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL, *etmp = NULL;
    SList *el = NULL, *tmp = NULL;
    Node ntmp = 0;

    e1 = edge_create(0, 1, 1, 0);
    e2 = edge_create(0, 2, 1, 0);
    e3 = edge_create(2, 3, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    el = network_get_edges(net, 0);
    fail_unless(!slist_is_empty(el));

    tmp = el;
    while(tmp != NULL){
        etmp = (Edge *) slist_nth_data(tmp, 0);
        ntmp = *edge_get_second(etmp);
        fail_unless(ntmp == 1 || ntmp == 2);

        tmp = slist_next(tmp);
    }

    network_destroy(net);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(test_network_nodes)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL;
    SList *nodes = NULL;
    Node ntmp = 0;

    e1 = edge_create(1, 2, 1, 0);
    e2 = edge_create(3, 4, 1, 0);
    e3 = edge_create(5, 6, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    nodes = network_nodes(net);
    fail_unless(nodes != NULL);
    fail_unless(slist_length(nodes) == 6);
    
    while(nodes != NULL){
        ntmp = *((Node *) slist_head_data(nodes));
        fail_unless((1 <= ntmp) && (ntmp <= 6));
        nodes = slist_next(nodes);
    }

    network_destroy(net);
}
Ejemplo n.º 3
0
END_TEST

START_TEST(test_network_add_edge_null_2)
{
    net = network_create();
    network_add_edge(net, NULL);
}
Ejemplo n.º 4
0
END_TEST

START_TEST(test_network_get_neightbours)
{
    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL;
    Node *ntmp = NULL;
    SList *el = NULL, *tmp = NULL;

    e1 = edge_create(2, 3, 1, 0);
    e2 = edge_create(1, 4, 1, 0);
    e3 = edge_create(2, 1, 1, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);

    el = network_neighbours(net, 2);
    fail_unless(!slist_is_empty(el));

    tmp = el;
    while(tmp != NULL){
        ntmp = (Node *) slist_nth_data(tmp, 0);

        fail_unless(*ntmp == 3 || *ntmp == 1);

        tmp = slist_next(tmp);
    }

    slist_free(el);
    network_destroy(net);
}
Ejemplo n.º 5
0
END_TEST

/* Crear y destruir */
START_TEST(test_network_new_destroy)
{
    net = network_create();
    network_destroy(net);
}
Ejemplo n.º 6
0
// -----[ _ez_topo_create ]------------------------------------------
static inline
ez_topo_t * _ez_topo_create(unsigned int num_nodes,
			    ez_node_t nodes[],
			    unsigned int num_edges,
			    ez_edge_t edges[])
{
  ez_topo_t * eztopo= (ez_topo_t *) MALLOC(sizeof(ez_topo_t));
  eztopo->network= network_create();
  eztopo->addr= IP_ADDR_ANY;
  eztopo->num_nodes= num_nodes;
  eztopo->nodes= (ez_node_t *) MALLOC(sizeof(ez_node_t)*num_nodes);
  eztopo->num_edges= num_edges;
  eztopo->edges= (ez_edge_t *) MALLOC(sizeof(ez_edge_t)*num_edges);
  return eztopo;
}
Ejemplo n.º 7
0
/* Para testing de memoria */
void network_memory_test(void){
    /* Codigo que deberia correr sin memory leaks */

    Edge *e1 = NULL, *e2 = NULL, *e3 = NULL, *e4 = NULL, *etmp = NULL;
    Node *ntmp = NULL;
    SList *el = NULL, *nl = NULL, *tmp = NULL;

    e1 = edge_create(0, 1, 1, 0);
    e2 = edge_create(0, 2, 4, 0);
    e3 = edge_create(2, 3, 6, 0);
    e4 = edge_create(2, 0, 0, 0);

    net = network_create();
    network_add_edge(net, e1);
    network_add_edge(net, e2);
    network_add_edge(net, e3);
    network_add_edge(net, e4);

    el = network_get_edges(net, 0);

    tmp = el;
    while(tmp != NULL){
        etmp = (Edge *) slist_nth_data(tmp, 0);
        edge_pprint(etmp);
        tmp = slist_next(tmp);
    }

    nl = network_neighbours(net, 2);
    printf("Vecinos del nodo: 2\n");

    tmp = nl;
    while(tmp != NULL){
        ntmp = (Node *) slist_nth_data(tmp, 0);
        tmp = slist_next(tmp);

        printf("  %d\n", *ntmp);
    }

    slist_free(nl);
    network_destroy(net);
}