Skip to content

Commit 293d6cd

Browse files
committed
test(location): resolve every township from a point inside it
1 parent dd8e7bf commit 293d6cd

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎test/core/geo/town_boundaries_test.dart‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import 'package:dpip/core/geo/location_service.dart';
12
import 'package:dpip/core/geo/town_boundaries.dart';
3+
import 'package:dpip/core/geo/town_directory.dart';
24
import 'package:flutter_test/flutter_test.dart';
35

46
/// A few adjacent synthetic townships (Taiwan-scale coords) exercising the
@@ -129,6 +131,38 @@ void main() {
129131
expect(boundaries.codeNearCoast(22.6000, 120.2100, 5), isNull);
130132
});
131133

134+
test('every township resolves from a point inside it', () async {
135+
// The coast limit must not strand any township — the small islands are
136+
// the ones it could: 烏坵's islets, 彭佳嶼 (part of 基隆中正區), 小蘭嶼,
137+
// 東沙. One interior point per township through the real service path is
138+
// enough to catch a limit that has been widened or narrowed into them.
139+
final directory = await TownDirectory.load();
140+
final service = LocationService(
141+
directory,
142+
boundaries: Future.value(boundaries),
143+
isAvailable: () async => true,
144+
);
145+
final unreachable = <String>[];
146+
for (final town in directory.all) {
147+
final box = boundaries.boundsFor(town.code);
148+
if (box == null) {
149+
unreachable.add('${town.code} 沒有邊界資料');
150+
continue;
151+
}
152+
String? got;
153+
outer:
154+
for (var lat = box[1]; lat <= box[3]; lat += 0.004) {
155+
for (var lng = box[0]; lng <= box[2]; lng += 0.004) {
156+
if (boundaries.codeAt(lat, lng) != town.code) continue;
157+
got = (await service.townAt(lat, lng))?.code;
158+
break outer;
159+
}
160+
}
161+
if (got != town.code) unreachable.add('${town.code} → $got');
162+
}
163+
expect(unreachable, isEmpty);
164+
});
165+
132166
test('the reported Xiamen coordinate is not near a Taiwanese coast', () {
133167
// 24.449350, 118.077110 — Siming, Xiamen. Before this rule it resolved to
134168
// 金門縣 烈嶼鄉 by nearest centroid, 17 km away, and its weather card named

0 commit comments

Comments
 (0)