forked from upstream-mirrors/OpenTracks
Clean up Constants.java
This commit is contained in:
+51
-48
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services;
|
||||
|
||||
import static com.google.android.apps.mytracks.Constants.RESUME_TRACK_EXTRA_NAME;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProvider;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
@@ -57,13 +55,13 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests for the MyTracks track recording service.
|
||||
*
|
||||
* <p>
|
||||
* TODO: The original class, ServiceTestCase, has a few limitations, e.g. it's
|
||||
* not possible to properly shutdown the service, unless tearDown() is called,
|
||||
* which prevents from testing multiple scenarios in a single test (see
|
||||
* runFunctionTest for more details).
|
||||
*
|
||||
* @author Bartlomiej Niechwiej
|
||||
*
|
||||
* TODO: The original class, ServiceTestCase, has a few limitations, e.g.
|
||||
* it's not possible to properly shutdown the service, unless tearDown()
|
||||
* is called, which prevents from testing multiple scenarios in a single
|
||||
* test (see runFunctionTest for more details).
|
||||
*/
|
||||
public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingService> {
|
||||
|
||||
@@ -71,9 +69,9 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
private MyTracksProviderUtils providerUtils;
|
||||
|
||||
/*
|
||||
* In order to support starting and binding to the service in the same
|
||||
* unit test, we provide a workaround, as the original class doesn't allow
|
||||
* to bind after the service has been previously started.
|
||||
* In order to support starting and binding to the service in the same unit
|
||||
* test, we provide a workaround, as the original class doesn't allow to bind
|
||||
* after the service has been previously started.
|
||||
*/
|
||||
|
||||
private boolean bound;
|
||||
@@ -84,9 +82,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
|
||||
/**
|
||||
* A context wrapper with the user provided {@link ContentResolver}.
|
||||
*
|
||||
* TODO: Move to test utils package.
|
||||
* A context wrapper with the user provided {@link ContentResolver}. TODO:
|
||||
* Move to test utils package.
|
||||
*/
|
||||
public static class MockContext extends ContextWrapper {
|
||||
private final ContentResolver contentResolver;
|
||||
@@ -106,8 +103,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
protected IBinder bindService(Intent intent) {
|
||||
if (getService() != null) {
|
||||
if (bound) {
|
||||
throw new IllegalStateException(
|
||||
"Service: " + getService() + " is already bound");
|
||||
throw new IllegalStateException("Service: " + getService() + " is already bound");
|
||||
}
|
||||
bound = true;
|
||||
serviceIntent = intent.cloneFilter();
|
||||
@@ -144,12 +140,13 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
MyTracksProvider myTracksProvider = new MyTracksProvider();
|
||||
myTracksProvider.attachInfo(context, null);
|
||||
mockContentResolver.addProvider(MyTracksProviderUtils.AUTHORITY, myTracksProvider);
|
||||
|
||||
|
||||
MockContentProvider settingsProvider = new MockContentProvider(context) {
|
||||
@Override
|
||||
public Bundle call(String method, String arg, Bundle extras) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
@@ -157,12 +154,13 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
};
|
||||
mockContentResolver.addProvider(Settings.AUTHORITY, settingsProvider);
|
||||
|
||||
|
||||
MockContentProvider googleSettingsProvider = new MockContentProvider(context) {
|
||||
@Override
|
||||
public Bundle call(String method, String arg, Bundle extras) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
@@ -171,14 +169,17 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
public int getCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean moveToNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) {
|
||||
return MyTracksLocationManager.USE_LOCATION_FOR_SERVICES_ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {}
|
||||
};
|
||||
@@ -186,7 +187,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
};
|
||||
mockContentResolver.addProvider("com.google.settings", googleSettingsProvider);
|
||||
|
||||
|
||||
// Set the context
|
||||
setContext(context);
|
||||
|
||||
@@ -227,7 +228,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
||||
startService(startIntent);
|
||||
assertNotNull(getService());
|
||||
|
||||
@@ -237,12 +238,13 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertEquals(123L, service.getRecordingTrackId());
|
||||
}
|
||||
|
||||
// TODO: shutdownService() has a bug and doesn't set mServiceCreated
|
||||
// to false, thus preventing from a second call to onCreate().
|
||||
// Report the bug to Android team. Until then, the following tests
|
||||
// and checks must be commented out.
|
||||
//
|
||||
// TODO: If fixed, remove "disabled" prefix from the test name.
|
||||
/*
|
||||
* TODO: shutdownService() has a bug and doesn't set mServiceCreated to false,
|
||||
* thus preventing from a second call to onCreate(). Report the bug to Android
|
||||
* team. Until then, the following tests and checks must be commented out.
|
||||
*
|
||||
* TODO: If fixed, remove "disabled" prefix from the test name.
|
||||
*/
|
||||
@MediumTest
|
||||
public void disabledTestResumeAfterReboot_simulateReboot() throws Exception {
|
||||
updateAutoResumePrefs(PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT,
|
||||
@@ -259,7 +261,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
||||
startService(startIntent);
|
||||
assertNotNull(getService());
|
||||
|
||||
@@ -277,7 +279,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
||||
startService(startIntent);
|
||||
assertNotNull(getService());
|
||||
|
||||
@@ -298,7 +300,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
||||
startService(startIntent);
|
||||
assertNotNull(getService());
|
||||
|
||||
@@ -319,7 +321,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
||||
Intent startIntent = createStartIntent();
|
||||
startIntent.putExtra(RESUME_TRACK_EXTRA_NAME, true);
|
||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
||||
startService(startIntent);
|
||||
assertNotNull(getService());
|
||||
|
||||
@@ -437,8 +439,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertEquals(1, receivedIntents.size());
|
||||
Intent broadcastIntent = receivedIntents.get(0);
|
||||
assertEquals(startAction, broadcastIntent.getAction());
|
||||
assertEquals(id, broadcastIntent.getLongExtra(
|
||||
context.getString(R.string.track_id_broadcast_extra), -1L));
|
||||
assertEquals(id,
|
||||
broadcastIntent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L));
|
||||
|
||||
context.unregisterReceiver(startReceiver);
|
||||
}
|
||||
@@ -483,8 +485,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertEquals(1, receivedIntents.size());
|
||||
Intent broadcastIntent = receivedIntents.get(0);
|
||||
assertEquals(stopAction, broadcastIntent.getAction());
|
||||
assertEquals(123L, broadcastIntent.getLongExtra(
|
||||
context.getString(R.string.track_id_broadcast_extra), -1L));
|
||||
assertEquals(123L,
|
||||
broadcastIntent.getLongExtra(context.getString(R.string.track_id_broadcast_extra), -1L));
|
||||
|
||||
context.unregisterReceiver(stopReceiver);
|
||||
}
|
||||
@@ -494,7 +496,10 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
ITrackRecordingService service = bindAndGetService(createStartIntent());
|
||||
assertFalse(service.isRecording());
|
||||
|
||||
// Ending the current track when there is no recording should not result in any error.
|
||||
/*
|
||||
* Ending the current track when there is no recording should not result in
|
||||
* any error.
|
||||
*/
|
||||
service.endCurrentTrack();
|
||||
|
||||
assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT,
|
||||
@@ -562,8 +567,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
assertEquals(1, service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT));
|
||||
Waypoint wpt = providerUtils.getWaypoint(1);
|
||||
assertEquals(getContext().getString(R.string.marker_waypoint_icon_url),
|
||||
wpt.getIcon());
|
||||
assertEquals(getContext().getString(R.string.marker_waypoint_icon_url), wpt.getIcon());
|
||||
assertEquals(getContext().getString(R.string.marker_name_format, 1), wpt.getName());
|
||||
assertEquals(WaypointType.WAYPOINT, wpt.getType());
|
||||
assertEquals(123L, wpt.getTrackId());
|
||||
@@ -574,8 +578,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_voiceFrequencyDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.voice_frequency_key,
|
||||
PreferencesUtils.VOICE_FREQUENCY_DEFAULT);
|
||||
PreferencesUtils.setInt(
|
||||
context, R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@@ -590,7 +594,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
PreferencesUtils.setInt(context, R.string.voice_frequency_key, 1);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_maxRecordingDistanceDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.max_recording_distance_key,
|
||||
@@ -619,8 +623,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
|
||||
@MediumTest
|
||||
public void testWithProperties_splitFrequencyDefault() throws Exception {
|
||||
PreferencesUtils.setInt(context, R.string.split_frequency_key,
|
||||
PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
|
||||
PreferencesUtils.setInt(
|
||||
context, R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@@ -690,8 +694,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
|
||||
private ITrackRecordingService bindAndGetService(Intent intent) {
|
||||
ITrackRecordingService service = ITrackRecordingService.Stub.asInterface(
|
||||
bindService(intent));
|
||||
ITrackRecordingService service = ITrackRecordingService.Stub.asInterface(bindService(intent));
|
||||
assertNotNull(service);
|
||||
return service;
|
||||
}
|
||||
@@ -722,8 +725,8 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(track.getId() >= 0);
|
||||
providerUtils.insertTrack(track);
|
||||
assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId()
|
||||
: PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key,
|
||||
isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording);
|
||||
}
|
||||
|
||||
@@ -760,7 +763,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
}
|
||||
}
|
||||
|
||||
// Stop the track. Validate if it has correct data.
|
||||
// Stop the track. Validate if it has correct data.
|
||||
service.endCurrentTrack();
|
||||
assertFalse(service.isRecording());
|
||||
assertEquals(-1L, service.getRecordingTrackId());
|
||||
@@ -772,7 +775,7 @@ public class TrackRecordingServiceTest extends ServiceTestCase<TestRecordingServ
|
||||
assertTrue(tripStatistics.getStartTime() > 0);
|
||||
assertTrue(tripStatistics.getStopTime() >= tripStatistics.getStartTime());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inserts a location and waits for 100ms.
|
||||
*
|
||||
|
||||
+32
-29
@@ -2,7 +2,6 @@
|
||||
|
||||
package com.google.android.apps.mytracks.stats;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
|
||||
import android.location.Location;
|
||||
@@ -103,21 +102,22 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
public void testElevationGain() throws Exception {
|
||||
for (double i = 0; i < 1000; i++) {
|
||||
double expectedGain;
|
||||
if (i < Constants.ELEVATION_SMOOTHING_FACTOR - 1) {
|
||||
if (i < TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR - 1) {
|
||||
expectedGain = 0;
|
||||
} else if (i < Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||
} else if (i < TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
expectedGain = 0.5;
|
||||
} else {
|
||||
expectedGain = 1.0;
|
||||
}
|
||||
assertEquals(expectedGain, tripStatisticsUpdater.updateElevation(i));
|
||||
assertEquals(i, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
|
||||
TripStatistics data = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals(0.0, data.getMinElevation());
|
||||
assertEquals(i, data.getMaxElevation(), Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(i, data.getTotalElevationGain(), Constants.ELEVATION_SMOOTHING_FACTOR);
|
||||
assertEquals(i, data.getMaxElevation(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(
|
||||
i, data.getTotalElevationGain(), TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
*/
|
||||
tripStatisticsUpdater.updateElevation(i);
|
||||
tripStatisticsUpdater.updateGrade(100, 100);
|
||||
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
||||
&& i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||
}
|
||||
@@ -145,7 +146,8 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
*/
|
||||
tripStatisticsUpdater.updateElevation(i);
|
||||
tripStatisticsUpdater.updateGrade(100, -100);
|
||||
if (i >= Constants.GRADE_SMOOTHING_FACTOR && i >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||
if (i >= TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR
|
||||
&& i >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
assertEquals(1.0, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(-1.0, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||
}
|
||||
@@ -164,10 +166,10 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
*/
|
||||
tripStatisticsUpdater.updateElevation(i);
|
||||
tripStatisticsUpdater.updateGrade(1, 100);
|
||||
assertEquals(Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics()
|
||||
.getMaxGrade());
|
||||
assertEquals(Double.POSITIVE_INFINITY, tripStatisticsUpdater.getTripStatistics()
|
||||
.getMinGrade());
|
||||
assertEquals(
|
||||
Double.NEGATIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMaxGrade());
|
||||
assertEquals(
|
||||
Double.POSITIVE_INFINITY, tripStatisticsUpdater.getTripStatistics().getMinGrade());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +212,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
double speed = 4.0;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
tripStatisticsUpdater.updateSpeed(i + ONE_SECOND, speed, i, speed);
|
||||
if (i >= Constants.SPEED_SMOOTHING_FACTOR) {
|
||||
if (i >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||
assertEquals(speed, tripStatisticsUpdater.getTripStatistics().getMaxSpeed());
|
||||
}
|
||||
}
|
||||
@@ -231,28 +233,29 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
// Going up by 1 meter each time.
|
||||
// Moving by .001 degree latitude (111 meters).
|
||||
// Each time slice is 10 seconds.
|
||||
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001,
|
||||
MOVING_SPEED, startTime + (timeOffset + i) * TEN_SECONDS);
|
||||
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, MOVING_SPEED,
|
||||
startTime + (timeOffset + i) * TEN_SECONDS);
|
||||
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
|
||||
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||
assertEquals((locationOffset + i) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||
assertEquals(i + locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||
assertEquals(i + locationOffset, tripStatistics.getMaxElevation(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(i + locationOffset, tripStatistics.getTotalElevationGain(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
|
||||
if (i + locationOffset >= Constants.SPEED_SMOOTHING_FACTOR) {
|
||||
if (i + locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
}
|
||||
|
||||
// If there are only moving locations in the track.
|
||||
if (locationOffset == 0 && (i + locationOffset) >= Constants.DISTANCE_SMOOTHING_FACTOR
|
||||
&& (i + locationOffset) >= Constants.ELEVATION_SMOOTHING_FACTOR) {
|
||||
if (locationOffset == 0
|
||||
&& (i + locationOffset) >= TripStatisticsUpdater.DISTANCE_SMOOTHING_FACTOR
|
||||
&& (i + locationOffset) >= TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR) {
|
||||
// 1 m / 111 m = .009
|
||||
assertEquals(0.009, tripStatistics.getMinGrade(), 0.0001);
|
||||
assertEquals(0.009, tripStatistics.getMaxGrade(), 0.0001);
|
||||
@@ -274,26 +277,26 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
private void addWaitLocations(int points, long startTime, TripStatistics tripStatistics,
|
||||
int timeOffset, int locationOffset) {
|
||||
for (int i = 0; i < points; i++) {
|
||||
Location location = getLocation(locationOffset, locationOffset * .001, 0, startTime
|
||||
+ (i + timeOffset) * TEN_SECONDS);
|
||||
Location location = getLocation(
|
||||
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
|
||||
tripStatisticsUpdater.addLocation(location, PreferencesUtils.MIN_RECORDING_DISTANCE_DEFAULT);
|
||||
|
||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||
assertEquals((locationOffset) * TEN_SECONDS, tripStatistics.getMovingTime());
|
||||
assertEquals(locationOffset, tripStatisticsUpdater.getSmoothedElevation(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(0.0, tripStatistics.getMinElevation());
|
||||
assertEquals(locationOffset, tripStatistics.getMaxElevation(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR / 2);
|
||||
assertEquals(locationOffset, tripStatistics.getTotalElevationGain(),
|
||||
Constants.ELEVATION_SMOOTHING_FACTOR);
|
||||
if (locationOffset >= Constants.SPEED_SMOOTHING_FACTOR) {
|
||||
TripStatisticsUpdater.ELEVATION_SMOOTHING_FACTOR);
|
||||
if (locationOffset >= TripStatisticsUpdater.SPEED_SMOOTHING_FACTOR) {
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
}
|
||||
assertEquals(MOVING_SPEED, tripStatistics.getMaxSpeed(), 0.1);
|
||||
assertEquals(locationOffset * 111.0, tripStatistics.getTotalDistance(),
|
||||
locationOffset * 111.0 * 0.01);
|
||||
assertEquals(
|
||||
locationOffset * 111.0, tripStatistics.getTotalDistance(), locationOffset * 111.0 * 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.util;
|
||||
|
||||
import com.google.android.apps.mytracks.Constants;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import java.io.File;
|
||||
@@ -25,7 +23,7 @@ import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests for {@link FileUtils}.
|
||||
*
|
||||
*
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class FileUtilsTest extends TestCase {
|
||||
@@ -35,7 +33,7 @@ public class FileUtilsTest extends TestCase {
|
||||
*/
|
||||
public void testBuildExternalDirectoryPath() {
|
||||
String expectedName = Environment.getExternalStorageDirectory() + File.separator
|
||||
+ Constants.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator
|
||||
+ FileUtils.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator
|
||||
+ "c";
|
||||
String dirName = FileUtils.buildExternalDirectoryPath("a", "b", "c");
|
||||
assertEquals(expectedName, dirName);
|
||||
|
||||
Reference in New Issue
Block a user