Skip to content

Commit c951f34

Browse files
committed
Port SerializationSpec to Scalatest
1 parent ccdfbae commit c951f34

File tree

1 file changed

+64
-66
lines changed

1 file changed

+64
-66
lines changed

geoscript/src/test/scala/org/geoscript/geometry/SerializationSpec.scala

Lines changed: 64 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,82 @@ package org.geoscript
22
package geometry
33

44
import org.geoscript.io.{ Sink, Source }
5-
import org.specs._
5+
import org.scalatest._, matchers._
66

7-
class SerializationSpec extends Specification {
8-
"JSON Serialization" should {
9-
"round-trip points" in {
10-
val p = Point(100, 0)
11-
val json = io.GeoJSON.write(p, Sink.string)
12-
json must_== """{"type":"Point","coordinates":[100,0.0]}"""
13-
// io.GeoJSON.read(Source.string(json)) must_== p
14-
// TODO: Implement equality for geometries
15-
}
7+
class SerializationSpec extends FunSuite with ShouldMatchers {
8+
test("round-trip points") {
9+
val p = Point(100, 0)
10+
val json = io.GeoJSON.write(p, Sink.string)
11+
json should be("""{"type":"Point","coordinates":[100,0.0]}""")
12+
// io.GeoJSON.read(Source.string(json)) should be p
13+
// TODO: Implement equality for geometries
14+
}
1615

17-
"round-trip linestrings" in {
18-
val ls = LineString((100, 0), (101, 1))
19-
io.GeoJSON.write(ls, Sink.string) must_==
20-
"""{"type":"LineString","coordinates":[[100,0.0],[101,1]]}"""
21-
}
16+
test("round-trip linestrings") {
17+
val ls = LineString((100, 0), (101, 1))
18+
io.GeoJSON.write(ls, Sink.string) should be
19+
("""{"type":"LineString","coordinates":[[100,0.0],[101,1]]}""")
20+
}
2221

23-
"round-trip polygons" in {
24-
val solid = Polygon(
25-
LineString((100, 0), (101, 0), (101, 1), (100, 1), (100, 0))
26-
)
22+
test("round-trip polygons") {
23+
val solid = Polygon(
24+
LineString((100, 0), (101, 0), (101, 1), (100, 1), (100, 0))
25+
)
2726

28-
val withHoles = Polygon(
29-
LineString((100, 0), (101, 0), (101, 1), (100, 1), (100, 0)),
30-
Seq(LineString(
31-
(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8), (100.2, 0.2)
32-
))
33-
)
27+
val withHoles = Polygon(
28+
LineString((100, 0), (101, 0), (101, 1), (100, 1), (100, 0)),
29+
Seq(LineString(
30+
(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8), (100.2, 0.2)
31+
))
32+
)
3433

35-
io.GeoJSON.write(solid, Sink.string) must_==
36-
"""{"type":"Polygon","coordinates":[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]]]}"""
37-
io.GeoJSON.write(withHoles, Sink.string) must_==
38-
"""{"type":"Polygon","coordinates":[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}"""
39-
}
34+
io.GeoJSON.write(solid, Sink.string) should be(
35+
"""{"type":"Polygon","coordinates":[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]]]}""")
36+
io.GeoJSON.write(withHoles, Sink.string) should be(
37+
"""{"type":"Polygon","coordinates":[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]}""")
38+
}
4039

41-
"round-trip a multipoint" in {
42-
val mp = MultiPoint((100.0, 0.0), (101.0, 1.0))
43-
io.GeoJSON.write(mp, Sink.string) must_==
44-
"""{"type":"MultiPoint","coordinates":[[100,0.0],[101,1]]}"""
45-
}
40+
test("round-trip a multipoint") {
41+
val mp = MultiPoint((100.0, 0.0), (101.0, 1.0))
42+
io.GeoJSON.write(mp, Sink.string) should be(
43+
"""{"type":"MultiPoint","coordinates":[[100,0.0],[101,1]]}""")
44+
}
4645

47-
"round-trip a MultiLineString" in {
48-
val mls = MultiLineString(
49-
LineString((100, 0), Point(101, 1)),
50-
LineString((102, 2), Point(103, 3))
51-
)
46+
test("round-trip a MultiLineString") {
47+
val mls = MultiLineString(
48+
LineString((100, 0), Point(101, 1)),
49+
LineString((102, 2), Point(103, 3))
50+
)
5251

53-
io.GeoJSON.write(mls, Sink.string) must_==
54-
"""{"type":"MultiLineString","coordinates":[[[100,0.0],[101,1]],[[102,2],[103,3]]]}"""
55-
}
52+
io.GeoJSON.write(mls, Sink.string) should be(
53+
"""{"type":"MultiLineString","coordinates":[[[100,0.0],[101,1]],[[102,2],[103,3]]]}""")
54+
}
5655

57-
"round-trip a MultiPolygon" in {
58-
val mp = MultiPolygon(
59-
Polygon(LineString(
60-
(102, 2), (103, 2), (103, 3), (102, 3), (102, 2)
61-
)),
62-
Polygon(LineString(
63-
(100, 0), (101, 0), (101, 1), (100, 1), (100, 0)
64-
),
65-
Seq(LineString(
66-
(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8), (100.2, 0.2)
67-
))
68-
)
56+
test("round-trip a MultiPolygon") {
57+
val mp = MultiPolygon(
58+
Polygon(LineString(
59+
(102, 2), (103, 2), (103, 3), (102, 3), (102, 2)
60+
)),
61+
Polygon(LineString(
62+
(100, 0), (101, 0), (101, 1), (100, 1), (100, 0)
63+
),
64+
Seq(LineString(
65+
(100.2, 0.2), (100.8, 0.2), (100.8, 0.8), (100.2, 0.8), (100.2, 0.2)
66+
))
6967
)
68+
)
7069

71-
io.GeoJSON.write(mp, Sink.string) must_==
72-
"""{"type":"MultiPolygon","coordinates":[[[[102,2],[103,2],[103,3],[102,3],[102,2]]],[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}"""
73-
}
70+
io.GeoJSON.write(mp, Sink.string) should be(
71+
"""{"type":"MultiPolygon","coordinates":[[[[102,2],[103,2],[103,3],[102,3],[102,2]]],[[[100,0.0],[101,0.0],[101,1],[100,1],[100,0.0]],[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}""")
72+
}
7473

75-
"round-trip a GeometryCollection" in {
76-
val gc = GeometryCollection(
77-
Point(100.0, 0.0),
78-
LineString((101.0, 0.0), (102.0, 1.0))
79-
)
74+
test("round-trip a GeometryCollection") {
75+
val gc = GeometryCollection(
76+
Point(100.0, 0.0),
77+
LineString((101.0, 0.0), (102.0, 1.0))
78+
)
8079

81-
io.GeoJSON.write(gc, Sink.string) must_==
82-
"""{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[100,0.0]},{"type":"LineString","coordinates":[[101,0.0],[102,1]]}]}"""
83-
}
80+
io.GeoJSON.write(gc, Sink.string) should be(
81+
"""{"type":"GeometryCollection","geometries":[{"type":"Point","coordinates":[100,0.0]},{"type":"LineString","coordinates":[[101,0.0],[102,1]]}]}""")
8482
}
8583
}

0 commit comments

Comments
 (0)