core-lightning/plugins/askrene/test/run-graph.c
Lagrang3 460a28bb32 askrene: add compiler flag ASKRENE_UNITTEST
Rusty: "We don't generally use NDEBUG in our code"

Instead use a compile time flag ASKRENE_UNITTEST to make checks on unit
tests that we don't normally need on release code.

Changelog-none

Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
2024-11-21 16:17:52 +10:30

63 lines
1.5 KiB
C

#include "config.h"
#include <assert.h>
#include <ccan/tal/tal.h>
#include <common/setup.h>
#include <common/utils.h>
#include <inttypes.h>
#include <stdio.h>
#define ASKRENE_UNITTEST
#include "../graph.c"
#define MAX_NODES 10
#define MAX_ARCS 256
#define DUAL_BIT 7
static void show(struct graph *graph, struct node node)
{
printf("Showing node %" PRIu32 "\n", node.idx);
for (struct arc arc = node_adjacency_begin(graph, node);
!node_adjacency_end(arc); arc = node_adjacency_next(graph, arc)) {
printf("arc id: %" PRIu32 ", (%" PRIu32 " -> %" PRIu32 ")\n",
arc.idx, arc_tail(graph, arc).idx,
arc_head(graph, arc).idx);
}
printf("\n");
}
int main(int argc, char *argv[])
{
common_setup(argv[0]);
printf("Allocating a memory context\n");
tal_t *ctx = tal(NULL, tal_t);
assert(ctx);
printf("Allocating a graph\n");
struct graph *graph = graph_new(ctx, MAX_NODES, MAX_ARCS, DUAL_BIT);
assert(graph);
bool success;
success = graph_add_arc(graph, arc_obj(0), node_obj(0), node_obj(1));
assert(success);
success = graph_add_arc(graph, arc_obj(1), node_obj(0), node_obj(2));
assert(success);
success = graph_add_arc(graph, arc_obj(2), node_obj(0), node_obj(3));
assert(success);
success = graph_add_arc(graph, arc_obj(3), node_obj(3), node_obj(2));
assert(success);
show(graph, node_obj(0));
show(graph, node_obj(1));
show(graph, node_obj(2));
show(graph, node_obj(3));
printf("Freeing memory\n");
ctx = tal_free(ctx);
common_shutdown();
return 0;
}