terraformer 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,120 +4,6 @@ describe Terraformer::Geometry do
4
4
 
5
5
  describe 'construction' do
6
6
 
7
- describe Terraformer::Point do
8
-
9
- it 'constructs from coordinate' do
10
- c = Terraformer::Coordinate.new -122.6764, 45.5165
11
- p = Terraformer::Point.new c
12
- p.must_be_valid_geojson
13
- end
14
-
15
- end
16
-
17
- describe Terraformer::MultiPoint do
18
-
19
- it 'constructs from coordinates' do
20
- a = Terraformer::Coordinate.new -122.6764, 45.5165
21
- b = a + [0.02, 0.02]
22
- mp = Terraformer::MultiPoint.new a, b
23
- mp.must_be_valid_geojson
24
- end
25
-
26
- it 'constructs from Point objects' do
27
- a = Terraformer::Coordinate.new -122.6764, 45.5165
28
- b = a + [0.02, 0.02]
29
- mp = Terraformer::MultiPoint.new a.to_point, b.to_point
30
- mp.must_be_valid_geojson
31
- end
32
-
33
- end
34
-
35
- describe Terraformer::LineString do
36
-
37
- it 'constructs from coordinates' do
38
- a = Terraformer::Coordinate.new -122.6764, 45.5165
39
- b = a + [0.02, 0.02]
40
- c = b + [0.1, -0.1]
41
- ls = Terraformer::LineString.new a, b, c
42
- ls.must_be_valid_geojson
43
- end
44
-
45
- end
46
-
47
- describe Terraformer::MultiLineString do
48
-
49
- it 'constructs from coordinates' do
50
- a = Terraformer::Coordinate.new -122.6764, 45.5165
51
- b = a + [0.02, 0.02]
52
- c = b + [0.1, -0.1]
53
- mls = Terraformer::MultiLineString.new a, b, c
54
- mls.must_be_valid_geojson
55
- end
56
-
57
- it 'constructs from coordinates arrays' do
58
- a = Terraformer::Coordinate.new -122.6764, 45.5165
59
- b = a + [0.02, 0.02]
60
- c = b + [0.1, -0.1]
61
- d = c + [1,1]
62
- e = d + [0.02, 0.02]
63
- f = e + [0.1, -0.1]
64
- mls = Terraformer::MultiLineString.new [a, b, c], [d, e, f]
65
- mls.must_be_valid_geojson
66
- end
67
-
68
- it 'constructs from LineString objects' do
69
- a = Terraformer::Coordinate.new -122.6764, 45.5165
70
- b = a + [0.02, 0.02]
71
- c = b + [0.1, -0.1]
72
- d = c + [1,1]
73
- e = d + [0.02, 0.02]
74
- f = e + [0.1, -0.1]
75
- ls_1 = Terraformer::LineString.new a, b, c
76
- ls_2 = Terraformer::LineString.new d, e, f
77
- mls = Terraformer::MultiLineString.new ls_1, ls_2
78
- mls.must_be_valid_geojson
79
- end
80
-
81
- end
82
-
83
- describe Terraformer::Polygon do
84
-
85
- it 'constructs from coordinates' do
86
- a = Terraformer::Coordinate.new -122.6764, 45.5165
87
- b = a + [0, 0.02]
88
- c = b + [0.02, 0]
89
- d = c + [0, -0.02]
90
- p = Terraformer::Polygon.new a, b, c, d, a
91
- p.must_be_valid_geojson
92
- end
93
-
94
- it 'constructs from coordinates array' do
95
- a = Terraformer::Coordinate.new -122.6764, 45.5165
96
- b = a + [0, 0.02]
97
- c = b + [0.02, 0]
98
- d = c + [0, -0.02]
99
- p = Terraformer::Polygon.new [a, b, c, d, a]
100
- p.must_be_valid_geojson
101
- end
102
-
103
- it 'constructs with holes from coordinates arrays' do
104
- a = Terraformer::Coordinate.new -122.6764, 45.5165
105
- b = a + [0, 0.02]
106
- c = b + [0.02, 0]
107
- d = c + [0, -0.02]
108
- hole = [
109
- [ -122.67072200775145, 45.52438983143154 ],
110
- [ -122.67072200775145, 45.53241707548722 ],
111
- [ -122.6617956161499, 45.53241707548722 ],
112
- [ -122.6617956161499, 45.52438983143154 ],
113
- [ -122.67072200775145, 45.52438983143154 ]
114
- ].map {|c| Terraformer::Coordinate.new c}
115
- p = Terraformer::Polygon.new [a, b, c, d, a], hole
116
- p.must_be_valid_geojson
117
- end
118
-
119
- end
120
-
121
7
  describe Terraformer::MultiPolygon do
122
8
 
123
9
  it 'constructs from coordinates' do
@@ -126,6 +12,7 @@ describe Terraformer::Geometry do
126
12
  c = b + [0.02, 0]
127
13
  d = c + [0, -0.02]
128
14
  mp = Terraformer::MultiPolygon.new a, b, c, d, a
15
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]]}'
129
16
  mp.must_be_valid_geojson
130
17
  end
131
18
 
@@ -135,6 +22,13 @@ describe Terraformer::Geometry do
135
22
  c = b + [0.02, 0]
136
23
  d = c + [0, -0.02]
137
24
  mp = Terraformer::MultiPolygon.new [a, b, c, d, a]
25
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]]}'
26
+ mp.must_be_valid_geojson
27
+ end
28
+
29
+ it 'constructs from array - single polygon' do
30
+ mp = Terraformer::MultiPolygon.new [[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]]
31
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]]]}'
138
32
  mp.must_be_valid_geojson
139
33
  end
140
34
 
@@ -151,6 +45,13 @@ describe Terraformer::Geometry do
151
45
  [ -122.67072200775145, 45.52438983143154 ]
152
46
  ].map {|c| Terraformer::Coordinate.new c}
153
47
  mp = Terraformer::MultiPolygon.new [a, b, c, d, a], hole
48
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]}'
49
+ mp.must_be_valid_geojson
50
+ end
51
+
52
+ it 'constructs from array - single polygon with hole' do
53
+ mp = Terraformer::MultiPolygon.new [[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]
54
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]}'
154
55
  mp.must_be_valid_geojson
155
56
  end
156
57
 
@@ -173,6 +74,13 @@ describe Terraformer::Geometry do
173
74
  ].map {|c| Terraformer::Coordinate.new c}
174
75
  p_2 = Terraformer::Polygon.new [a, b, c, d, a], hole
175
76
  mp = Terraformer::MultiPolygon.new p_1, p_2
77
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]],[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]}'
78
+ mp.must_be_valid_geojson
79
+ end
80
+
81
+ it 'constructs from array - multi polygons with hole' do
82
+ mp = Terraformer::MultiPolygon.new [[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]],[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]
83
+ mp.to_json.must_equal '{"type":"MultiPolygon","coordinates":[[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]]],[[[-122.6764,45.5165],[-122.6764,45.5365],[-122.6564,45.5365],[-122.6564,45.5165],[-122.6764,45.5165]],[[-122.67072200775145,45.52438983143154],[-122.67072200775145,45.53241707548722],[-122.6617956161499,45.53241707548722],[-122.6617956161499,45.52438983143154],[-122.67072200775145,45.52438983143154]]]]}'
176
84
  mp.must_be_valid_geojson
177
85
  end
178
86
 
@@ -300,7 +208,7 @@ describe Terraformer::Geometry do
300
208
  ]
301
209
  }'
302
210
  b = Terraformer.parse '{
303
- "type": "LineString",
211
+ "type": "MultiLineString",
304
212
  "coordinates": [
305
213
  [
306
214
  [
data/test/helper.rb CHANGED
@@ -1,9 +1,15 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/test/'
4
+ end
5
+
1
6
  require 'bundler'
2
7
  Bundler.require :default, :test
3
8
 
4
9
  require 'minitest/autorun'
5
10
  require 'minitest/pride'
6
11
 
12
+
7
13
  lib = File.expand_path '../../lib', __FILE__
8
14
  $:.unshift lib unless $:.include? lib
9
15
  require 'terraformer'
@@ -0,0 +1,154 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::LineString do
4
+
5
+ describe 'construction' do
6
+
7
+ it 'constructs from coordinates' do
8
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
9
+ b = a + [0.02, 0.02]
10
+ c = b + [0.1, -0.1]
11
+ ls = Terraformer::LineString.new a, b, c
12
+ ls.to_json.must_equal '{"type":"LineString","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]}'
13
+ ls.must_be_valid_geojson
14
+ end
15
+
16
+ it 'constructs from array' do
17
+ ls = Terraformer::LineString.new [[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]
18
+ ls.to_json.must_equal '{"type":"LineString","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]}'
19
+ ls.must_be_valid_geojson
20
+ end
21
+
22
+ it 'constructs from array of points' do
23
+ ls = Terraformer::LineString.new [-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]
24
+ ls.to_json.must_equal '{"type":"LineString","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]}'
25
+ ls.must_be_valid_geojson
26
+ end
27
+ end
28
+
29
+ describe 'methods' do
30
+ before :each do
31
+ @c1 = Terraformer::Coordinate.new -122.6764, 45.5165
32
+ @c2 = @c1 + [0.02, 0.02]
33
+ @c3 = @c2 + [0.1, -0.1]
34
+ @l = Terraformer::LineString.new @c1, @c2, @c3
35
+ end
36
+
37
+ it 'should have coordinates' do
38
+ @l.coordinates.must_equal [@c1, @c2, @c3]
39
+ end
40
+
41
+ it 'should have first coordinates' do
42
+ @l.first_coordinate.must_equal @c1
43
+ end
44
+
45
+ describe 'linear ring' do
46
+ it 'should not be linear ring' do
47
+ assert !@l.linear_ring?
48
+ end
49
+
50
+ it 'should be linear ring' do
51
+ @l.add_vertex @c1
52
+ assert @l.linear_ring?
53
+ end
54
+ end
55
+
56
+ it 'should get points' do
57
+ points = [@c1.to_point, @c2.to_point, @c3.to_point]
58
+
59
+ @l.points.must_equal points
60
+ @l.vertices.must_equal points
61
+ end
62
+
63
+ it 'should get point at' do
64
+ @l.point_at(1).must_equal Terraformer::Point.new(@c2)
65
+ @l.vertex_at(1).must_equal Terraformer::Point.new(@c2)
66
+ end
67
+
68
+ end
69
+
70
+ describe 'modification methods' do
71
+ before :each do
72
+ @c1 = Terraformer::Coordinate.new -122.6764, 45.5165
73
+ @c2 = @c1 + [0.02, 0.02]
74
+ @c3 = @c2 + [0.1, -0.1]
75
+ @l = Terraformer::LineString.new @c1, @c2, @c3
76
+
77
+ @c4 = @c3 + [0.5, -0.3]
78
+ end
79
+
80
+ it 'should add coordinate' do
81
+ @l.add_vertex @c4
82
+ @l.coordinates.must_equal [ @c1, @c2, @c3, @c4 ]
83
+ end
84
+
85
+ it 'should add point' do
86
+ p = Terraformer::Point.new @c4
87
+ @l.add_vertex p
88
+ @l.coordinates.must_equal [ @c1, @c2, @c3, @c4 ]
89
+ end
90
+
91
+ it 'should return add argument error' do
92
+ assert_raises ArgumentError do
93
+ @l.add_vertex 1
94
+ end
95
+ end
96
+
97
+ it 'should << coordinate' do
98
+ @l << @c4
99
+ @l.coordinates.must_equal [ @c1, @c2, @c3, @c4 ]
100
+ end
101
+
102
+ it 'should << point' do
103
+ p = Terraformer::Point.new @c4
104
+ @l << p
105
+ @l.coordinates.must_equal [ @c1, @c2, @c3, @c4 ]
106
+ end
107
+
108
+ it 'should return add argument error' do
109
+ assert_raises ArgumentError do
110
+ @l << 1
111
+ end
112
+ end
113
+
114
+ it 'should insert coordinate' do
115
+ @l.insert_vertex 1, @c4
116
+ @l.coordinates.must_equal [ @c1, @c4, @c2, @c3 ]
117
+ end
118
+
119
+ it 'should insert point ' do
120
+ p = Terraformer::Point.new @c4
121
+ @l.insert_vertex 1, p
122
+ @l.coordinates.must_equal [ @c1, @c4, @c2, @c3 ]
123
+ end
124
+
125
+ it 'should return insert argument error' do
126
+ assert_raises ArgumentError do
127
+ @l.insert_vertex 1, 1
128
+ end
129
+ end
130
+
131
+ it 'should remove coordinate' do
132
+ @l.remove_vertex @c3
133
+ @l.coordinates.must_equal [ @c1, @c2 ]
134
+ end
135
+
136
+ it 'should remove point' do
137
+ @l.remove_vertex Terraformer::Point.new(@c3)
138
+ @l.coordinates.must_equal [ @c1, @c2 ]
139
+ end
140
+
141
+ it 'should return remove argument error' do
142
+ assert_raises ArgumentError do
143
+ @l.remove_vertex 1
144
+ end
145
+ end
146
+
147
+ it 'should remove vertex at index' do
148
+ @l.remove_vertex_at 1
149
+ @l.coordinates.must_equal [ @c1, @c3 ]
150
+ end
151
+
152
+ end
153
+
154
+ end
@@ -0,0 +1,78 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::MultiLineString do
4
+
5
+ describe 'construction' do
6
+
7
+ it 'constructs from coordinates' do
8
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
9
+ b = a + [0.02, 0.02]
10
+ c = b + [0.1, -0.1]
11
+ mls = Terraformer::MultiLineString.new a, b, c
12
+ mls.to_json.must_equal '{"type":"MultiLineString","coordinates":[[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]]}'
13
+ mls.must_be_valid_geojson
14
+ end
15
+
16
+ it 'constructs from array - single line' do
17
+ ## unlike point, multipoint and linestring, passing in the coordinates array directly into multilinestring doesn't work
18
+ # mls = Terraformer::MultiLineString.new [[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]]
19
+ mls = Terraformer::MultiLineString.new [[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]
20
+ mls.to_json.must_equal '{"type":"MultiLineString","coordinates":[[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]]]}'
21
+ mls.must_be_valid_geojson
22
+ end
23
+
24
+ it 'constructs from coordinates arrays' do
25
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
26
+ b = a + [0.02, 0.02]
27
+ c = b + [0.1, -0.1]
28
+ d = c + [1,1]
29
+ e = d + [0.02, 0.02]
30
+ f = e + [0.1, -0.1]
31
+ mls = Terraformer::MultiLineString.new [a, b, c], [d, e, f]
32
+ mls.to_json.must_equal '{"type":"MultiLineString","coordinates":[[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]],[[-121.5564,46.4365],[-121.5364,46.4565],[-121.4364,46.3565]]]}'
33
+ mls.must_be_valid_geojson
34
+ end
35
+ it 'constructs from LineString objects' do
36
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
37
+ b = a + [0.02, 0.02]
38
+ c = b + [0.1, -0.1]
39
+ d = c + [1,1]
40
+ e = d + [0.02, 0.02]
41
+ f = e + [0.1, -0.1]
42
+ ls_1 = Terraformer::LineString.new a, b, c
43
+ ls_2 = Terraformer::LineString.new d, e, f
44
+ mls = Terraformer::MultiLineString.new ls_1, ls_2
45
+ mls.to_json.must_equal '{"type":"MultiLineString","coordinates":[[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]],[[-121.5564,46.4365],[-121.5364,46.4565],[-121.4364,46.3565]]]}'
46
+ mls.must_be_valid_geojson
47
+ end
48
+
49
+ it 'constructs from array - multiple lines' do
50
+ ## unlike point, multipoint and linestring, passing in the coordinates array directly into multilinestring doesn't work
51
+ # mls = Terraformer::MultiLineString.new [[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]],[[-121.5564,46.4365],[-121.5364,46.4565],[-121.4364,46.3565]]]
52
+ mls = Terraformer::MultiLineString.new [[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]],[[-121.5564,46.4365],[-121.5364,46.4565],[-121.4364,46.3565]]
53
+ mls.to_json.must_equal '{"type":"MultiLineString","coordinates":[[[-122.6764,45.5165],[-122.6564,45.5365],[-122.5564,45.4365]],[[-121.5564,46.4365],[-121.5364,46.4565],[-121.4364,46.3565]]]}'
54
+ mls.must_be_valid_geojson
55
+ end
56
+
57
+ end
58
+
59
+ describe 'methods' do
60
+ before :each do
61
+ @a = Terraformer::Coordinate.new -122.6764, 45.5165
62
+ @b = @a + [0.02, 0.02]
63
+ @c = @b + [0.1, -0.1]
64
+ @d = @c + [1,1]
65
+ @e = @d + [0.02, 0.02]
66
+ @f = @e + [0.1, -0.1]
67
+ @mls = Terraformer::MultiLineString.new [@a, @b, @c], [@d, @e, @f]
68
+ end
69
+
70
+ it 'should have coordinates' do
71
+ @mls.coordinates.must_equal [[@a, @b, @c], [@d, @e, @f]]
72
+ end
73
+
74
+ it 'should have first coordinates' do
75
+ @mls.first_coordinate.must_equal @a
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,151 @@
1
+ require_relative './helper'
2
+
3
+ describe Terraformer::MultiPoint do
4
+
5
+ describe 'construction' do
6
+
7
+ it 'constructs from coordinates' do
8
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
9
+ b = a + [0.02, 0.02]
10
+ mp = Terraformer::MultiPoint.new a, b
11
+ mp.to_json.must_equal '{"type":"MultiPoint","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365]]}'
12
+ mp.must_be_valid_geojson
13
+ end
14
+
15
+ it 'constructs from Point objects' do
16
+ a = Terraformer::Coordinate.new -122.6764, 45.5165
17
+ b = a + [0.02, 0.02]
18
+ mp = Terraformer::MultiPoint.new a.to_point, b.to_point
19
+ mp.to_json.must_equal '{"type":"MultiPoint","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365]]}'
20
+ mp.must_be_valid_geojson
21
+ end
22
+
23
+ it 'constructs from array' do
24
+ mp = Terraformer::MultiPoint.new [[-122.6764, 45.5165],[-122.6564, 45.5365]]
25
+ mp.to_json.must_equal '{"type":"MultiPoint","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365]]}'
26
+ mp.must_be_valid_geojson
27
+ end
28
+
29
+ it 'constructs from multiple point arrays' do
30
+ mp = Terraformer::MultiPoint.new [-122.6764, 45.5165],[-122.6564, 45.5365]
31
+ mp.to_json.must_equal '{"type":"MultiPoint","coordinates":[[-122.6764,45.5165],[-122.6564,45.5365]]}'
32
+ mp.must_be_valid_geojson
33
+ end
34
+
35
+ end
36
+ describe 'methods' do
37
+ before :each do
38
+ @p1 = Terraformer::Point.new -122.6764, 45.5165
39
+ @p2 = Terraformer::Point.new -122.6564, 45.5365
40
+ @mp = Terraformer::MultiPoint.new @p1, @p2
41
+ end
42
+
43
+ it 'should have coordinates' do
44
+ c = Terraformer::Coordinate.new -122.6764, 45.5165
45
+ d = Terraformer::Coordinate.new -122.6564, 45.5365
46
+ @mp.coordinates.must_equal [c,d]
47
+ end
48
+
49
+ it 'should have first_coordinate' do
50
+ c = Terraformer::Coordinate.new -122.6764, 45.5165
51
+ @mp.first_coordinate.must_equal c
52
+ end
53
+
54
+ it 'should return points' do
55
+ @mp.points.must_equal [ @p1, @p2 ]
56
+ end
57
+
58
+ describe 'contains?' do
59
+ it 'should contain any included points' do
60
+ assert @mp.contains?(@p1)
61
+
62
+ end
63
+
64
+ it 'should not contain point' do
65
+ p = Terraformer::Point.new -122, 45
66
+ assert !@mp.contains?(p)
67
+ end
68
+ end
69
+ end
70
+
71
+ describe 'modification methods' do
72
+ before :each do
73
+ @p1 = Terraformer::Point.new -122.6764, 45.5165
74
+ @p2 = Terraformer::Point.new -122.6564, 45.5365
75
+ @mp = Terraformer::MultiPoint.new @p1, @p2
76
+
77
+ @p3 = Terraformer::Point.new -122.6364, 45.5565
78
+ end
79
+
80
+ it 'should add point' do
81
+ @mp.add_point @p3
82
+ @mp.points.must_equal [ @p1, @p2, @p3 ]
83
+ end
84
+
85
+ it 'should add coordinate' do
86
+ @mp.add_point @p3.first_coordinate
87
+ @mp.points.must_equal [ @p1, @p2, @p3 ]
88
+ end
89
+
90
+ it 'should return add argument error' do
91
+ assert_raises ArgumentError do
92
+ @mp.add_point 1
93
+ end
94
+ end
95
+
96
+ it 'should << point' do
97
+ @mp << @p3
98
+ @mp.points.must_equal [ @p1, @p2, @p3 ]
99
+ end
100
+
101
+ it 'should << coordinate' do
102
+ @mp << @p3.first_coordinate
103
+ @mp.points.must_equal [ @p1, @p2, @p3 ]
104
+ end
105
+
106
+ it 'should return << argument error' do
107
+ assert_raises ArgumentError do
108
+ @mp << 1
109
+ end
110
+ end
111
+
112
+ it 'should insert point' do
113
+ @mp.insert_point 1, @p3
114
+ @mp.points.must_equal [ @p1, @p3, @p2 ]
115
+ end
116
+
117
+ it 'should insert coordinate' do
118
+ @mp.insert_point 1, @p3.first_coordinate
119
+ @mp.points.must_equal [ @p1, @p3, @p2 ]
120
+ end
121
+
122
+ it 'should return insert argument error' do
123
+ assert_raises ArgumentError do
124
+ @mp.insert_point 1, 1
125
+ end
126
+ end
127
+
128
+ it 'should remove point' do
129
+ @mp.remove_point @p2
130
+ @mp.points.must_equal [ @p1 ]
131
+ end
132
+
133
+ it 'should remove coordinate' do
134
+ @mp.remove_point @p2.first_coordinate
135
+ @mp.points.must_equal [ @p1 ]
136
+ end
137
+
138
+ it 'should return remove argument error' do
139
+ assert_raises ArgumentError do
140
+ @mp.remove_point 1
141
+ end
142
+ end
143
+
144
+ it 'should remove point at index' do
145
+ @mp.remove_point_at 0
146
+ @mp.points.must_equal [ @p2 ]
147
+ end
148
+
149
+ end
150
+
151
+ end