import 'package:flutter_test/flutter_test.dart'; import 'package:rippr/src/domain/models.dart'; import 'package:rippr/src/ui/trips/trips_screen.dart'; /// UI-07: `RideHistorySummary.compute` is a pure function specifically so it can be /// tested directly against a hand-computed total, rather than through a screen. void main() { test('compute matches a hand-computed total over a fixed set of trips', () { final trips = [ const Trip( id: 1, startedAt: 0, endedAt: 3600000, distanceM: 20000, movingMillis: 3600000, ), const Trip( id: 2, startedAt: 0, endedAt: 1800000, distanceM: 5000, movingMillis: 1800000, ), ]; final summary = RideHistorySummary.compute(trips); expect(summary.rideCount, 2); expect(summary.totalDistanceM, 25000); expect(summary.totalMovingMillis, 5400000); // Distance-weighted, not an average of each ride's own average: 25 km over 1.5 h. expect(summary.avgSpeedKmh, closeTo(25 / 1.5, 0.0001)); }); test('an empty history has zero average speed, not a division error', () { final summary = RideHistorySummary.compute(const []); expect(summary.rideCount, 0); expect(summary.totalDistanceM, 0); expect(summary.totalMovingMillis, 0); expect(summary.avgSpeedKmh, 0); }); }