mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Add test case of the getColor method of MultiColorTrackPath when use dynamic speed track path descriptor.
This commit is contained in:
@@ -20,6 +20,7 @@ import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.Polyline;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -102,7 +103,8 @@ public class MultiColorTrackPath implements TrackPath {
|
||||
TrackPathUtils.addPath(googleMap, paths, lastSegmentPoints, lastSegmentColor, useLastPolyline);
|
||||
}
|
||||
|
||||
private int getColor(int speed) {
|
||||
@VisibleForTesting
|
||||
protected int getColor(int speed) {
|
||||
if (speed <= trackPathDescriptor.getSlowSpeed()) {
|
||||
return slowColor;
|
||||
} else if (speed <= trackPathDescriptor.getNormalSpeed()) {
|
||||
@@ -111,4 +113,16 @@ public class MultiColorTrackPath implements TrackPath {
|
||||
return fastColor;
|
||||
}
|
||||
}
|
||||
|
||||
public int getSlowColor() {
|
||||
return slowColor;
|
||||
}
|
||||
|
||||
public int getNormalColor() {
|
||||
return normalColor;
|
||||
}
|
||||
|
||||
public int getFastColor() {
|
||||
return fastColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package com.google.android.apps.mytracks.maps;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
|
||||
/**
|
||||
* Tests for the {@link MultiColorTrackPath}.
|
||||
*
|
||||
* @author Youtao Liu
|
||||
*/
|
||||
public class MultiColorTrackPathTest extends AndroidTestCase {
|
||||
|
||||
MultiColorTrackPath multiColorTrackPath;
|
||||
Context context;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
context = getContext();
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the {@link MultiColorTrackPath#getColor(int)} when use dynamic speed track path descriptor.
|
||||
*/
|
||||
public void testGetColor_DynamicSpeedTrackPathDescriptor() {
|
||||
DynamicSpeedTrackPathDescriptor dynamicSpeedTrackPathDescriptor = new DynamicSpeedTrackPathDescriptor(
|
||||
context);
|
||||
dynamicSpeedTrackPathDescriptor.setAverageMovingSpeed(50);
|
||||
dynamicSpeedTrackPathDescriptor.setSpeedMargin(10);
|
||||
multiColorTrackPath = new MultiColorTrackPath(context, dynamicSpeedTrackPathDescriptor);
|
||||
|
||||
assertEquals(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getColor(5));
|
||||
assertEquals(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getColor(44));
|
||||
assertEquals(multiColorTrackPath.getNormalColor(), multiColorTrackPath.getColor(50));
|
||||
assertEquals(multiColorTrackPath.getNormalColor(), multiColorTrackPath.getColor(54));
|
||||
assertEquals(multiColorTrackPath.getFastColor(), multiColorTrackPath.getColor(56));
|
||||
assertEquals(multiColorTrackPath.getFastColor(), multiColorTrackPath.getColor(100));
|
||||
|
||||
assertNotSame(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getNormalColor());
|
||||
assertNotSame(multiColorTrackPath.getSlowColor(), multiColorTrackPath.getFastColor());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user