2021-05-18 14:30:32 +02:00
|
|
|
#include "closure.hh"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
map<string, set<string>> testGraph = {
|
|
|
|
{ "A", { "B", "C", "G" } },
|
|
|
|
{ "B", { "A" } }, // Loops back to A
|
|
|
|
{ "C", { "F" } }, // Indirect reference
|
|
|
|
{ "D", { "A" } }, // Not reachable, but has backreferences
|
|
|
|
{ "E", {} }, // Just not reachable
|
|
|
|
{ "F", {} },
|
|
|
|
{ "G", { "G" } }, // Self reference
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(closure, correctClosure) {
|
|
|
|
set<string> expectedClosure = {"A", "B", "C", "F", "G"};
|
2024-04-27 01:02:22 +02:00
|
|
|
set<string> aClosure = computeClosure<string>(
|
2021-05-18 14:30:32 +02:00
|
|
|
{"A"},
|
2024-04-27 01:02:22 +02:00
|
|
|
[&](const string currentNode) {
|
|
|
|
return testGraph[currentNode];
|
2021-05-18 14:30:32 +02:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
ASSERT_EQ(aClosure, expectedClosure);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(closure, properlyHandlesDirectExceptions) {
|
|
|
|
struct TestExn {};
|
|
|
|
EXPECT_THROW(
|
|
|
|
computeClosure<string>(
|
|
|
|
{"A"},
|
2024-04-27 01:02:22 +02:00
|
|
|
[&](const string currentNode) -> set<string> {
|
2021-05-18 14:30:32 +02:00
|
|
|
throw TestExn();
|
|
|
|
}
|
|
|
|
),
|
|
|
|
TestExn
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|