From 0edb72aaed4ebeab105d0d7d9710f160567be6ec Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Tue, 29 Jun 2021 17:07:14 +0200 Subject: [PATCH] Tests: created TrackPointAssert to unify verification (incl. speed). --- .../io/file/importer/GPXImportTest.java | 7 +- .../io/file/importer/KMLImportTest.java | 23 ++++-- .../io/file/importer/TrackPointAssert.java | 3 +- .../TrackRecordingServiceTestLocation.java | 79 +++++++++++++------ .../viewmodels/IntervalStatistics.java | 8 +- 5 files changed, 80 insertions(+), 40 deletions(-) diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java index 95db90def..9dabf221c 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXImportTest.java @@ -17,6 +17,7 @@ import java.io.InputStream; import java.util.List; import de.dennisguse.opentracks.content.data.Distance; +import de.dennisguse.opentracks.content.data.Speed; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; @@ -81,8 +82,10 @@ public class GPXImportTest { TrackPointAssert a = new TrackPointAssert(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2021-01-07T21:51:59.179Z", 14.0, 3.0, 10.0), - a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:00.653Z", 14.001, 3.0, 10.0), - a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:01.010Z", 14.002, 3.0, 10.0), + a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:00.653Z", 14.001, 3.0, 10.0) + .setSpeed(Speed.of(75.4192)), + a.expect(TrackPoint.Type.TRACKPOINT, "2021-01-07T21:52:01.010Z", 14.002, 3.0, 10.0) + .setSpeed(Speed.of(311.3948)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL, "2021-01-07T21:52:02.658Z"), // created resume trackpoint with time of next valid trackpoint diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java index a06f92750..5840f6cf5 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLImportTest.java @@ -17,6 +17,7 @@ import java.io.InputStream; import java.util.List; import de.dennisguse.opentracks.content.data.Distance; +import de.dennisguse.opentracks.content.data.Speed; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; @@ -82,8 +83,10 @@ public class KMLImportTest { a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL, "2021-05-29T18:06:21.767Z"), a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.042Z", 14.0, 3.0, 10.0), - a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.192Z", 14.001, 3.0, 10.0), - a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.318Z", 14.002, 3.0, 10.0), + a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.192Z", 14.001, 3.0, 10.0) + .setSpeed(Speed.of(741.1196)), + a.expect(TrackPoint.Type.TRACKPOINT, "2021-05-29T18:06:22.318Z", 14.002, 3.0, 10.0) + .setSpeed(Speed.of(882.2853)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL, "2021-05-29T18:06:22.512Z") ), importedTrackPoints); } @@ -158,19 +161,25 @@ public class KMLImportTest { a.assertEquals(List.of( // first 3 trackpoints a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:22.401Z", 1.234156, 12.340097, 469.286376953125) - .setAltitudeGain(0f), + .setAltitudeGain(0f) + .setSpeed(Speed.of(0.539)), a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:25.448Z", 1.23415, 12.340036, 439.1626281738281) - .setAltitudeGain(0f), + .setAltitudeGain(0f) + .setSpeed(Speed.of(0.1577)), a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:47.888Z", 1.23405, 12.340057, 421.8070983886719) - .setAltitudeGain(0f), + .setAltitudeGain(0f) + .setSpeed(Speed.of(0)), // created resume trackpoint with time of next valid trackpoint a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, "2020-11-28T17:06:55.861Z", 1.23405, 12.340057, 419.93902587890625) - .setAltitudeGain(0f), + .setAltitudeGain(0f) + .setSpeed(Speed.of(0)), a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:06:56.905Z", 1.23405, 12.340057, 419.9036560058594) - .setAltitudeGain(0f), + .setAltitudeGain(0f) + .setSpeed(Speed.of(0)), a.expect(TrackPoint.Type.TRACKPOINT, "2020-11-28T17:07:20.870Z", 1.234046, 12.340082, 417.99432373046875) .setAltitudeGain(0f) + .setSpeed(Speed.of(0)) ), importedTrackPoints); } diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java index 34b9c795e..14529fb4b 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/TrackPointAssert.java @@ -45,8 +45,7 @@ public class TrackPointAssert { Assert.assertEquals(expected.getAltitudeLoss(), actual.getAltitudeLoss(), 0.001); } - // TODO Speed is always computed even if none was exported, thus this assert fails for now; -// Assert.assertEquals(expected.hasSpeed(), actual.hasSpeed()); + Assert.assertEquals(expected.hasSpeed(), actual.hasSpeed()); if (expected.hasSpeed()) { Assert.assertEquals(expected.getSpeed().toMPS(), actual.getSpeed().toMPS(), 0.001); } diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java index e145a96ab..383ccf835 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceTestLocation.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import de.dennisguse.opentracks.content.data.Speed; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.Track; import de.dennisguse.opentracks.content.data.TrackPoint; @@ -117,12 +118,18 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1), - a.expect(TrackPoint.Type.TRACKPOINT, 2), - a.expect(TrackPoint.Type.TRACKPOINT, 3), - a.expect(TrackPoint.Type.TRACKPOINT, 4), - a.expect(TrackPoint.Type.TRACKPOINT, 5), - a.expect(TrackPoint.Type.TRACKPOINT, 6), + a.expect(TrackPoint.Type.TRACKPOINT, 1) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 2) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 3) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 4) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 5) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 6) + .setSpeed(Speed.of(15)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL) ), trackPoints); } @@ -152,8 +159,10 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1), - a.expect(TrackPoint.Type.TRACKPOINT, 6), + a.expect(TrackPoint.Type.TRACKPOINT, 1) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 6) + .setSpeed(Speed.of(15)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL) ), trackPoints); } @@ -182,9 +191,12 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1), - a.expect(TrackPoint.Type.TRACKPOINT, 2), - a.expect(TrackPoint.Type.TRACKPOINT, 6), + a.expect(TrackPoint.Type.TRACKPOINT, 1) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 2) //TODO Why is this added? Systems is idle and not moving at all. + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 6) + .setSpeed(Speed.of(0)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL) ), trackPoints); } @@ -213,10 +225,14 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1), - a.expect(TrackPoint.Type.TRACKPOINT, 2), - a.expect(TrackPoint.Type.TRACKPOINT, 5), //TODO Check why this trackPoint is inserted. - a.expect(TrackPoint.Type.TRACKPOINT, 6), + a.expect(TrackPoint.Type.TRACKPOINT, 1) + .setSpeed(Speed.of(15)), + a.expect(TrackPoint.Type.TRACKPOINT, 2) //TODO Check why this trackPoint is inserted. + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 5) //TODO Check why this trackPoint is inserted. + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 6) + .setSpeed(Speed.of(15)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL) ), trackPoints); } @@ -260,12 +276,18 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1, 5f), - a.expect(TrackPoint.Type.TRACKPOINT, 2, 5f), - a.expect(TrackPoint.Type.TRACKPOINT, 3, 5f), - a.expect(TrackPoint.Type.TRACKPOINT, 4, 5f), - a.expect(TrackPoint.Type.TRACKPOINT, 5, 5f), - a.expect(TrackPoint.Type.TRACKPOINT, 6, 5f), + a.expect(TrackPoint.Type.TRACKPOINT, 1, 5f) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 2, 5f) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 3, 5f) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 4, 5f) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 5, 5f) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 6, 5f) + .setSpeed(Speed.of(0)), a.expecHeartrate(TrackPoint.Type.SEGMENT_END_MANUAL, 5f) ), trackPoints); } @@ -294,13 +316,18 @@ public class TrackRecordingServiceTestLocation { .ignoreTime(); a.assertEquals(List.of( a.expect(TrackPoint.Type.SEGMENT_START_MANUAL), - a.expect(TrackPoint.Type.TRACKPOINT, 1), + a.expect(TrackPoint.Type.TRACKPOINT, 1) + .setSpeed(Speed.of(0)), - a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 2), - a.expect(TrackPoint.Type.TRACKPOINT, 3), + a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 2) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 3) + .setSpeed(Speed.of(0)), - a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 4), - a.expect(TrackPoint.Type.TRACKPOINT, 5), + a.expect(TrackPoint.Type.SEGMENT_START_AUTOMATIC, 4) + .setSpeed(Speed.of(0)), + a.expect(TrackPoint.Type.TRACKPOINT, 5) + .setSpeed(Speed.of(0)), a.expect(TrackPoint.Type.SEGMENT_END_MANUAL) ), trackPoints); } diff --git a/src/main/java/de/dennisguse/opentracks/viewmodels/IntervalStatistics.java b/src/main/java/de/dennisguse/opentracks/viewmodels/IntervalStatistics.java index 35102a07d..a751876ce 100644 --- a/src/main/java/de/dennisguse/opentracks/viewmodels/IntervalStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/viewmodels/IntervalStatistics.java @@ -164,9 +164,11 @@ public class IntervalStatistics { time = time.plus(trackStatistics.getTotalTime()); gain_m = trackStatistics.hasTotalAltitudeGain() ? trackStatistics.getTotalAltitudeGain() : gain_m; loss_m = trackStatistics.hasTotalAltitudeLoss() ? trackStatistics.getTotalAltitudeLoss() : loss_m; - if (lastTrackPoint != null) { - gain_m = lastTrackPoint.hasAltitudeGain() ? gain_m - lastTrackPoint.getAltitudeGain() : gain_m; - loss_m = lastTrackPoint.hasAltitudeLoss() ? loss_m - lastTrackPoint.getAltitudeLoss() : loss_m; + if (gain_m != null && lastTrackPoint != null && lastTrackPoint.hasAltitudeGain()) { + gain_m = gain_m - lastTrackPoint.getAltitudeGain(); + } + if (loss_m != null && lastTrackPoint != null && lastTrackPoint.hasAltitudeLoss()) { + loss_m = loss_m - lastTrackPoint.getAltitudeLoss(); } }