Skip to content
This repository has been archived by the owner on Jun 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #274 from Ph0tonic/refactor/mapTests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0tonic authored Jun 5, 2020
2 parents 6fc56db + cffcb61 commit 03acef2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 42 deletions.
36 changes: 3 additions & 33 deletions app/src/androidTest/java/ch/epfl/sdp/ui/maps/MapActivityTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,20 @@ class MapActivityTest {

mUiDevice.wait(Until.hasObject(By.desc(applicationContext().getString(R.string.map_ready))), MAP_LOADING_TIMEOUT)
assertThat(mActivityRule.activity.mapView.contentDescription == applicationContext().getString(R.string.map_ready), equalTo(true))

runOnUiThread {
val searchArea = QuadrilateralArea(arrayListOf(
LatLng(47.397026, 8.543067), //we consider the closest point to the drone
LatLng(47.398979, 8.543434),
LatLng(47.398279, 8.543934),
LatLng(47.397426, 8.544867)
))
mActivityRule.activity.missionBuilder
val mission = mActivityRule.activity.missionBuilder
.withSearchArea(searchArea)
.withStartingLocation(LatLng(47.397026, 8.543067))
.withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE))
.withStrategy(SimpleQuadStrategy(Drone.GROUND_SENSOR_SCOPE)).build()
mActivityRule.activity.launchMission(mission)
}

// Then start mission officially
runOnUiThread {
mActivityRule.activity.launchMission()
}

val uploadedMission = Drone.missionLiveData.value
assertThat(uploadedMission, `is`(notNullValue()))
Expand Down Expand Up @@ -240,32 +236,6 @@ class MapActivityTest {
HeatmapRepository.daoProvider = { OfflineHeatmapDao() }
}

@Test
fun canUpdateUserLocation() {
//TODO Rewrite this test
CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST)
}

@Test
fun canUpdateUserLocationTwice() {
//TODO Rewrite this test
CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST)
CentralLocationManager.currentUserPosition.postValue(FAKE_LOCATION_TEST)
}

@Test
fun canOnRequestPermissionResult() {
//TODO Rewrite this test
runOnUiThread {
MainDataManager.goOffline()
MainDataManager.groupId.value = DUMMY_GROUP_ID
MainDataManager.role.value = Role.OPERATOR
}
mActivityRule.launchActivity(Intent())

mActivityRule.activity.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0))
}

@Test
fun droneStatusIsVisibleForOperator() {
runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


//TODO extract toast tests (now commented)
@RunWith(AndroidJUnit4::class)
class OfflineManagerActivityTest {
private lateinit var mUiDevice: UiDevice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ch.epfl.sdp.database.repository.HeatmapRepository
import ch.epfl.sdp.database.repository.MarkerRepository
import ch.epfl.sdp.drone.DroneInstanceMock
import ch.epfl.sdp.ui.maps.MapActivity
import ch.epfl.sdp.ui.maps.MapActivityTest
import com.mapbox.mapboxsdk.geometry.LatLng
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
Expand Down Expand Up @@ -102,4 +104,5 @@ class LocationWithPermissionTest {
CentralLocationManager.onRequestPermissionsResult(1011, Array(0) { "" }, IntArray(0))
Mockito.verify(manager, Mockito.times(2)).requestLocationUpdates(Mockito.eq(LocationManager.GPS_PROVIDER), Mockito.eq(REFRESH_RATE), Mockito.eq(MIN_DIST), Mockito.any<LocationListener>())
}

}
10 changes: 5 additions & 5 deletions app/src/main/java/ch/epfl/sdp/ui/maps/MapActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo
super.initMapView(savedInstanceState, R.layout.activity_map, R.id.mapView)
mapView.getMapAsync(this)

//TODO: Give user location if current drone position is not available
CentralLocationManager.configure(this)
mapView.contentDescription = getString(R.string.map_not_ready)

Expand Down Expand Up @@ -302,10 +301,11 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo
fun startOrPauseMissionButton(v: View) {
if (Drone.isFlyingLiveData.value!!) {
if (Drone.isMissionPausedLiveData.value!!) Drone.resumeMission() else Drone.pauseMission()
} else if (!searchAreaBuilder.isComplete()) { //TODO add missionBuilder isComplete method
} else if (!searchAreaBuilder.isComplete()) {
Toast.makeText(this, getString(R.string.not_enough_waypoints_message), Toast.LENGTH_SHORT).show()
} else {
launchMission()
val mission = missionBuilder.build()
launchMission(mission)
}
}

Expand All @@ -314,10 +314,10 @@ class MapActivity : MapViewBaseActivity(), OnMapReadyCallback, MapboxMap.OnMapLo
}

@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
fun launchMission() {
fun launchMission(mission: List<LatLng>) {
val altitude = PreferenceManager.getDefaultSharedPreferences(this)
.getString(this.getString(R.string.pref_key_drone_altitude), Drone.DEFAULT_ALTITUDE.toString()).toString().toFloat()
Drone.startMission(DroneUtils.makeDroneMission(missionBuilder.build(), altitude), groupId.value!!)
Drone.startMission(DroneUtils.makeDroneMission(mission, altitude), groupId.value!!)
searchAreaBuilder.reset()
}

Expand Down
20 changes: 18 additions & 2 deletions app/src/test/java/ch/epfl/sdp/mission/SimpleQuadStrategyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package ch.epfl.sdp.mission

import ch.epfl.sdp.searcharea.QuadrilateralArea
import com.mapbox.mapboxsdk.geometry.LatLng
import net.mastrgamr.mbmapboxutils.SphericalUtil.computeOffset
import org.hamcrest.CoreMatchers.equalTo
import net.mastrgamr.mbmapboxutils.SphericalUtil.*
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import java.lang.Double.max
Expand Down Expand Up @@ -76,5 +76,21 @@ class SimpleQuadStrategyTest {
assertThat("Wanted $theoryRes, but got: $res", diff < 0.01)
}

//TODO test that starting location is taken into account.
@Test
fun missionStartsWithClosestPoint() {
val waypoints = arrayListOf(
LatLng(47.397026, 8.543067), //we consider the closest point to the drone
LatLng(47.398979, 8.543434),
LatLng(47.398279, 8.543934),
LatLng(47.397426, 8.544867)
)

val searchArea = QuadrilateralArea(waypoints
)
val dronePos = LatLng(47.4, 8.6)
val strategy = SimpleQuadStrategy(20.0)
val path = strategy.createFlightPath(dronePos, searchArea)
val orderedSearchArea = waypoints.sortedBy { it.distanceTo(dronePos) }
assertThat(path[0], equalTo(orderedSearchArea[0]))
}
}

0 comments on commit 03acef2

Please sign in to comment.