|
4 | 4 | // |
5 | 5 |
|
6 | 6 | #include "Architecture.hpp" |
| 7 | +#include "utils.hpp" |
7 | 8 |
|
8 | 9 | #include "gtest/gtest.h" |
9 | 10 | #include <iostream> |
@@ -52,3 +53,33 @@ TEST(General, TestLineParsing) { |
52 | 53 | EXPECT_EQ(data[1], "Entry2"); |
53 | 54 | EXPECT_EQ(data[2], "EscapedEntry1;EscapedEntry2"); |
54 | 55 | } |
| 56 | + |
| 57 | +TEST(General, Dijkstra) { |
| 58 | + /* |
| 59 | + (6) |
| 60 | + .----------. |
| 61 | + \/ \/ |
| 62 | + 0 <-> 1 --> 2 <-> 3 |
| 63 | + (1) (2) (3) |
| 64 | + */ |
| 65 | + |
| 66 | + const CouplingMap cm = {{0, 1}, {1, 0}, {1, 2}, {2, 3}, |
| 67 | + {3, 2}, {1, 3}, {3, 1}}; |
| 68 | + |
| 69 | + const Matrix edgeWeights = { |
| 70 | + {0, 1, 0, 0}, {1, 0, 2, 6}, {0, 15, 0, 3}, {0, 6, 3, 0}}; |
| 71 | + |
| 72 | + const Matrix targetTable1 = { |
| 73 | + {0, 1, 3, 6}, {1, 0, 2, 5}, {10, 9, 0, 3}, {7, 6, 3, 0}}; |
| 74 | + Matrix distanceTable{}; |
| 75 | + Dijkstra::buildTable(4, cm, distanceTable, edgeWeights, |
| 76 | + [](const Dijkstra::Node& n) { return n.cost; }); |
| 77 | + EXPECT_EQ(distanceTable, targetTable1); |
| 78 | + |
| 79 | + const Matrix targetTable2 = { |
| 80 | + {0, 0, 1, 3}, {0, 0, 0, 2}, {9, 3, 0, 0}, {6, 0, 0, 0}}; |
| 81 | + distanceTable = {}; |
| 82 | + Dijkstra::buildTable(4, cm, distanceTable, edgeWeights, |
| 83 | + [](const Dijkstra::Node& n) { return n.prevCost; }); |
| 84 | + EXPECT_EQ(distanceTable, targetTable2); |
| 85 | +} |
0 commit comments