mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Change the code style of SingleColorTrackPathPainterTest and DynamicSpeedTrackPathPainterTest.
This commit is contained in:
@@ -51,9 +51,9 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
@Override
|
||||
public void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points) {
|
||||
Path newPath = new Path();
|
||||
newPath.incReserve(points.size());
|
||||
path = updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, newPath);
|
||||
path = new Path();
|
||||
path.incReserve(points.size());
|
||||
updatePath(projection, viewRect, startLocationIdx, alwaysVisible, points, path);
|
||||
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
* @param newPath The path to be created.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
Path updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
void updatePath(Projection projection, Rect viewRect, int startLocationIdx,
|
||||
Boolean alwaysVisible, List<CachedLocation> points, Path newPath) {
|
||||
// Whether to start a new segment on new valid and visible point.
|
||||
boolean newSegment = startLocationIdx <= 0 || !points.get(startLocationIdx - 1).valid;
|
||||
@@ -103,7 +103,6 @@ public class SingleColorTrackPathPainter implements TrackPathPainter {
|
||||
newPath.lineTo(pt.x, pt.y);
|
||||
}
|
||||
}
|
||||
return newPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-8
@@ -34,13 +34,12 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
|
||||
private DynamicSpeedTrackPathPainter dynamicSpeedTrackPathPainter;
|
||||
private TrackPathDescriptor trackPathDescriptor;
|
||||
// This number must bigger than 10 to meets the requirement of test.
|
||||
// This number must bigger than 10 to meet the requirement of test.
|
||||
private static final int NUMBER_OF_LOCATIONS = 100;
|
||||
private static final int NUMBER_OF_SEGMENTS = 4;
|
||||
private static final int LOCATIONS_PER_SEGMENT = 25;
|
||||
// The maximum speed which is considered slow.
|
||||
// The maximum speed(KM/H) which is considered slow.
|
||||
private static final int SLOW_SPEED = 30;
|
||||
// The maximum speed which is considered normal.
|
||||
// The maximum speed(KM/H) which is considered normal.
|
||||
private static final int NORMAL_SPEED = 50;
|
||||
|
||||
@Override
|
||||
@@ -94,18 +93,21 @@ public class DynamicSpeedTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
*/
|
||||
public void testUpdatePath_CheckColoredPath() {
|
||||
// Gets the slow speed. Divide SLOW_SPEED by 2 to make it smaller than
|
||||
// SLOW_SPEED.
|
||||
// SLOW_SPEED. Speed in MyTracksLocation use MS, but speed in CachedLocation
|
||||
// use KMH.
|
||||
int slowSpeed = (int) (SLOW_SPEED / (2 * UnitConversions.MS_TO_KMH));
|
||||
// Gets the normal speed. Makes it smaller than SLOW_SPEED and bigger than
|
||||
// NORMAL_SPEED.
|
||||
// NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in
|
||||
// CachedLocation use KMH.
|
||||
int normalSpeed = (int) ((SLOW_SPEED + NORMAL_SPEED) / (2 * UnitConversions.MS_TO_KMH));
|
||||
// Gets the fast speed. Multiply it by 2 to make it bigger than
|
||||
// NORMAL_SPEED.
|
||||
// NORMAL_SPEED. Speed in MyTracksLocation use MS, but speed in
|
||||
// CachedLocation use KMH.
|
||||
int fastSpeed = (int) (NORMAL_SPEED * 2 / UnitConversions.MS_TO_KMH);
|
||||
|
||||
// Get a number of startLocationIdx. And divide NUMBER_OF_LOCATIONS by 8 to
|
||||
// make sure it is less than numberOfFirstThreeSegments.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / NUMBER_OF_SEGMENTS / 2;
|
||||
int startLocationIdx = LOCATIONS_PER_SEGMENT / 2;
|
||||
|
||||
List<CachedLocation> points = createCachedLocations(LOCATIONS_PER_SEGMENT,
|
||||
TrackStubUtils.INITIAL_LATITUDE, slowSpeed);
|
||||
|
||||
+3
-3
@@ -59,7 +59,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
// Gets a number as the start index of points.
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) {
|
||||
for (int i = startLocationIdx; i < NUMBER_OF_LOCATIONS; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
public void testUpdatePath_AllInvalidLocation() {
|
||||
List<CachedLocation> points = createCachedLocations(NUMBER_OF_LOCATIONS, INVALID_LATITUDE, -1);
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = (int) (1 + (NUMBER_OF_LOCATIONS - 1) * Math.random());
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
AndroidMock.replay(pathMock);
|
||||
singleColorTrackPathPainter.updatePath(myTracksOverlay.getMapProjection(mockView),
|
||||
myTracksOverlay.getMapViewRect(mockView), startLocationIdx, true, points, pathMock);
|
||||
@@ -100,7 +100,7 @@ public class SingleColorTrackPathPainterTest extends TrackPathPainterTestCase {
|
||||
// Third segment.
|
||||
points.addAll(createCachedLocations(NUMBER_OF_LOCATIONS, TrackStubUtils.INITIAL_LATITUDE, -1));
|
||||
// Gets a random number from 1 to numberOfLocations.
|
||||
int startLocationIdx = (int) (1 + (NUMBER_OF_LOCATIONS - 1) * Math.random());
|
||||
int startLocationIdx = NUMBER_OF_LOCATIONS / 2;
|
||||
for (int i = 0; i < NUMBER_OF_LOCATIONS - startLocationIdx; i++) {
|
||||
pathMock.lineTo(0, 0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class TrackPathPainterTestCase extends AndroidTestCase {
|
||||
*
|
||||
* @param number the number of locations
|
||||
* @param latitude the latitude value of locations.
|
||||
* @param speed the speed of locations, and will give a default valid value if
|
||||
* @param speed the speed(meter per second) of locations, and will give a default valid value if
|
||||
* less than zero
|
||||
* @return the simulated locations
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user