File: test_cases.rb

package info (click to toggle)
libalgorithm-diff-ruby 0.4-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 96 kB
  • ctags: 195
  • sloc: ruby: 1,168; makefile: 60
file content (137 lines) | stat: -rw-r--r-- 2,223 bytes parent folder | download | duplicates (5)
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
module DiffArrayTests

  def test_array_append
    difftest [1,2,3], [1,2,3,4]
    difftest [1,2,3], [1,2,3,4,5]
  end

  def test_array_prepend
    difftest [1,2,3], [0,1,2,3]
    difftest [1,2,3], [-1,0,1,2,3]
  end

  def test_array_insert
    difftest [1,2,3], [1,2,4,3]
    difftest [1,2,3], [1,2,4,5,3]
  end

  def test_array_remove
    difftest [1,2,3], [1,3]
  end

  def test_array_cutfront
    difftest [1,2,3], [2,3]
    difftest [1,2,3], [3]
  end

  def test_array_cutback
    difftest [1,2,3], [1,2]
    difftest [1,2,3], [1]
  end

  def test_array_empty
    difftest [1,2,3], []
  end

  def test_array_fill
    difftest [], [1,2,3]
  end

  def test_array_change
    difftest [1,2,3], [1,4,3]
    difftest [1,2,3], [1,4,5]
    difftest [1,2,3,4], [1,5,4]
  end

  def test_array_noop
    difftest [1,2,3], [1,2,3]
  end

  def test_array_grow
    difftest [1,2,3], [4,1,5,2,6,3,7]
  end

  def test_array_shrink
    difftest [1,2,3,4,5,6,7], [2,4,6]
  end

end

module DiffStringTests

  def test_string_append
    difftest "abc", "abcd"
    difftest "abc", "abcde"
  end

  def test_string_preprend
    difftest "abc", "qabc"
    difftest "abc", "qrabc"
  end
  
  def test_string_insert
    difftest "abc", "abqc"
    difftest "abc", "abqrc"
  end
  
  def test_string_cutfront
    difftest "abc", "bc"
    difftest "abc", "c"
  end

  def test_string_cutback
    difftest "abc", "ab"
    difftest "abc", "a"
  end

  def test_string_empty
    difftest "abc", ""
  end
  
  def test_string_fill
    difftest "", "abc"
  end

  def test_string_change
    difftest "abc", "aqc"
    difftest "abc", "aqrc"
    difftest "abcd", "aqd"
  end

  def test_string_noop
    difftest "abc", "abc"
  end

  def test_string_grow
    difftest "abc", "qarbsct"
  end
  
  def test_string_shrink
    difftest "abcdefg", "bdf"
  end

  def test_string_remove
    difftest "abc", "ac"
  end

end

module DiffStressTest
  Elems = [1,2,3]
  def generate_array
    length = (16 + 16 * rand).to_i
    ary = []
    length.times {
      ary << Elems[(rand * Elems.length).to_i]
    }
    return ary
  end

  def test_stress
    256.times {
      a = generate_array
      b = generate_array
      difftest(a, b)
    }
  end
end