forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_geom.rb
executable file
·141 lines (122 loc) · 5.08 KB
/
test_geom.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env ruby
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './geom'
require 'minitest/unit'
class TestGeom < MiniTest::Unit::TestCase
# checks that, under normal circumstances, the application of
# a bunch of patches derived from a sequence of versions form
# the same sequence when merged on top of each other. in other
# words, that the patch taking and application works.
#
def test_relation_diff_inserts
geoms = [[],
[ [OSM::Way,29336166]],
[ [OSM::Way,29336166], [OSM::Way,29377987]],
[[OSM::Way,9650915], [OSM::Way,29336166], [OSM::Way,29377987]],
[[OSM::Way,9650915], [OSM::Way,29336166], [OSM::Way,29377987], [OSM::Way,29335519]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_deletes
geoms = [[[OSM::Way,9650915], [OSM::Way,29336166], [OSM::Way,29377987], [OSM::Way,29335519]],
[[OSM::Way,9650915], [OSM::Way,29336166], [OSM::Way,29377987]],
[ [OSM::Way,29336166], [OSM::Way,29377987]],
[ [OSM::Way,29336166]],
[]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_inserts_and_deletes
geoms = [[],
[[OSM::Way,9650915], [OSM::Way,29336166]],
[ [OSM::Way,29336166], [OSM::Way,29377987]],
[[OSM::Way,9650915], [OSM::Way,29336166], [OSM::Way,29377987]],
[[OSM::Way,9650915], [OSM::Way,29377987], [OSM::Way,29335519]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_moves
geoms = [[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3], [OSM::Way,4]],
[[OSM::Way,2], [OSM::Way,1], [OSM::Way,3], [OSM::Way,4]],
[[OSM::Way,2], [OSM::Way,3], [OSM::Way,1], [OSM::Way,4]],
[[OSM::Way,2], [OSM::Way,3], [OSM::Way,4], [OSM::Way,1]],
[[OSM::Way,2], [OSM::Way,3], [OSM::Way,4], [OSM::Way,1]],
[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3], [OSM::Way,4]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_moves_reverse
geoms = [[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3], [OSM::Way,4]],
[[OSM::Way,4], [OSM::Way,1], [OSM::Way,2], [OSM::Way,3]],
[[OSM::Way,3], [OSM::Way,4], [OSM::Way,1], [OSM::Way,2]],
[[OSM::Way,2], [OSM::Way,3], [OSM::Way,4], [OSM::Way,1]],
[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3], [OSM::Way,4]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_alter
geoms = [[[OSM::Way,1], [OSM::Way,2,"foo123"], [OSM::Way,3]],
[[OSM::Way,1], [OSM::Way,2,"bar456"], [OSM::Way,3]],
[[OSM::Way,1], [OSM::Way,2,"bat789"], [OSM::Way,3]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_alter_front
geoms = [[[OSM::Way,1,"foo123"], [OSM::Way,2], [OSM::Way,3]],
[[OSM::Way,1,"bar456"], [OSM::Way,2], [OSM::Way,3]],
[[OSM::Way,1,"bat789"], [OSM::Way,2], [OSM::Way,3]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
def test_relation_diff_alter_back
geoms = [[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3,"foo123"]],
[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3,"bar456"]],
[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3,"bat789"]]
].map {|g| OSM::Relation[g]}
check_diff_apply(geoms)
end
# this is a very cut-down, geometry-only version of one
# of the auto tests, which is failing because the non-applied
# insert by a decliner is throwing off the diff indexes later
# on in the process.
def test_relation_partial_insertion
geoms = [[[OSM::Way,1], [OSM::Way,3]],
[[OSM::Way,1], [OSM::Way,2], [OSM::Way,3]],
[[OSM::Way,1], [OSM::Way,2] ],
[[OSM::Way,1], [OSM::Way,3]],
].map {|g| OSM::Relation[g]}
diffs = geoms.each_cons(2).map {|a, b| Geom.diff(a, b)}
g = geoms[0].geom
# apply diffs, with the first being a "decliner" diff
state = []
g = diffs[0].apply(g, :only => :deleted, :state => state)
g = diffs[1].apply(g, :state => state)
g = diffs[2].apply(g, :state => state)
# the "decliner" diff adds way 2, but this is deleted in
# the final diff, so the result should be the same as the
# first version of the geometry: ways 1 & 3
assert_equal(g, OSM::Relation[[[OSM::Way,1], [OSM::Way,3]]].geom)
end
private
def check_diff_apply(geoms)
x = OSM::Relation[[]]
x.geom = geoms.first.geom
geoms.each_cons(2).each do |a, b|
d = Geom.diff(a, b)
x.geom = d.apply(x.geom)
#puts
#puts "a: #{a.members}"
#puts "b: #{b.members}"
#puts "d: #{d}"
#puts "x: #{x.members}"
assert_equal(b, x)
end
end
end
if __FILE__ == $0
MiniTest::Unit.new.run(ARGV)
end