add alternative approach from 2013-01
[synclust.git] / src / tests / t.dijkstra.c
... / ...
CommitLineData
1#include "tests/helpers.h"
2#include "sources/dijkstra.h"
3
4//custom graph 1 (connected!)
5void test_dijkstra1()
6{
7 int n = 10;
8 double distsIn[100] =
9 {
10 NAN,4.0,6.0,3.0,NAN,1.0,NAN,NAN,NAN,NAN,
11 4.0,NAN,NAN,5.0,NAN,1.0,3.0,NAN,1.0,NAN,
12 6.0,NAN,NAN,NAN,NAN,7.0,1.0,NAN,NAN,NAN,
13 3.0,5.0,NAN,NAN,4.0,NAN,NAN,NAN,NAN,1.0,
14 NAN,NAN,NAN,4.0,NAN,NAN,NAN,2.0,3.0,NAN,
15 1.0,1.0,7.0,NAN,NAN,NAN,NAN,3.0,NAN,NAN,
16 NAN,3.0,1.0,NAN,NAN,NAN,NAN,NAN,1.0,NAN,
17 NAN,NAN,NAN,NAN,2.0,3.0,NAN,NAN,NAN,1.0,
18 NAN,1.0,NAN,NAN,3.0,NAN,1.0,NAN,NAN,NAN,
19 NAN,NAN,NAN,1.0,NAN,NAN,NAN,1.0,NAN,NAN
20 };
21 double* distsOut;
22
23 distsOut = dijkstra_core(distsIn, 0, 10);
24 //as by-hand computed, distances should be as follow
25 double shouldOutput0[10] = {0.0,2.0,5.0,3.0,6.0,1.0,4.0,4.0,3.0,4.0};
26 ASSERT_TRUE(checkEqualV(shouldOutput0, distsOut, n));
27 free(distsOut);
28
29 distsOut = dijkstra_core(distsIn, 7, 10);
30 //as by-hand computed, distances should be as follow
31 double shouldOutput7[10] = {4.0,4.0,7.0,2.0,2.0,3.0,6.0,0.0,5.0,1.0};
32 ASSERT_TRUE(checkEqualV(shouldOutput7, distsOut, n));
33 free(distsOut);
34}
35
36//custom graph 2 (connected!)
37void test_dijkstra2()
38{
39 int n = 10;
40 // same as graph 1 above, but link between 1 and 5 is now 4.0 instead of 1.0
41 double distsIn[100] =
42 {
43 NAN,4.0,6.0,3.0,NAN,1.0,NAN,NAN,NAN,NAN,
44 4.0,NAN,NAN,5.0,NAN,4.0,3.0,NAN,1.0,NAN,
45 6.0,NAN,NAN,NAN,NAN,7.0,1.0,NAN,NAN,NAN,
46 3.0,5.0,NAN,NAN,4.0,NAN,NAN,NAN,NAN,1.0,
47 NAN,NAN,NAN,4.0,NAN,NAN,NAN,2.0,3.0,NAN,
48 1.0,4.0,7.0,NAN,NAN,NAN,NAN,3.0,NAN,NAN,
49 NAN,3.0,1.0,NAN,NAN,NAN,NAN,NAN,1.0,NAN,
50 NAN,NAN,NAN,NAN,2.0,3.0,NAN,NAN,NAN,1.0,
51 NAN,1.0,NAN,NAN,3.0,NAN,1.0,NAN,NAN,NAN,
52 NAN,NAN,NAN,1.0,NAN,NAN,NAN,1.0,NAN,NAN
53 };
54 double* distsOut;
55
56 distsOut = dijkstra_core(distsIn, 0, 10);
57 //as by-hand computed, distances should be as follow
58 double shouldOutput0[10] = {0.0,4.0,6.0,3.0,6.0,1.0,6.0,4.0,5.0,4.0};
59 ASSERT_TRUE(checkEqualV(shouldOutput0, distsOut, n));
60 free(distsOut);
61
62 distsOut = dijkstra_core(distsIn, 7, 10);
63 //as by-hand computed, distances should be as follow
64 double shouldOutput7[10] = {4.0,6.0,7.0,2.0,2.0,3.0,6.0,0.0,5.0,1.0};
65 ASSERT_TRUE(checkEqualV(shouldOutput7, distsOut, n));
66 free(distsOut);
67}