63 lines
2.3 KiB
Dart
63 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:motorcycle_dash/services/routes/valhalla_polyline_decoder.dart';
|
|
|
|
void main() {
|
|
group('ValhallaPolylineDecoder', () {
|
|
test('handles empty string', () {
|
|
final points = ValhallaPolylineDecoder.decode('');
|
|
expect(points, isEmpty);
|
|
});
|
|
|
|
test('decodes single point with precision 6', () {
|
|
// Deterministic fixture for (37.774900, -122.419400)
|
|
final points = ValhallaPolylineDecoder.decode('gbr`gAnk{nhF');
|
|
expect(points.length, 1);
|
|
expect(points[0].latitude, closeTo(37.7749, 1e-5));
|
|
expect(points[0].longitude, closeTo(-122.4194, 1e-5));
|
|
});
|
|
|
|
test('decodes multiple points with positive deltas (SF to Oakland)', () {
|
|
// SF (37.774900, -122.419400) -> Oakland (37.804400, -122.271200)
|
|
final points = ValhallaPolylineDecoder.decode('gbr`gAnk{nhFwrx@om`H');
|
|
expect(points.length, 2);
|
|
expect(points[0].latitude, closeTo(37.7749, 1e-5));
|
|
expect(points[0].longitude, closeTo(-122.4194, 1e-5));
|
|
expect(points[1].latitude, closeTo(37.8044, 1e-5));
|
|
expect(points[1].longitude, closeTo(-122.2712, 1e-5));
|
|
});
|
|
|
|
test('decodes multiple points with negative lat delta (SF to San Jose)', () {
|
|
// SF (37.774900, -122.419400) -> San Jose (37.338200, -121.886300)
|
|
final points = ValhallaPolylineDecoder.decode('gbr`gAnk{nhFv|sYwep_@');
|
|
expect(points.length, 2);
|
|
expect(points[0].latitude, closeTo(37.7749, 1e-5));
|
|
expect(points[0].longitude, closeTo(-122.4194, 1e-5));
|
|
expect(points[1].latitude, closeTo(37.3382, 1e-5));
|
|
expect(points[1].longitude, closeTo(-121.8863, 1e-5));
|
|
});
|
|
|
|
test('throws FormatException on truncated polyline', () {
|
|
expect(
|
|
() => ValhallaPolylineDecoder.decode('gbr`gA'),
|
|
throwsA(isA<FormatException>()),
|
|
);
|
|
});
|
|
|
|
test('throws FormatException on invalid characters (ascii < 63)', () {
|
|
expect(
|
|
() => ValhallaPolylineDecoder.decode('gbr\x00gAnk'),
|
|
throwsA(isA<FormatException>()),
|
|
);
|
|
});
|
|
|
|
test('throws FormatException when coordinates exceed geographic bounds', () {
|
|
// Encoded value that unpacks to latitude > 90
|
|
// 95.0 * 1e6 = 95000000
|
|
expect(
|
|
() => ValhallaPolylineDecoder.decode('____~_~_~_~_~_'),
|
|
throwsA(isA<FormatException>()),
|
|
);
|
|
});
|
|
});
|
|
}
|