[ADD] Static Data Test
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package com.a1.nextlocation.data;
|
||||
|
||||
import org.osmdroid.views.overlay.Polyline;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -11,7 +9,7 @@ public enum StaticData {
|
||||
INSTANCE;
|
||||
private double distanceTraveled = 0;
|
||||
private int locationsVisited = 0;
|
||||
private long timeWalkedRoute = 0;
|
||||
private long timeWalked = 0;
|
||||
|
||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||
|
||||
@@ -19,12 +17,12 @@ public enum StaticData {
|
||||
distanceTraveled += d;
|
||||
}
|
||||
|
||||
public long getTimeWalkedRoute() {
|
||||
return timeWalkedRoute;
|
||||
public long getTimeWalked() {
|
||||
return timeWalked;
|
||||
}
|
||||
|
||||
public void addTimeWalked(long time) {
|
||||
timeWalkedRoute += time;
|
||||
timeWalked += time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,15 +5,12 @@ import android.os.Bundle;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.a1.nextlocation.R;
|
||||
import com.a1.nextlocation.data.Coupon;
|
||||
@@ -46,7 +43,7 @@ public class StatisticFragment extends Fragment {
|
||||
distance.setText("" + String.format("%.1f",dist) + " km");
|
||||
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
|
||||
|
||||
long seconds = StaticData.INSTANCE.getTimeWalkedRoute() / 1000;
|
||||
long seconds = StaticData.INSTANCE.getTimeWalked() / 1000;
|
||||
long p1 = seconds % 60;
|
||||
long p2 = seconds / 60;
|
||||
long p3 = p2 % 60;
|
||||
|
||||
@@ -68,8 +68,8 @@ public class LocationTest {
|
||||
@Test
|
||||
public void coordinateDoublesTest(){
|
||||
double[] testDoubles = new double[2];
|
||||
testDoubles[0] = 15.4;
|
||||
testDoubles[1] = 27.5;
|
||||
testDoubles[0] = 27.5;
|
||||
testDoubles[1] = 15.4;
|
||||
|
||||
double [] expectedCoordAsDouble = testDoubles;
|
||||
String expectedStringFromDouble = "15.4,27.5";
|
||||
|
||||
49
app/src/test/java/com/a1/nextlocation/StaticDataTest.java
Normal file
49
app/src/test/java/com/a1/nextlocation/StaticDataTest.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.a1.nextlocation;
|
||||
|
||||
import com.a1.nextlocation.data.Location;
|
||||
import com.a1.nextlocation.data.StaticData;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
|
||||
public class StaticDataTest {
|
||||
private StaticData staticData;
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
staticData = StaticData.INSTANCE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDistance(){
|
||||
staticData.addDistance(2356.234);
|
||||
double expected = 2356.234;
|
||||
assertEquals(expected, staticData.getDistanceTraveled(), 0.01);
|
||||
staticData.addDistance(234342.1);
|
||||
assertNotEquals(expected, staticData.getDistanceTraveled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeWalked(){
|
||||
staticData.addTimeWalked(3456);
|
||||
long expected = 3456;
|
||||
assertEquals(expected, staticData.getTimeWalked());
|
||||
staticData.addTimeWalked(3445);
|
||||
assertNotEquals(expected, staticData.getTimeWalked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
Location testLocation = new Location("test", "test", "test", "test");
|
||||
staticData.visitLocation(testLocation);
|
||||
int expected = 1;
|
||||
assertEquals(expected, staticData.getLocationsVisited());
|
||||
staticData.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
|
||||
assertNotEquals(expected, staticData.getLocationsVisited());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user