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

Clean up and simplify tests #560

Merged
merged 1 commit into from Oct 7, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
277 changes: 144 additions & 133 deletions library/tests/src/com/google/maps/android/PolyUtilTest.java

Large diffs are not rendered by default.

276 changes: 133 additions & 143 deletions library/tests/src/com/google/maps/android/SphericalUtilTest.java

Large diffs are not rendered by default.

Expand Up @@ -20,14 +20,34 @@
import com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm;

import org.junit.Test;
import org.junit.Assert;

import static org.junit.Assert.*;

public class QuadItemTest {
@Test
public void testRemoval() {
TestingItem item_1_5 = new TestingItem(0.1, 0.5);
TestingItem item_2_3 = new TestingItem(0.2, 0.3);

NonHierarchicalDistanceBasedAlgorithm<ClusterItem> algo =
new NonHierarchicalDistanceBasedAlgorithm<>();
algo.addItem(item_1_5);
algo.addItem(item_2_3);

assertEquals(2, algo.getItems().size());

algo.removeItem(item_1_5);

assertEquals(1, algo.getItems().size());

assertFalse(algo.getItems().contains(item_1_5));
assertTrue(algo.getItems().contains(item_2_3));
}

public class TestingItem implements ClusterItem {
private final LatLng mPosition;

public TestingItem(double lat, double lng) {
TestingItem(double lat, double lng) {
mPosition = new LatLng(lat, lng);
}

Expand All @@ -46,28 +66,4 @@ public String getSnippet() {
return null;
}
}

public void setUp() {
// nothing to setup
}

@Test
public void testRemoval() {
TestingItem item_1_5 = new TestingItem(0.1, 0.5);
TestingItem item_2_3 = new TestingItem(0.2, 0.3);

NonHierarchicalDistanceBasedAlgorithm<ClusterItem> algo
= new NonHierarchicalDistanceBasedAlgorithm<ClusterItem>();
algo.addItem(item_1_5);
algo.addItem(item_2_3);

Assert.assertEquals(2, algo.getItems().size());

algo.removeItem(item_1_5);

Assert.assertEquals(1, algo.getItems().size());

Assert.assertFalse(algo.getItems().contains(item_1_5));
Assert.assertTrue(algo.getItems().contains(item_2_3));
}
}
Expand Up @@ -19,35 +19,27 @@
import com.google.android.gms.maps.model.LatLng;
import com.google.maps.android.clustering.algo.StaticCluster;

import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;

public class StaticClusterTest {

private StaticCluster<ClusterItem> mCluster;

@Before
public void setUp() {
mCluster = new StaticCluster<ClusterItem>(new LatLng(0.1, 0.5));
}
import static org.junit.Assert.*;

public class StaticClusterTest {
@Test
public void testEquality() {
StaticCluster<ClusterItem> cluster_1_5 = new StaticCluster<ClusterItem>(
new LatLng(0.1, 0.5));
StaticCluster<ClusterItem> cluster1 = new StaticCluster<>(new LatLng(0.1, 0.5));
StaticCluster<ClusterItem> cluster2 = new StaticCluster<>(new LatLng(0.1, 0.5));

Assert.assertEquals(cluster_1_5, mCluster);
Assert.assertNotSame(cluster_1_5, mCluster);
Assert.assertEquals(cluster_1_5.hashCode(), mCluster.hashCode());
assertEquals(cluster1, cluster2);
assertNotSame(cluster1, cluster2);
assertEquals(cluster1.hashCode(), cluster2.hashCode());
}

@Test
public void testUnequality() {
StaticCluster<ClusterItem> cluster_2_3 = new StaticCluster<ClusterItem>(
new LatLng(0.2, 0.3));
StaticCluster<ClusterItem> cluster1 = new StaticCluster<>(new LatLng(0.1, 0.5));
StaticCluster<ClusterItem> cluster2 = new StaticCluster<>(new LatLng(0.2, 0.3));

Assert.assertNotEquals(mCluster, cluster_2_3);
Assert.assertNotEquals(cluster_2_3.hashCode(), mCluster.hashCode());
assertNotEquals(cluster1, cluster2);
assertNotEquals(cluster1.hashCode(), cluster2.hashCode());
}
}
62 changes: 31 additions & 31 deletions library/tests/src/com/google/maps/android/data/FeatureTest.java
Expand Up @@ -3,61 +3,61 @@
import com.google.android.gms.maps.model.LatLng;

import org.junit.Test;
import org.junit.Assert;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class FeatureTest {
Feature feature;
import static org.junit.Assert.*;

public class FeatureTest {
@Test
public void testGetId() throws Exception {
feature = new Feature(null, "Pirate", null);
Assert.assertNotNull(feature.getId());
Assert.assertEquals("Pirate", feature.getId());
public void testGetId() {
Feature feature = new Feature(null, "Pirate", null);
assertNotNull(feature.getId());
assertEquals("Pirate", feature.getId());
feature = new Feature(null, null, null);
Assert.assertNull(feature.getId());
assertNull(feature.getId());
}

@Test
public void testProperty() throws Exception {
HashMap<String, String> properties = new HashMap<>();
public void testProperty() {
Map<String, String> properties = new HashMap<>();
properties.put("Color", "Red");
properties.put("Width", "3");
feature = new Feature(null, null, properties);
Assert.assertFalse(feature.hasProperty("llama"));
Assert.assertTrue(feature.hasProperty("Color"));
Assert.assertEquals("Red", feature.getProperty("Color"));
Assert.assertTrue(feature.hasProperty("Width"));
Assert.assertEquals("3", feature.getProperty("Width"));
Assert.assertNull(feature.removeProperty("banana"));
Assert.assertEquals("3", feature.removeProperty("Width"));
Assert.assertNull(feature.setProperty("Width", "10"));
Assert.assertEquals("10", feature.setProperty("Width", "500"));
Feature feature = new Feature(null, null, properties);
assertFalse(feature.hasProperty("llama"));
assertTrue(feature.hasProperty("Color"));
assertEquals("Red", feature.getProperty("Color"));
assertTrue(feature.hasProperty("Width"));
assertEquals("3", feature.getProperty("Width"));
assertNull(feature.removeProperty("banana"));
assertEquals("3", feature.removeProperty("Width"));
assertNull(feature.setProperty("Width", "10"));
assertEquals("10", feature.setProperty("Width", "500"));
}

@Test
public void testGeometry() {
feature = new Feature(null, null, null);
Assert.assertNull(feature.getGeometry());
Feature feature = new Feature(null, null, null);
assertNull(feature.getGeometry());
Point point = new Point(new LatLng(0, 0));
feature.setGeometry(point);
Assert.assertEquals(point, feature.getGeometry());
assertEquals(point, feature.getGeometry());
feature.setGeometry(null);
Assert.assertNull(feature.getGeometry());
assertNull(feature.getGeometry());

LineString lineString = new LineString(new ArrayList<>(Arrays.asList(new LatLng(0, 0), new LatLng(50, 50))));
LineString lineString =
new LineString(
new ArrayList<>(Arrays.asList(new LatLng(0, 0), new LatLng(50, 50))));
feature = new Feature(lineString, null, null);
Assert.assertEquals(lineString, feature.getGeometry());
assertEquals(lineString, feature.getGeometry());
feature.setGeometry(point);
Assert.assertEquals(point, feature.getGeometry());
assertEquals(point, feature.getGeometry());
feature.setGeometry(null);
Assert.assertNull(feature.getGeometry());
assertNull(feature.getGeometry());
feature.setGeometry(lineString);
Assert.assertEquals(lineString, feature.getGeometry());
assertEquals(lineString, feature.getGeometry());
}


}
66 changes: 32 additions & 34 deletions library/tests/src/com/google/maps/android/data/LineStringTest.java
Expand Up @@ -3,15 +3,15 @@
import com.google.android.gms.maps.model.LatLng;

import org.junit.Test;
import org.junit.Assert;

import java.util.ArrayList;
import java.util.List;

public class LineStringTest {
LineString lineString;
import static org.junit.Assert.*;

public LineString createSimpleLineString() {
ArrayList<LatLng> coordinates = new ArrayList<LatLng>();
public class LineStringTest {
private LineString createSimpleLineString() {
List<LatLng> coordinates = new ArrayList<>();
coordinates.add(new LatLng(95, 60));
coordinates.add(new LatLng(93, 57));
coordinates.add(new LatLng(95, 55));
Expand All @@ -21,8 +21,8 @@ public LineString createSimpleLineString() {
return new LineString(coordinates);
}

public LineString createLoopedLineString() {
ArrayList<LatLng> coordinates = new ArrayList<LatLng>();
private LineString createLoopedLineString() {
List<LatLng> coordinates = new ArrayList<>();
coordinates.add(new LatLng(92, 66));
coordinates.add(new LatLng(89, 64));
coordinates.add(new LatLng(94, 62));
Expand All @@ -31,37 +31,35 @@ public LineString createLoopedLineString() {
}

@Test
public void testGetType() throws Exception {
lineString = createSimpleLineString();
Assert.assertNotNull(lineString);
Assert.assertNotNull(lineString.getGeometryType());
Assert.assertEquals("LineString", lineString.getGeometryType());
public void testGetType() {
LineString lineString = createSimpleLineString();
assertNotNull(lineString);
assertNotNull(lineString.getGeometryType());
assertEquals("LineString", lineString.getGeometryType());
lineString = createLoopedLineString();
Assert.assertNotNull(lineString);
Assert.assertNotNull(lineString.getGeometryType());
Assert.assertEquals("LineString", lineString.getGeometryType());
assertNotNull(lineString);
assertNotNull(lineString.getGeometryType());
assertEquals("LineString", lineString.getGeometryType());
}

@Test
public void testGetGeometryObject() throws Exception {
lineString = createSimpleLineString();
Assert.assertNotNull(lineString);
Assert.assertNotNull(lineString.getGeometryObject());
Assert.assertEquals(lineString.getGeometryObject().size(), 6);
Assert.assertEquals(lineString.getGeometryObject().get(0).latitude, 90.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(1).latitude, 90.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(2).latitude, 90.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(3).longitude, 53.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(4).longitude, 54.0, 0);
public void testGetGeometryObject() {
LineString lineString = createSimpleLineString();
assertNotNull(lineString);
assertNotNull(lineString.getGeometryObject());
assertEquals(lineString.getGeometryObject().size(), 6);
assertEquals(lineString.getGeometryObject().get(0).latitude, 90.0, 0);
assertEquals(lineString.getGeometryObject().get(1).latitude, 90.0, 0);
assertEquals(lineString.getGeometryObject().get(2).latitude, 90.0, 0);
assertEquals(lineString.getGeometryObject().get(3).longitude, 53.0, 0);
assertEquals(lineString.getGeometryObject().get(4).longitude, 54.0, 0);
lineString = createLoopedLineString();
Assert.assertNotNull(lineString);
Assert.assertNotNull(lineString.getGeometryObject());
Assert.assertEquals(lineString.getGeometryObject().size(), 4);
Assert.assertEquals(lineString.getGeometryObject().get(0).latitude, 90.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(1).latitude, 89.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(2).longitude, 62.0, 0);
Assert.assertEquals(lineString.getGeometryObject().get(3).longitude, 66.0, 0);

assertNotNull(lineString);
assertNotNull(lineString.getGeometryObject());
assertEquals(lineString.getGeometryObject().size(), 4);
assertEquals(lineString.getGeometryObject().get(0).latitude, 90.0, 0);
assertEquals(lineString.getGeometryObject().get(1).latitude, 89.0, 0);
assertEquals(lineString.getGeometryObject().get(2).longitude, 62.0, 0);
assertEquals(lineString.getGeometryObject().get(3).longitude, 66.0, 0);
}

}