forked from zerebubuth/openstreetmap-license-change
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_util.rb
48 lines (42 loc) · 2.1 KB
/
test_util.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
require './change_bot'
require './user'
require './changeset'
require './db'
require './actions'
require './util.rb'
require 'test/unit'
class TestUtil < Test::Unit::TestCase
# testing the longest common substring utility function. this isn't
# license-related directly, but it's used in the way/relation geometry
# handling and diffing routines.
def test_util_lcs
assert_equal([], Util::lcs([1,2,3],[4,5,6]))
assert_equal([], Util::lcs([], []))
assert_equal([], Util::lcs([1], [2]))
assert_equal([1], Util::lcs([1], [1]))
assert_equal([1,2,3], Util::lcs([1,2,3],[1,2,3]))
assert_equal([2,3], Util::lcs([1,2,3],[2,3,4]))
assert_equal([2,3,2], Util::lcs([1,2,3,2],[2,3,2,4]))
assert_equal([2,3,2,2], Util::lcs([1,2,3,2,2],[2,3,2,4,2]))
assert_equal([2,3,2,2], Util::lcs([2,3,2,4,2],[1,2,3,2,2]))
assert_equal([2,3,2,2,2], Util::lcs([1,2,3,2,3,3,4,2,2,5,6],[2,3,2,2,2]))
assert_equal([2,3,2,2,2], Util::lcs([2,3,2,2,2],[1,2,3,2,3,3,4,2,2,5,6]))
end
def test_util_diff
assert_equal([], Util::diff([], []))
assert_equal([[:c, 1], [:c, 2], [:c, 3]], Util::diff([1,2,3], [1,2,3]))
assert_equal([[:c, 1], [:a, 2], [:c, 3]], Util::diff([1,2,3], [1,3]))
assert_equal([[:c, 1], [:b, 2], [:c, 3]], Util::diff([1,3], [1,2,3]))
assert_equal([[:a, 1], [:a, 2], [:a, 3]], Util::diff([1,2,3], []))
assert_equal([[:b, 1], [:b, 2], [:b, 3]], Util::diff([], [1,2,3]))
assert_equal([[:a, 1], [:c, 2], [:c, 3], [:b, 4]], Util::diff([1,2,3], [2,3,4]))
assert_equal([[:a, 1], [:a, 2], [:b, 3], [:b, 4]], Util::diff([1,2], [3,4]))
end
def test_util_diff_split
assert_equal([true, true, true], Util::diff_split([], [], [1,2,3], [true, true, true]))
assert_equal([], Util::diff_split([1,2,3], [false, false, false], [], []))
assert_equal([false, false, false], Util::diff_split([1,2,3], [false, false, false], [1,2,3], [true, true, true]))
assert_equal([false, true, false], Util::diff_split([1,3], [false, false], [1,2,3], [true, true, true]))
assert_equal([true, true, false], Util::diff_split([1,3], [true, false], [1,2,3], [true, true, true]))
end
end