aboutsummaryrefslogtreecommitdiff
path: root/test/geo
diff options
context:
space:
mode:
Diffstat (limited to 'test/geo')
-rw-r--r--test/geo/countries_test.dart35
-rw-r--r--test/geo/topojson_test.dart122
2 files changed, 157 insertions, 0 deletions
diff --git a/test/geo/countries_test.dart b/test/geo/countries_test.dart
new file mode 100644
index 0000000..c1dda96
--- /dev/null
+++ b/test/geo/countries_test.dart
@@ -0,0 +1,35 @@
+import 'package:aves/geo/countries.dart';
+import 'package:aves/geo/topojson.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:latlong2/latlong.dart';
+
+void main() {
+ // [lng, lat, z]
+ const buenosAires = [-58.381667, -34.603333];
+ const paris = [2.348777, 48.875683];
+ const seoul = [126.99, 37.56, 42.0];
+ const argentinaN3String = '032';
+ const franceN3String = '250';
+ const southKoreaN3String = '410';
+
+ test('Parse countries', () async {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ final topo = await countryTopology.getTopology();
+ expect(topo != null, true);
+ if (topo == null) return;
+
+ final countries = topo.objects['countries'] as GeometryCollection;
+
+ final argentina = countries.geometries.firstWhere((geometry) => geometry.id == argentinaN3String);
+ expect(argentina.properties!['name'], 'Argentina');
+ expect(argentina.containsPoint(topo, buenosAires), true);
+ expect(argentina.containsPoint(topo, seoul), false);
+ });
+
+ test('Get country id', () async {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ expect(await countryTopology.numericCode(LatLng(buenosAires[1], buenosAires[0])), int.parse(argentinaN3String));
+ expect(await countryTopology.numericCode(LatLng(seoul[1], seoul[0])), int.parse(southKoreaN3String));
+ expect(await countryTopology.numericCode(LatLng(paris[1], paris[0])), int.parse(franceN3String));
+ });
+}
diff --git a/test/geo/topojson_test.dart b/test/geo/topojson_test.dart
new file mode 100644
index 0000000..9606a3e
--- /dev/null
+++ b/test/geo/topojson_test.dart
@@ -0,0 +1,122 @@
+import 'package:aves/geo/topojson.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() {
+ const example1 = '''
+{
+ "type": "Topology",
+ "objects": {
+ "example": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "properties": {
+ "prop0": "value0"
+ },
+ "coordinates": [102, 0.5]
+ },
+ {
+ "type": "LineString",
+ "properties": {
+ "prop0": "value0",
+ "prop1": 0
+ },
+ "arcs": [0]
+ },
+ {
+ "type": "Polygon",
+ "properties": {
+ "prop0": "value0",
+ "prop1": {
+ "this": "that"
+ }
+ },
+ "arcs": [[-2]]
+ }
+ ]
+ }
+ },
+ "arcs": [
+ [[102, 0], [103, 1], [104, 0], [105, 1]],
+ [[100, 0], [101, 0], [101, 1], [100, 1], [100, 0]]
+ ]
+}
+''';
+
+ const example1Quantized = '''
+{
+ "type": "Topology",
+ "transform": {
+ "scale": [0.0005000500050005, 0.00010001000100010001],
+ "translate": [100, 0]
+ },
+ "objects": {
+ "example": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "properties": {
+ "prop0": "value0"
+ },
+ "coordinates": [4000, 5000]
+ },
+ {
+ "type": "LineString",
+ "properties": {
+ "prop0": "value0",
+ "prop1": 0
+ },
+ "arcs": [0]
+ },
+ {
+ "type": "Polygon",
+ "properties": {
+ "prop0": "value0",
+ "prop1": {
+ "this": "that"
+ }
+ },
+ "arcs": [[1]]
+ }
+ ]
+ }
+ },
+ "arcs": [
+ [[4000, 0], [1999, 9999], [2000, -9999], [2000, 9999]],
+ [[0, 0], [0, 9999], [2000, 0], [0, -9999], [-2000, 0]]
+ ]
+}
+''';
+
+ test('parse example', () async {
+ final topo = await TopoJson().parse(example1);
+ expect(topo != null, true);
+ if (topo == null) return;
+
+ expect(topo.objects.containsKey('example'), true);
+
+ final exampleObj = topo.objects['example'] as GeometryCollection;
+ expect(exampleObj.geometries.length, 3);
+
+ final point = exampleObj.geometries[0] as Point;
+ expect(point.coordinates, [102, 0.5]);
+
+ final lineString = exampleObj.geometries[1] as LineString;
+ expect(lineString.arcs, [0]);
+
+ final polygon = exampleObj.geometries[2] as Polygon;
+ expect(polygon.arcs.first, [-2]);
+ expect(polygon.properties!.containsKey('prop0'), true);
+ });
+
+ test('parse quantized example', () async {
+ final topo = await TopoJson().parse(example1Quantized);
+ expect(topo != null, true);
+ if (topo == null) return;
+
+ expect(topo.arcs.first.first, [4000, 0]);
+ expect(topo.transform!.scale, [0.0005000500050005, 0.00010001000100010001]);
+ });
+}