struct parallel_graphr pgr;
struct agar_state *sr;
aga_icost_t cost;
- const void *node;
+ const void *node, *edge;
- parallel_graphr_init(&pgr, 3);
+ parallel_graphr_init(&pgr, 3, 0);
ok1(sr = agar_dijkstra_new(NULL, &pgr.gr, int2ptr(1)));
ok1(agar_dijkstra_step(sr, &node));
ok1(agar_dijkstra_path(sr, int2ptr(1), &cost, NULL, NULL));
ok1(cost == 0);
ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, &node, NULL));
- ok1(cost == 1);
+ ok1(cost == 2);
ok1(node == int2ptr(1));
tal_free(sr);
ok1(cost == 0);
ok1(!agar_dijkstra_path(sr, int2ptr(1), NULL, NULL, NULL));
tal_free(sr);
+
+ parallel_graphr_init(&pgr, 3, 2);
+ ok1(sr = agar_dijkstra_new(NULL, &pgr.gr, int2ptr(1)));
+ ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, &node, &edge));
+ ok1(cost == 1);
+ ok1(ptr2int(node) == 1);
+ ok1(ptr2int(edge) == 2);
+ tal_free(sr);
}
#define FULL_LEN 4
tal_free(sr);
}
+static void test_shortcut1(void)
+{
+ struct shortcut1_graphr s1gr;
+ struct agar_state *sr;
+ aga_icost_t cost;
+ const void *node;
+
+ shortcut1_graphr_init(&s1gr);
+
+ ok1(sr = agar_dijkstra_new(NULL, &s1gr.gr, int2ptr(1)));
+ ok1(agar_dijkstra_path(sr, int2ptr(3), &cost, &node, NULL));
+ ok1(cost == 2);
+ ok1(node == int2ptr(2));
+ ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, &node, NULL));
+ ok1(cost == 1);
+ ok1(node == int2ptr(1));
+ tal_free(sr);
+}
+
+static void test_shortcut2(void)
+{
+ struct shortcut2_graphr s2gr;
+ struct agar_state *sr;
+
+ shortcut2_graphr_init(&s2gr);
+
+ ok1(sr = agar_dijkstra_new(NULL, &s2gr.gr, int2ptr(1)));
+ agar_dijkstra_all_paths(sr);
+ ok1(agar_error(sr) == AGA_ERR_NEGATIVE_COST);
+ tal_free(sr);
+}
+
int main(void)
{
- plan_tests(6 + 18
+ plan_tests(6 + 23
+ FULL_LEN * (FULL_LEN*4 - 1)
+ CHAIN_LEN * (1 + CHAIN_LEN*2)
- + 12 + 32);
+ + 12 + 32 + 7 + 2);
test_trivial();
test_parallel();
test_chain();
test_error();
test_traversal1();
+ test_shortcut1();
+ test_shortcut2();
return exit_status();
}