Skip to content

Commit

Permalink
Fix FakeMapFragment poly behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Feb 24, 2023
1 parent c91d1f3 commit 2c28d97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void recordingPointManually_whenPointIsADuplicateOfTheLastPoint_skipsPoin
mapFragment.setLocation(new MapPoint(1, 1));
onView(withId(R.id.record_button)).perform(click());
onView(withId(R.id.record_button)).perform(click());
assertThat(mapFragment.getPolyPoints(0).size(), equalTo(1));
assertThat(mapFragment.getPolys().get(0).size(), equalTo(1));
}

@Test
Expand All @@ -243,7 +243,7 @@ public void placingPoint_whenPointIsADuplicateOfTheLastPoint_skipsPoint() {

mapFragment.click(new MapPoint(1, 1));
mapFragment.click(new MapPoint(1, 1));
assertThat(mapFragment.getPolyPoints(0).size(), equalTo(1));
assertThat(mapFragment.getPolys().get(0).size(), equalTo(1));
}

private void startInput(int mode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class FakeMapFragment : Fragment(), MapFragment {
private val polyClosed: MutableList<Boolean> = ArrayList()
private val polyDraggable: MutableList<Boolean> = ArrayList()
private var hasCenter = false
private val polyPoints = mutableMapOf<Int, MutableList<MapPoint>>()
private val featureIds = mutableListOf<Int>()

override fun init(
Expand Down Expand Up @@ -123,15 +122,17 @@ class FakeMapFragment : Fragment(), MapFragment {
}

override fun appendPointToPoly(featureId: Int, point: MapPoint) {
polyPoints.getOrPut(featureId) { mutableListOf() }.add(point)
val poly = polys[featureId]!!
polys[featureId] = poly + point
}

override fun removePolyLastPoint(featureId: Int) {
polyPoints.getOrPut(featureId) { mutableListOf() }.removeLast()
val poly = polys[featureId]!!
polys[featureId] = poly.dropLast(1)
}

override fun getPolyPoints(featureId: Int): List<MapPoint> {
return polyPoints.getOrPut(featureId) { mutableListOf() }
return polys[featureId]!!
}

override fun clearFeatures() {
Expand Down

0 comments on commit 2c28d97

Please sign in to comment.