|
| 1 | +import 'package:dpip/core/geo/location_service.dart'; |
1 | 2 | import 'package:dpip/core/geo/town_boundaries.dart'; |
| 3 | +import 'package:dpip/core/geo/town_directory.dart'; |
2 | 4 | import 'package:flutter_test/flutter_test.dart'; |
3 | 5 |
|
4 | 6 | /// A few adjacent synthetic townships (Taiwan-scale coords) exercising the |
@@ -129,6 +131,38 @@ void main() { |
129 | 131 | expect(boundaries.codeNearCoast(22.6000, 120.2100, 5), isNull); |
130 | 132 | }); |
131 | 133 |
|
| 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 | + |
132 | 166 | test('the reported Xiamen coordinate is not near a Taiwanese coast', () { |
133 | 167 | // 24.449350, 118.077110 — Siming, Xiamen. Before this rule it resolved to |
134 | 168 | // 金門縣 烈嶼鄉 by nearest centroid, 17 km away, and its weather card named |
|
0 commit comments