cofounderella/test/math_test.dart

89 lines
2.9 KiB
Dart
Raw Normal View History

import 'package:cofounderella/utils/math.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('Distance Calculation', () {
test('returns correct distance between Berlin and Paris', () {
// Example coordinates for Berlin and Paris
double berlinLat = 52.516216;
double berlinLon = 13.377646;
double parisLat = 48.858119;
double parisLon = 2.294483;
// Calculated distance between Berlin and Paris
double distance = calculateDistance(berlinLat, berlinLon, parisLat, parisLon);
// Expected approximate distance in kilometers
double expectedDistance = 879.1;
// Comparison of both distances
expect(distance, closeTo(expectedDistance, 1.0));
});
test('returns correct distance between same coordinates', () {
double lat = 49.469548;
double lon = 8.48243;
double distance = calculateDistance(lat, lon, lat, lon);
expect(distance, equals(0.0));
});
test('returns correct distance for long distances', () {
// Example coordinates for New York and Sydney
double newYorkLat = 40.7128;
double newYorkLon = -74.0060;
double sydneyLat = -33.8688;
double sydneyLon = 151.2093;
double distance = calculateDistance(newYorkLat, newYorkLon, sydneyLat, sydneyLon);
double expectedDistance = 15988; // in kilometers
// Comparison of the calculated and expected distance
// with a tolerance of 10 due to the enormous distance
expect(distance, closeTo(expectedDistance, 10.0));
});
});
group('Coordinate Conversion', () {
test('converts positive latitude correctly', () {
double decimalValue = 40.7128;
String result = convertDecimalToDMS(decimalValue, isLatitude: true);
expect(result, '40° 42\' 46.08" N');
});
test('converts negative latitude correctly', () {
double decimalValue = -40.7128;
String result = convertDecimalToDMS(decimalValue, isLatitude: true);
expect(result, '40° 42\' 46.08" S');
});
test('converts positive longitude correctly', () {
double decimalValue = 74.0060;
String result = convertDecimalToDMS(decimalValue, isLatitude: false);
expect(result, '74° 0\' 21.60" E');
});
test('converts negative longitude correctly', () {
double decimalValue = -74.0060;
String result = convertDecimalToDMS(decimalValue, isLatitude: false);
expect(result, '74° 0\' 21.60" W');
});
test('handles zero latitude correctly', () {
double decimalValue = 0.0;
String result = convertDecimalToDMS(decimalValue, isLatitude: true);
expect(result, '0° 0\' 0.00" N');
});
test('handles zero longitude correctly', () {
double decimalValue = 0.0;
String result = convertDecimalToDMS(decimalValue, isLatitude: false);
expect(result, '0° 0\' 0.00" E');
});
});
}