-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move some tests to commonTest use kotlin-test annotations everywhere instead of junit get rid of test task override (breaks jvm build :-) ) rename remaining jvm tests to have Jvm in their file name (avoid clash with commonTest)
- Loading branch information
1 parent
442e611
commit c475f29
Showing
7 changed files
with
134 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version=0.0.1-SNAPSHOT | ||
group=com.github.jillesvangurp |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import com.jillesvangurp.geo.GeoHashUtils | ||
import com.jillesvangurp.geo.latitude | ||
import com.jillesvangurp.geo.longitude | ||
import io.kotest.data.blocking.forAll | ||
import io.kotest.data.row | ||
import io.kotest.matchers.shouldBe | ||
import kotlin.test.Test | ||
|
||
class GeoHashUtilsTest { | ||
val coordinatesWithHashes = arrayOf( | ||
row(0.1, -0.1, "ebpbtdpntc6e"), | ||
row(52.530888, 13.394904, "u33dbfcyegk2") | ||
) | ||
|
||
fun lines() = arrayOf( | ||
arrayOf(1, 1, 2, 2), | ||
arrayOf(2, 2, 1, 1), | ||
arrayOf(2, 1, 1, 1), | ||
arrayOf(1, 2, 1, 1), | ||
arrayOf(1, 1, 2, 1), | ||
arrayOf(1, 1, 1, 2), | ||
arrayOf(1, 1, 1, 2) | ||
) | ||
|
||
// @Test | ||
// fun shouldBreak() { | ||
// 42 shouldBe 40 | ||
// } | ||
|
||
@Test | ||
fun shouldDecodeHashes() { | ||
forAll(*coordinatesWithHashes) { lat: Double, lon: Double, geoHash: String -> | ||
val decoded = GeoHashUtils.decode(geoHash) | ||
decoded.latitude shouldBeApproximately lat | ||
decoded.longitude shouldBeApproximately lon | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldEncodeHashes() { | ||
forAll(*coordinatesWithHashes) { lat: Double, lon: Double, geoHash: String -> | ||
GeoHashUtils.encode(lat, lon) shouldBe geoHash | ||
GeoHashUtils.encode(doubleArrayOf(lon, lat)) shouldBe geoHash | ||
} | ||
} | ||
|
||
@Test | ||
fun shouldContainCoordinateInBbox() { | ||
forAll(*coordinatesWithHashes) { lat: Double, lon: Double, geoHash: String -> | ||
GeoHashUtils.contains(geoHash, lat, lon) shouldBe true | ||
GeoHashUtils.contains(geoHash, lon, lat) shouldBe false | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import io.kotest.matchers.doubles.shouldBeLessThan | ||
import kotlin.math.abs | ||
|
||
fun Double.shouldBeApproximately(other: Double, marginOfError: Double = 0.0000001) { | ||
// allow for tiny rounding errors | ||
abs(this - other) shouldBeLessThan marginOfError | ||
} | ||
|
||
infix fun Double.shouldBeApproximately(other: Double) { | ||
this.shouldBeApproximately(other, 0.0000001) | ||
} |
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