Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Update the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
synw committed Oct 21, 2019
1 parent 64ed079 commit 04350b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
23 changes: 21 additions & 2 deletions test/geopoint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ void main() {
str += "Altitude: ${geoPoint.altitude}\n";
str += "Speed: ${geoPoint.speed}\n";
str += "Heading: ${geoPoint.heading}\n";
expect(geoPoint.toString(), equals(str));
expect(geoPoint.toString(), equals("Geopoint ${geoPoint.name}"));
expect(geoPoint.details(), equals(str));
});

test("from json", () {
Expand Down Expand Up @@ -134,10 +135,28 @@ void main() {
throwsA(predicate<dynamic>((dynamic e) => e is AssertionError)));
});

test("from latlng", () {
test("latlng", () {
var geoPoint = GeoPoint.fromLatLng(name: "gp", point: LatLng(0.0, 0.0));
expect(geoPoint.latitude, equals(0.0));
expect(geoPoint.longitude, equals(0.0));
final tl = geoPoint.toLatLng();
expect(LatLng(0.0, 0.0), tl);
});

test("tostring", () {
var geoPoint = GeoPoint(latitude: 0.0, longitude: 0.0);
expect(geoPoint.toString(), "Geopoint 0.0/0.0");
});

test("geojson", () {
var geoPoint = GeoPoint(latitude: 0.0, longitude: 0.0, name: "gp");
expect(geoPoint.toGeoJsonCoordinatesString(), "[0.0,0.0]");
final str = '[{"type":"Feature","properties":{"name":"gp"}, ' +
'"geometry":{"type":"Point",' +
'"coordinates":' +
geoPoint.toGeoJsonCoordinatesString() +
'}}]';
expect(geoPoint.toGeoJsonFeatureString(), str);
});

test("address", () {
Expand Down
42 changes: 35 additions & 7 deletions test/geoserie_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "package:test/test.dart";
import 'package:geopoint/geopoint.dart';
import 'package:latlong/latlong.dart';

void main() {
var geoPoints = <GeoPoint>[
Expand Down Expand Up @@ -28,13 +29,6 @@ void main() {
expect(geoSerie.boundary, equals(boundary));
});

test("null", () {
expect(() => GeoSerie(name: null, type: GeoSerieType.line),
throwsA(predicate<dynamic>((dynamic e) => e is AssertionError)));
expect(() => GeoSerie(name: "gs", type: null),
throwsA(predicate<dynamic>((dynamic e) => e is AssertionError)));
});

test("type", () {
expect(
GeoSerie(name: "gs", type: GeoSerieType.line).typeStr, equals("line"));
Expand Down Expand Up @@ -79,4 +73,38 @@ void main() {
expect(() => GeoSerie.fromNameAndType(name: "gs", typeStr: null),
throwsA(predicate<dynamic>((dynamic e) => e is AssertionError)));
});

test("latlng", () {
expect(<LatLng>[LatLng(0.0, 0.0), LatLng(1.0, 1.0)], geoSerie.toLatLng());
});

test("geojson", () {
final gs =
GeoSerie(name: "gs", type: GeoSerieType.group, geoPoints: <GeoPoint>[
GeoPoint(latitude: 0.0, longitude: 0.0),
GeoPoint(latitude: 1.0, longitude: 1.0),
]);
final res = "[[0.0,0.0],[1.0,1.0]]";
expect(gs.toGeoJsonCoordinatesString(), res);
var str = '[{"type":"Feature","properties":{"name":"gs"}, ' +
'"geometry":{"type":"MultiPoint",' +
'"coordinates":' +
gs.toGeoJsonCoordinatesString() +
'}}]';
expect(gs.toGeoJsonFeatureString(), str);
gs.type = GeoSerieType.line;
str = '[{"type":"Feature","properties":{"name":"gs"}, ' +
'"geometry":{"type":"Line",' +
'"coordinates":' +
gs.toGeoJsonCoordinatesString() +
'}}]';
expect(gs.toGeoJsonFeatureString(), str);
gs.type = GeoSerieType.polygon;
str = '[{"type":"Feature","properties":{"name":"gs"}, ' +
'"geometry":{"type":"Polygon",' +
'"coordinates":[' +
gs.toGeoJsonCoordinatesString() +
']}}]';
expect(gs.toGeoJsonFeatureString(), str);
});
}

0 comments on commit 04350b7

Please sign in to comment.