-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base animation duration on actual distance estimation
- Loading branch information
Showing
5 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 23 additions & 2 deletions
25
android/lib/model/src/test/kotlin/net/mullvad/mullvadvpn/model/LatLongTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,41 @@ | ||
package net.mullvad.mullvadvpn.model | ||
|
||
import kotlin.math.sqrt | ||
import kotlin.test.assertTrue | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Test | ||
|
||
class LatLongTest { | ||
|
||
@Test | ||
fun `distance between two LatLong should be same as hypotenuse`() { | ||
fun `degree distance between two LatLong should be same as hypotenuse`() { | ||
val latLong1 = LatLong(Latitude(30f), Longitude(40f)) | ||
val latLong2 = LatLong(Latitude(-40f), Longitude(170f)) | ||
|
||
val latDiff = latLong1.latitude.distanceTo(latLong2.latitude) | ||
val longDiff = latLong1.longitude.distanceTo(latLong2.longitude) | ||
val hypotenuse = sqrt(latDiff * latDiff + longDiff * longDiff) | ||
|
||
assertEquals(hypotenuse, latLong1.distanceTo(latLong2)) | ||
assertEquals(hypotenuse, latLong1.degreeDistanceTo(latLong2)) | ||
} | ||
|
||
@Test | ||
fun `ensure seppDistance respects lateral value is respected`() { | ||
// Malmö & New York is a shorter distance than Malmö & Johannesburg, but the degree | ||
// difference is larger since they are at a higher latitude. | ||
|
||
// Malmo 55.6050° N, 13.0038° E | ||
val malmo = LatLong(Latitude(55.6050f), Longitude(13.0038f)) | ||
|
||
// New York 40.7128° N, 74.0060° W | ||
val newYork = LatLong(Latitude(40.7128f), Longitude(-74.0060f)) | ||
|
||
// Johannesburg 26.2041° S, 28.0473° E | ||
val johannesburg = LatLong(Latitude(-26.2041f), Longitude(28.0473f)) | ||
|
||
val malmoeToNewYork = malmo.seppDistanceTo(newYork) | ||
val malmoeToJohannesburg = malmo.seppDistanceTo(johannesburg) | ||
|
||
assertTrue(malmoeToNewYork < malmoeToJohannesburg) | ||
} | ||
} |