feat: complete working navigation functions

This commit is contained in:
2024-04-21 10:47:29 +02:00
parent 3de71e2a5a
commit ad0c8e3124
9 changed files with 237 additions and 261 deletions

View File

@ -22,6 +22,7 @@ String formatGraphFeature(GraphFeature feature) {
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
group('findAdjacent', () {
late MyMapController mapController;
late List<Feature> allFeatures;
@ -34,6 +35,69 @@ void main() {
allFeatures = mapController.features;
});
test('generates a graph (new)', () {
// Find a building feature
// final buildingFeature = allFeatures.firstWhere((f) => f.type is Building);
final buildingFeature = allFeatures
.firstWhere((f) => f.type is Building && eq(f.name, 'o28'));
// final endFeature = allFeatures
// .firstWhere((f) => f.type is Building && eq(f.name, 'o25'));
// final targetFeature = allFeatures
// .firstWhere((f) => f.type is LectureHall && eq(f.name, 'H22'));
// final wrapped =
// wrap(targetFeature, targetFeature.level!, targetFeature.building!);
// print(wrapped);
final graph = makeGraph(
wrap(buildingFeature, 2, buildingFeature.name).first, allFeatures);
final wrapped = [
graph.nodes.firstWhere((element) =>
element is BasicFeature && eq(element.feature.name, "H22"))
];
print(graph.contains(wrapped.first)); // print(graph);
print(wrapped.first.hashCode); // print(graph);
// print(wrap(targetFeature, targetFeature.level!, targetFeature.building!)
// .first
// .hashCode);
// print(wrapped.first ==
// wrap(targetFeature, targetFeature.level!, targetFeature.building!)
// .first);
// print(graph.toString());
});
test('tries to find a path through the graph using own method', () async {
// Find a building feature
// final buildingFeature = allFeatures.firstWhere((f) => f.type is Building);
final startFeature = allFeatures
.firstWhere((f) => f.type is Building && eq(f.name, 'o25'));
// final endFeature = allFeatures
// .firstWhere((f) => f.type is Building && eq(f.name, 'o25'));
final endFeature = allFeatures
.firstWhere((f) => f.type is LectureHall && eq(f.name, 'H22'));
print(endFeature);
final path = findShortestPath(
wrap(startFeature, 4, startFeature.name).first,
(f) => f is BasicFeature && eq(f.feature.name, 'H1'),
// wrap(endFeature, 2, "o28").first,
allFeatures,
);
print(path
.unwrap()
.map((e) => "${formatGraphFeature(e.$1)} (${e.$2}m)")
.join(' -> '));
});
/*
test('generates a graph', () {
// Find a building feature
// final buildingFeature = allFeatures.firstWhere((f) => f.type is Building);
@ -172,5 +236,6 @@ void main() {
print(path.map(formatGraphFeature).join('\n'));
});
*/
*/
});
}

5
test/scratch_1 Normal file

File diff suppressed because one or more lines are too long