Skip to content

Commit 37a2437

Browse files
author
Josh Devins
committed
Adding tests
1 parent 7beded8 commit 37a2437

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/main/scala/net/joshdevins/gis/geocoder/ReverseGeocoder.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ReverseGeocoder(private val dataDirecotory: String) extends Logging {
2020
new ShapefileIndex("admin-1", "data/build/naturalearth-admin-1/10m_admin_1_states_provinces_shp.shp"),
2121
new ShapefileIndex("admin-0", "data/build/naturalearth-admin-0/10m_admin_0_countries.shp"))
2222

23-
def mkString: String = indices.iterator.mkString
23+
def mkString: String = indices.mkString(", ")
2424

2525
/**
2626
* Gets the lowest-level WOEIDs for the shapes that contain the lat/lon provided. A subsequent lookup of the WOEID's will find the point

src/main/scala/net/joshdevins/gis/geocoder/ShapefileIndex.scala

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class ShapefileIndex(val name: String, private val shapefile: String) extends Lo
5959
log.info("Index built in: %.2f seconds\n", duration / 1000F)
6060
}
6161

62+
override def toString: String = name
63+
6264
/**
6365
* Gets the WOEIDs for the shapes that contain the lat/lon provided.
6466
*/

src/test/scala/net/joshdevins/gis/geocoder/ReverseGeocoderTestSuite.scala

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,26 @@ import org.scalatest.junit.JUnitRunner
88
@RunWith(classOf[JUnitRunner])
99
class ReverseGeocoderTestSuite extends FunSuite with ShouldMatchers {
1010

11+
val reverseGeocoder = new ReverseGeocoder("build/data")
12+
1113
test("basic indexing of all the shapefiles") {
12-
val reverseGeocoder = new ReverseGeocoder("build/data")
14+
reverseGeocoder.mkString should be("neighbourhood, county, admin-1, admin-0")
15+
}
16+
17+
test("lookup lat/lon that is not in any index") {
18+
19+
val option = reverseGeocoder.getLowestLevelWOEIDSetForCoordinates(0, 0)
20+
option.isEmpty should be(true)
21+
}
22+
23+
test("lookup lat/lon that is only in country index") {
24+
25+
val option = reverseGeocoder.getLowestLevelWOEIDSetForCoordinates(53, -125)
26+
option.isEmpty should be(false)
27+
option.get._1 should be("admin-1")
1328

14-
System.out.println(reverseGeocoder.mkString)
29+
val list = option.get._2
30+
list.size should be(1)
31+
list.head should be(0) // FIXME: this is because there are no WOEID's on these shapefiles yet
1532
}
1633
}

0 commit comments

Comments
 (0)