Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup: use record if possible #1710

Merged
merged 4 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.dennisguse.opentracks;


import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
Expand All @@ -12,7 +11,6 @@
import static androidx.test.espresso.matcher.ViewMatchers.withParentIndex;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static de.dennisguse.opentracks.util.EspressoUtils.childAtPosition;
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.dennisguse.opentracks;

import static androidx.test.espresso.Espresso.onData;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.longClick;
Expand All @@ -11,7 +10,6 @@
import static androidx.test.espresso.matcher.ViewMatchers.withParent;
import static androidx.test.espresso.matcher.ViewMatchers.withParentIndex;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anything;
import static de.dennisguse.opentracks.util.EspressoUtils.selectTabAtIndex;
import static de.dennisguse.opentracks.util.EspressoUtils.waitFor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public void create_by_time() {
statistics.setTotalTime(Duration.ofSeconds(1000));

// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), false, UnitSystem.IMPERIAL_FEET);

// then
assertEquals(1000000, (long) point.getTimeOrDistance());
assertEquals(1000000, (long) point.timeOrDistance());
}

@Test
Expand All @@ -40,10 +40,10 @@ public void create_by_distance() {
statistics.setTotalDistance(Distance.of(1000));

// when
ChartPoint point = new ChartPoint(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, TrackStubUtils.createDefaultTrackPoint(), Speed.of(0), true, UnitSystem.METRIC);

// then
assertEquals(1, (long) point.getTimeOrDistance());
assertEquals(1, (long) point.timeOrDistance());
}

@Test
Expand All @@ -54,12 +54,12 @@ public void create_get_altitude_speed_and_pace() {
.setAltitude(Altitude.EGM2008.of(50));

// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertEquals(50, point.getAltitude(), 0.01);
assertEquals(36, point.getSpeed(), 0.01);
assertEquals(1.66, point.getPace(), 0.01);
assertEquals(50, point.altitude(), 0.01);
assertEquals(36, point.speed(), 0.01);
assertEquals(1.66, point.pace(), 0.01);
}

@Test
Expand All @@ -69,12 +69,12 @@ public void create_sensorNotAvailable() {
TrackPoint trackPoint = TrackStubUtils.createDefaultTrackPoint()
.setAltitude(Altitude.EGM2008.of(50));
// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertNull(point.getHeartRate());
assertNull(point.getCadence());
assertNull(point.getPower());
assertNull(point.heartRate());
assertNull(point.cadence());
assertNull(point.power());
}

@Test
Expand All @@ -89,11 +89,11 @@ public void create_sensorAvailable() {
TrackStatistics statistics = new TrackStatistics();

// when
ChartPoint point = new ChartPoint(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);
ChartPoint point = ChartPoint.create(statistics, trackPoint, Speed.of(10), false, UnitSystem.METRIC);

// then
assertEquals(100.0, point.getHeartRate(), 0.01);
assertEquals(101.0, point.getCadence(), 0.01);
assertEquals(102.0, point.getPower(), 0.01);
assertEquals(100.0, point.heartRate(), 0.01);
assertEquals(101.0, point.cadence(), 0.01);
assertEquals(102.0, point.power(), 0.01);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void setUp() {
18) {
@Override
Double extractDataFromChartPoint(@NonNull ChartPoint chartPoint) {
return chartPoint.getAltitude();
return chartPoint.altitude();
}

@Override
Expand All @@ -80,9 +80,9 @@ public void testEnabled() {

@Test
public void testVerySmallUpdates() {
series.update(new ChartPoint(1f));
series.update(new ChartPoint(2f));
series.update(new ChartPoint(3f));
series.update(withAltitude(1f));
series.update(withAltitude(2f));
series.update(withAltitude(3f));
series.updateDimension();
assertEquals(1, series.getInterval());
assertEquals(1, series.getMinMarkerValue());
Expand All @@ -91,8 +91,8 @@ public void testVerySmallUpdates() {

@Test
public void testSmallUpdates() {
series.update(new ChartPoint(0));
series.update(new ChartPoint(10));
series.update(withAltitude(0));
series.update(withAltitude(10));
series.updateDimension();
assertEquals(100, series.getInterval());
assertEquals(0, series.getMinMarkerValue());
Expand All @@ -101,8 +101,8 @@ public void testSmallUpdates() {

@Test
public void testBigUpdates() {
series.update(new ChartPoint(0));
series.update(new ChartPoint(901));
series.update(withAltitude(0));
series.update(withAltitude(901));
series.updateDimension();
assertEquals(1000, series.getInterval());
assertEquals(0, series.getMinMarkerValue());
Expand All @@ -111,11 +111,23 @@ public void testBigUpdates() {

@Test
public void testNotZeroBasedUpdates() {
series.update(new ChartPoint(220));
series.update(new ChartPoint(250));
series.update(withAltitude(220));
series.update(withAltitude(250));
series.updateDimension();
assertEquals(100, series.getInterval());
assertEquals(200, series.getMinMarkerValue());
assertEquals(700, series.getMaxMarkerValue());
}

static ChartPoint withAltitude(double altitude) {
return new ChartPoint(
0,
altitude,
null,
null,
null,
null,
null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -986,13 +986,13 @@ public void testGetSensorStats_needAtLeastTwoTrackPointsTrue() {

// then
assertTrue(sensorStatistics.hasHeartRate());
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertTrue(sensorStatistics.hasCadence());
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertTrue(sensorStatistics.hasPower());
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}

@Test
Expand All @@ -1018,8 +1018,8 @@ public void testGetSensorStats_onlyHr() {

// then
assertTrue(sensorStatistics.hasHeartRate());
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertFalse(sensorStatistics.hasCadence());
assertFalse(sensorStatistics.hasPower());
}
Expand Down Expand Up @@ -1048,8 +1048,8 @@ public void testGetSensorStats_onlyCadence() {
// then
assertFalse(sensorStatistics.hasHeartRate());
assertTrue(sensorStatistics.hasCadence());
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertFalse(sensorStatistics.hasPower());
}

Expand Down Expand Up @@ -1078,7 +1078,7 @@ public void testGetSensorStats_onlyPower() {
assertFalse(sensorStatistics.hasHeartRate());
assertFalse(sensorStatistics.hasCadence());
assertTrue(sensorStatistics.hasPower());
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}

@Test
Expand Down Expand Up @@ -1111,11 +1111,11 @@ public void testGetSensorStats() {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();

// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}

@Test
Expand Down Expand Up @@ -1156,11 +1156,11 @@ public void testGetSensorStats_withManualResume() {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();

// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}

@Test
Expand Down Expand Up @@ -1201,11 +1201,11 @@ public void testGetSensorStats_withStartAutomatic() {
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();

// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0f);
}

private void testGetSensorStats_randomData(int totalPoints, boolean withStartSegments) {
Expand All @@ -1232,11 +1232,11 @@ private void testGetSensorStats_randomData(int totalPoints, boolean withStartSeg
TestSensorDataUtil.SensorDataStats stats = sensorDataUtil.computeStats();

// then
assertEquals(sensorStatistics.getAvgHeartRate().getBPM(), stats.avgHr, 0.01f);
assertEquals(sensorStatistics.getMaxHeartRate().getBPM(), stats.maxHr, 0.01f);
assertEquals(sensorStatistics.getAvgCadence().getRPM(), stats.avgCadence, 0.01f);
assertEquals(sensorStatistics.getMaxCadence().getRPM(), stats.maxCadence, 0.01f);
assertEquals(sensorStatistics.getAvgPower().getW(), stats.avgPower, 0.01f);
assertEquals(sensorStatistics.avgHeartRate().getBPM(), stats.avgHr, 0.01f);
assertEquals(sensorStatistics.maxHeartRate().getBPM(), stats.maxHr, 0.01f);
assertEquals(sensorStatistics.avgCadence().getRPM(), stats.avgCadence, 0.01f);
assertEquals(sensorStatistics.maxCadence().getRPM(), stats.maxCadence, 0.01f);
assertEquals(sensorStatistics.avgPower().getW(), stats.avgPower, 0.01f);
}

@Test
Expand Down
Loading
Loading