LCOV - code coverage report
Current view: top level - Users/yeradis/Projects/Garage/dart/stay_points.dart/test - offline_identification_test.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 41 41 100.0 %
Date: 2017-10-10 20:17:03 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:stay_points/stay_points.dart';
       2             : import 'package:test/test.dart';
       3             : 
       4             : void main() {
       5           1 :     group('Offline stay-point identification', () {
       6             :         final lat1 = 41.139129;
       7             :         final lon1 = 1.402244;
       8             : 
       9           1 :         final Location location = new Location.fromDegrees(latitude: lat1,
      10           1 :             longitude: lon1, timestamp: new DateTime.now());
      11             : 
      12             :         StayPointIdentification extractor;
      13             : 
      14           1 :         setUp(() {
      15           1 :             Threshold threshold = new Threshold(
      16           2 :                 minimumTime: new Duration(minutes: 4), minimumDistance: new Distance(meters: 20.0));
      17           1 :             extractor = new StayPointIdentification(threshold);
      18             :         });
      19             : 
      20           1 :         test('Having nil should no throw', () {
      21           3 :             expect(extractor.process(locations: null), isNot(Exception));
      22             :         });
      23             : 
      24           1 :         test('Having nil should return something', () {
      25           2 :             expect(extractor.process(locations: null), isNotNull);
      26             :         });
      27             : 
      28           1 :         test('Having nil should return empty list', () {
      29           2 :             expect(extractor.process(locations: null), isEmpty);
      30             :         });
      31             : 
      32           1 :         test('Having one location should return empty list', () {
      33           3 :             expect(extractor.process(locations: [location]), isEmpty);
      34             :         });
      35             : 
      36           1 :         test('Having same location twice should return empty list', () {
      37           3 :             expect(extractor.process(locations: [location, location]), isEmpty);
      38             :         });
      39             : 
      40           1 :         test('Having same location multiple times should return empty list', () {
      41           3 :             expect(extractor.process(locations: [location, location, location, location, location]),
      42             :                 isEmpty);
      43             :         });
      44             : 
      45           1 :         test('Having two locations that pass the threshold validation (time, distance) should return 1 stay-point with just one involved location in the calculus', () {
      46             : 
      47           1 :             DateTime date1 = new DateTime(2017, 9, 27, 13, 06, 29);
      48           1 :             Location location1 = new Location.fromDegrees(
      49             :                 latitude: 41.141903,
      50             :                 longitude: 1.401316,
      51             :                 timestamp: date1
      52             :             );
      53             : 
      54           1 :             DateTime date2 = new DateTime(2017, 9, 27, 13, 12, 11);
      55           1 :             Location location2 = new Location.fromDegrees(
      56             :                 latitude: 41.141183,
      57             :                 longitude: 1.401788,
      58             :                 timestamp: date2);
      59             : 
      60           2 :             List<StayPoint> stayPoints = extractor.process(locations: [location1, location2]);
      61           3 :             expect(stayPoints.length, equals(1));
      62           5 :             expect(stayPoints.first.locationsInvolved.length, equals(1));
      63           1 :         }, tags: ["multiple"]);
      64             : 
      65           1 :         test('Should match returned StayPoint - Having two locations that pass the threshold validation (time, distance) returns 1 stay-point with just one involved location in the calculus', () {
      66             : 
      67           1 :             DateTime date1 = new DateTime(2017, 9, 27, 13, 06, 29);
      68           1 :             Location location1 = new Location.fromDegrees(
      69             :                 latitude: 41.141903,
      70             :                 longitude: 1.401316,
      71             :                 timestamp: date1
      72             :             );
      73             : 
      74           1 :             DateTime date2 = new DateTime(2017, 9, 27, 13, 12, 11);
      75           1 :             Location location2 = new Location.fromDegrees(
      76             :                 latitude: 41.141183,
      77             :                 longitude: 1.401788,
      78             :                 timestamp: date2);
      79             : 
      80           6 :             StayPoint stayPoint = new StayPoint(latitude: location1.latitude, longitude: location1.longitude, arrival: location1.timestamp, departure: location1.timestamp, locationsInvolved: [location1]);
      81             : 
      82           3 :             expect(extractor.process(locations: [location1, location2]),
      83           2 :                 equals(predicate((e) =>
      84           1 :                     e is List<StayPoint>
      85           5 :                     && e.first.location.compareTo(stayPoint.location) == 0
      86           5 :                     && e.first.arrival.compareTo(stayPoint.arrival) == 0
      87           5 :                     && e.first.departure.compareTo(stayPoint.departure) == 0
      88           6 :                     && e.first.locationsInvolved.first.compareTo(stayPoint.location) == 0
      89             :                 )));
      90             :         });
      91             :     });
      92             : }

Generated by: LCOV version 1.13