40 lines
1 KiB
C++
40 lines
1 KiB
C++
#include <iostream>
|
|
#include <memory>
|
|
#include <cassert>
|
|
|
|
#include "basic_testing.h"
|
|
|
|
#include "../roadmap.h"
|
|
|
|
TEST(example) {
|
|
std::unique_ptr<AbstractRoadMap> m(createRoadMap());
|
|
|
|
// Add roads on one island:
|
|
m->addRoad("Sengkol", "Sakra");
|
|
m->addRoad({"Mataram", "Mangsit", "Pamenang"});
|
|
m->addRoad({"Mataram", "Sengkol", "Koeta"});
|
|
|
|
assert_int_eq(m->countIslands(), 1);
|
|
assert_true(m->reachable("Sengkol", "Mataram"));
|
|
assert_int_eq(m->neighborCountForCity("Mataram"), 2);
|
|
assert_int_eq(m->neighborCountForCity("Pamenang"), 1);
|
|
assert_false(m->hasLoop());
|
|
|
|
// Create a loop:
|
|
m->addRoad("Sakra", "Mataram");
|
|
assert_true(m->hasLoop());
|
|
|
|
// Add roads on another island:
|
|
m->addRoad({"Denpasar", "Sukawati", "Ubud"});
|
|
assert_int_eq(m->countIslands(), 2);
|
|
|
|
// Cities on different islands are not reachable:
|
|
assert_false(m->reachable("Sengkol", "Sukawati"));
|
|
TEST_PASSED;
|
|
}
|
|
|
|
int main() {
|
|
RUN_TEST(example);
|
|
PRINT_TEST_RESULTS;
|
|
assert(ALL_TESTS_PASSED);
|
|
}
|