bdb1 0.2.4
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.
- data/.document +5 -0
- data/Changes +51 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +21 -0
- data/LICENSE.txt +3 -0
- data/README.md +27 -0
- data/Rakefile +65 -0
- data/VERSION +1 -0
- data/bdb1.gemspec +75 -0
- data/examples/basic.rb +15 -0
- data/examples/func.rb +29 -0
- data/examples/recno.rb +19 -0
- data/examples/record.rb +43 -0
- data/examples/wordtest +10000 -0
- data/examples/zeroc.rb +40 -0
- data/ext/bdb1/bdb1.c +1868 -0
- data/ext/bdb1/bdb1.h +160 -0
- data/ext/bdb1/delegate.c +196 -0
- data/ext/bdb1/extconf.rb +33 -0
- data/ext/bdb1/recnum.c +1093 -0
- data/test/helper.rb +39 -0
- data/test/test_btree.rb +360 -0
- data/test/test_hash.rb +293 -0
- data/test/test_marshal.rb +181 -0
- data/test/test_recnum.rb +440 -0
- data/test/tmp/.keep_me +0 -0
- metadata +153 -0
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMarshal < Test::Unit::TestCase
|
4
|
+
class AZ < BDB1::Btree
|
5
|
+
def bdb1_store_key(a)
|
6
|
+
"xx_" + a
|
7
|
+
end
|
8
|
+
def bdb1_fetch_key(a)
|
9
|
+
a.sub(/^xx_/, '')
|
10
|
+
end
|
11
|
+
def bdb1_store_value(a)
|
12
|
+
"yy_" + a
|
13
|
+
end
|
14
|
+
def bdb1_fetch_value(a)
|
15
|
+
a.sub(/^yy_/, '')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_00_error
|
20
|
+
clean_tmpdir
|
21
|
+
assert_raises(BDB1::Fatal, "invalid name") do
|
22
|
+
BDB1::Btree.new(".", "a")
|
23
|
+
end
|
24
|
+
assert_raises(BDB1::Fatal, "invalid Env") do
|
25
|
+
BDB1::Btree.open(tmpdir("aa"), "env" => 1)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_01_file
|
30
|
+
sub_file_init
|
31
|
+
sub_file_get_set
|
32
|
+
sub_file_delete
|
33
|
+
sub_file_cursor
|
34
|
+
sub_file_reopen
|
35
|
+
sub_file_dup
|
36
|
+
sub_file_close
|
37
|
+
end
|
38
|
+
|
39
|
+
def sub_file_init
|
40
|
+
assert_kind_of(BDB1::Btree, @bdb = BDB1::Btree.new(tmpdir("aa"), "a", "marshal" => Marshal), "<open>")
|
41
|
+
end
|
42
|
+
|
43
|
+
def sub_file_get_set
|
44
|
+
assert_equal([12, "alpha"], @bdb["alpha"] = [12, "alpha"], "<set value>")
|
45
|
+
assert_equal([12, "alpha"], @bdb["alpha"].to_orig, "<retrieve value>")
|
46
|
+
assert_equal(nil, @bdb["gamma"] = nil, "<set nil>")
|
47
|
+
assert_equal(nil, @bdb["gamma"].to_orig, "<retrieve nil>")
|
48
|
+
assert(@bdb.key?("alpha").to_orig == [12, "alpha"], "<has key>")
|
49
|
+
assert_equal(false, @bdb.key?("unknown"), "<has unknown key>")
|
50
|
+
assert(@bdb.value?(nil), "<has nil>")
|
51
|
+
assert(@bdb.value?([12, "alpha"]), "<has value>")
|
52
|
+
assert_equal(false, @bdb.value?("unknown"), "<has unknown value>")
|
53
|
+
assert_equal(false, @bdb.put("alpha", "gamma", BDB1::NOOVERWRITE), "<nooverwrite>")
|
54
|
+
assert_equal([12, "alpha"], @bdb["alpha"].to_orig, "<must not be changed>")
|
55
|
+
assert_equal([1, 2, [3, 4]], @bdb["array"] = [1, 2, [3, 4]], "<array>")
|
56
|
+
assert_equal([1, 2, [3, 4]], @bdb["array"].to_orig, "<retrieve array>")
|
57
|
+
assert_equal({"a" => "b"}, @bdb["hash"] = {"a" => "b"}, "<hash>")
|
58
|
+
assert_equal({"a" => "b"}, @bdb["hash"].to_orig, "<retrieve hash>")
|
59
|
+
assert(@bdb.sync, "<sync>")
|
60
|
+
end
|
61
|
+
|
62
|
+
def sub_file_delete
|
63
|
+
size = @bdb.size
|
64
|
+
i = 0
|
65
|
+
@bdb.each do |key, value|
|
66
|
+
assert_equal(@bdb, @bdb.delete(key), "<delete value>")
|
67
|
+
i += 1
|
68
|
+
end
|
69
|
+
assert(size == i, "<delete count>")
|
70
|
+
assert_equal(0, @bdb.size, "<empty>")
|
71
|
+
end
|
72
|
+
|
73
|
+
def sub_file_cursor
|
74
|
+
cat = Struct.new("Cat", :name, :age, :life)
|
75
|
+
array = ["abc", [1, 3], {"aa" => 12}, [2, {"bb" => "cc"}, 4],
|
76
|
+
cat.new("cat", 15, 7)]
|
77
|
+
array.each do |x|
|
78
|
+
assert_equal(x, @bdb[x] = x, "<set value>")
|
79
|
+
end
|
80
|
+
assert(array.size == @bdb.size, "<set count>")
|
81
|
+
@bdb.each_value do |x|
|
82
|
+
assert(array.index(x) != nil)
|
83
|
+
end
|
84
|
+
@bdb.reverse_each_value do |x|
|
85
|
+
assert(array.index(x) != nil)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def sub_file_reopen
|
90
|
+
assert_equal(nil, @bdb.close, "<close>")
|
91
|
+
assert_kind_of(BDB1::Btree, @bdb = BDB1::Btree.open(tmpdir("aa"), "w",
|
92
|
+
"set_flags" => BDB1::DUP, "marshal" => Marshal),
|
93
|
+
"<reopen with DB_DUP>")
|
94
|
+
assert_equal(0, @bdb.size, "<must be 0 after reopen>")
|
95
|
+
end
|
96
|
+
|
97
|
+
def sub_file_dup
|
98
|
+
array = [[[0, "a"], [1, "b"], [2, "c"], [3, "d"]],
|
99
|
+
[{"aa" => 0}, {"bb" => 1}, {"cc" => 2}],
|
100
|
+
[["aaa", 12], [12, "bbb"]],
|
101
|
+
["aaaa"]]
|
102
|
+
ind = 0
|
103
|
+
array.each do |arr|
|
104
|
+
arr.each do |i|
|
105
|
+
assert_equal(i, @bdb[ind.to_s] = i, "<set dup>")
|
106
|
+
end
|
107
|
+
ind += 1
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def sub_file_close
|
112
|
+
assert_equal(nil, @bdb.close, "<close>")
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_02_memory
|
116
|
+
sub_memory_open
|
117
|
+
sub_memory_get_set
|
118
|
+
sub_memory_close
|
119
|
+
end
|
120
|
+
|
121
|
+
def sub_memory_open
|
122
|
+
assert_kind_of(BDB1::Btree, @bdb = BDB1::Btree.open("marshal" => Marshal), "<open in memory>")
|
123
|
+
assert_equal(0, @bdb.size, "<must be 0 after open>")
|
124
|
+
end
|
125
|
+
|
126
|
+
def sub_memory_get_set
|
127
|
+
assert_equal([1, 2, [3, 4]], @bdb["array"] = [1, 2, [3, 4]], "<set in memory>")
|
128
|
+
assert_equal([1, 2, [3, 4]], @bdb["array"].to_orig, "<get in memory>")
|
129
|
+
assert_equal({"a" => "b"}, @bdb["hash"] = {"a" => "b"}, "<set in memory>")
|
130
|
+
assert_equal({"a" => "b"}, @bdb["hash"].to_orig, "<get in memory>")
|
131
|
+
assert_equal("cc", @bdb["bb"] = "cc", "<set in memory>")
|
132
|
+
assert_equal("cc", @bdb["bb"].to_orig, "<get in memory>")
|
133
|
+
end
|
134
|
+
|
135
|
+
def sub_memory_close
|
136
|
+
assert_equal(nil, @bdb.close, "<close>")
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_04_btree
|
140
|
+
sub_modify
|
141
|
+
sub_sh
|
142
|
+
end
|
143
|
+
|
144
|
+
def sub_modify
|
145
|
+
assert_kind_of(BDB1::Btree, @bdb = BDB1::Btree.open(tmpdir("aa"), "w",
|
146
|
+
"marshal" => Marshal),
|
147
|
+
"<reopen RECNUM>")
|
148
|
+
array = [1, "a", {"a" => 12}]
|
149
|
+
assert_equal(array, @bdb["a"] = array, "<set>")
|
150
|
+
arr = @bdb["a"]
|
151
|
+
arr.push [1, 2]; array.push [1, 2]
|
152
|
+
assert_equal(array, @bdb["a"].to_orig, "<get>")
|
153
|
+
@bdb["a"][-1] = 4; array[-1] = 4
|
154
|
+
assert_equal(array, @bdb["a"].to_orig, "<get>")
|
155
|
+
@bdb["a"][-1] = ["abc", 4]; array[-1] = ["abc", 4]
|
156
|
+
assert_equal(array, @bdb["a"].to_orig, "<get>")
|
157
|
+
assert_equal(nil, @bdb.close, "<close>")
|
158
|
+
end
|
159
|
+
|
160
|
+
def sub_sh
|
161
|
+
val = 'a' .. 'zz'
|
162
|
+
assert_equal(nil, @bdb.close, "<close>")
|
163
|
+
assert_kind_of(BDB1::Btree, @bdb = AZ.open(tmpdir("aa"), "w"), "<sh>")
|
164
|
+
val.each do |l|
|
165
|
+
assert_equal(l, @bdb[l] = l, "<store>")
|
166
|
+
end
|
167
|
+
@bdb.each do |k, v|
|
168
|
+
assert_equal(k, v, "<fetch>")
|
169
|
+
end
|
170
|
+
assert_equal(nil, @bdb.close, "<close>")
|
171
|
+
assert_kind_of(BDB1::Btree, @bdb = BDB1::Btree.open(tmpdir("aa")), "<sh>")
|
172
|
+
val.each do |l|
|
173
|
+
assert_equal("yy_#{l}", @bdb["xx_#{l}"], "<fetch value>")
|
174
|
+
end
|
175
|
+
@bdb.each do |k, v|
|
176
|
+
assert_equal("xx_", k[0, 3], "<fetch key>")
|
177
|
+
assert_equal("yy_", v[0, 3], "<fetch key>")
|
178
|
+
end
|
179
|
+
assert_equal(nil, @bdb.close, "<close>")
|
180
|
+
end
|
181
|
+
end
|
data/test/test_recnum.rb
ADDED
@@ -0,0 +1,440 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestRecnum < Test::Unit::TestCase
|
4
|
+
def reinject(i)
|
5
|
+
1.upto(i) do |i|
|
6
|
+
@array.push i.to_s
|
7
|
+
@bdb1.push i
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_00_error
|
12
|
+
clean_tmpdir
|
13
|
+
assert_raises(BDB1::Fatal, "invalid name") do
|
14
|
+
BDB1::Recnum.new(tmpdir("."), "a")
|
15
|
+
end
|
16
|
+
assert_raises(BDB1::Fatal, "invalid Env") do
|
17
|
+
BDB1::Recnum.open(tmpdir("aa"), "env" => 1)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_01
|
22
|
+
sub_init
|
23
|
+
sub_get_set
|
24
|
+
sub_subseq
|
25
|
+
sub_op
|
26
|
+
sub_at
|
27
|
+
sub_slice
|
28
|
+
sub_slice_bang
|
29
|
+
sub_reverse
|
30
|
+
sub_index
|
31
|
+
sub_delete
|
32
|
+
sub_reject
|
33
|
+
sub_clear
|
34
|
+
sub_fill
|
35
|
+
sub_include
|
36
|
+
sub_replace
|
37
|
+
sub_reopen
|
38
|
+
sub_collect
|
39
|
+
sub_insert
|
40
|
+
sub_flp
|
41
|
+
sub_cmp
|
42
|
+
sub_compact
|
43
|
+
sub_close
|
44
|
+
end
|
45
|
+
|
46
|
+
def sub_init
|
47
|
+
assert_kind_of(BDB1::Recnum, @bdb1 = BDB1::Recnum.new(tmpdir("aa"), "w"), "<open>")
|
48
|
+
@array = []
|
49
|
+
end
|
50
|
+
|
51
|
+
def sub_get_set
|
52
|
+
reinject(99)
|
53
|
+
@bdb1.each_index do |i|
|
54
|
+
assert_equal(@bdb1[i], @array[i], "<sequential get>")
|
55
|
+
end
|
56
|
+
-1.downto(-99) do |i|
|
57
|
+
assert_equal(@bdb1[i], @array[i], "<sequential get reversed>")
|
58
|
+
end
|
59
|
+
200.times do
|
60
|
+
i = rand(@array.size)
|
61
|
+
assert_equal(@bdb1[i], @array[i], "<random get>")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def sub_subseq
|
66
|
+
assert_equal(@bdb1[-1], @array[-1], "<negative index>")
|
67
|
+
assert_equal(@bdb1[2 .. 7], @array[2 .. 7], "<subseq>")
|
68
|
+
@bdb1[2 .. 7] = "a", "b"
|
69
|
+
@array[2 .. 7] = "a", "b"
|
70
|
+
assert_equal(@bdb1.size, @array.size, "<size>")
|
71
|
+
assert_equal(@bdb1.to_a, @array, "<small subseq>")
|
72
|
+
@bdb1[3 .. 6] = "a", "b", "c", "d", "e", "g", "h", "i"
|
73
|
+
@array[3 .. 6] = "a", "b", "c", "d", "e", "g", "h", "i"
|
74
|
+
assert_equal(@bdb1.size, @array.size, "<size>")
|
75
|
+
assert_equal(@bdb1.to_a, @array, "<big subseq>")
|
76
|
+
end
|
77
|
+
|
78
|
+
def sub_op
|
79
|
+
assert_equal(@bdb1 & ["1", "2", "3"], @array & ["1", "2", "3"], "<&>")
|
80
|
+
assert_equal(@bdb1 & [], @array & [], "<&>")
|
81
|
+
assert_equal(@bdb1 + ["3", "4"], @array + ["3", "4"], "<plus>")
|
82
|
+
assert_equal(["3", "4"] + @bdb1, ["3", "4"] + @array, "<plus>")
|
83
|
+
assert_equal(@bdb1 - ["3", "4"], @array - ["3", "4"], "<minus>")
|
84
|
+
assert_equal(["3", "4"] - @bdb1, ["3", "4"] - @array, "<minus>")
|
85
|
+
assert_equal(@bdb1 * 2, @array * 2, "<multiply>")
|
86
|
+
assert_equal(@bdb1 * ":", @array * ":", "<multiply>")
|
87
|
+
assert_equal(@bdb1 * "", @array * "", "<multiply>")
|
88
|
+
assert_equal(@bdb1.size, @array.size, "<size>")
|
89
|
+
end
|
90
|
+
|
91
|
+
def sub_at
|
92
|
+
assert_equal(@bdb1.to_a, @array, "<equal array>")
|
93
|
+
assert_equal(@bdb1.at(0), @array.at(0), "<positive at>")
|
94
|
+
assert_equal(@bdb1.at(10), @array.at(10), "<positive at>")
|
95
|
+
assert_equal(@bdb1.at(99), @array.at(99), "<positive at>")
|
96
|
+
assert_equal(@bdb1.at(205), @array.at(205), "<positive at>")
|
97
|
+
assert_equal(@bdb1.at(-1), @array.at(-1), "<negative at>")
|
98
|
+
assert_equal(@bdb1.at(-100), @array.at(-100), "<negative at>")
|
99
|
+
assert_equal(@bdb1.at(205), @array.at(205), "<negative at>")
|
100
|
+
end
|
101
|
+
|
102
|
+
def sub_slice
|
103
|
+
assert_equal(@bdb1.to_a, @array, "<equal array>")
|
104
|
+
100.times do
|
105
|
+
i = rand(@bdb1.size)
|
106
|
+
assert_equal(@bdb1.slice(i), @array.slice(i), "<slice>")
|
107
|
+
end
|
108
|
+
100.times do
|
109
|
+
i = rand(@bdb1.size)
|
110
|
+
assert_equal(@bdb1.slice(-i), @array.slice(-i), "<negative slice>")
|
111
|
+
end
|
112
|
+
100.times do
|
113
|
+
i = rand(@bdb1.size)
|
114
|
+
j = rand(@bdb1.size)
|
115
|
+
assert_equal(@bdb1.slice(i, j), @array.slice(i, j), "<slice>")
|
116
|
+
end
|
117
|
+
100.times do
|
118
|
+
i = rand(@bdb1.size)
|
119
|
+
j = rand(@bdb1.size)
|
120
|
+
assert_equal(@bdb1.slice(-i, j), @array.slice(-i, j), "<negative slice>")
|
121
|
+
end
|
122
|
+
100.times do
|
123
|
+
i = rand(@bdb1.size)
|
124
|
+
j = rand(@bdb1.size)
|
125
|
+
assert_equal(@bdb1.slice(i .. j), @array.slice(i .. j), "<range>")
|
126
|
+
end
|
127
|
+
100.times do
|
128
|
+
i = rand(@bdb1.size)
|
129
|
+
j = rand(@bdb1.size)
|
130
|
+
assert_equal(@bdb1.slice(-i, j), @array.slice(-i, j), "<negative range>")
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def sub_slice_bang
|
135
|
+
assert_equal(@bdb1.to_a, @array, "<equal array>")
|
136
|
+
10.times do |iter|
|
137
|
+
i = rand(@bdb1.size)
|
138
|
+
assert_equal(@bdb1.slice!(i), @array.slice!(i), "<#{iter} slice!(#{i})>")
|
139
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice!(#{i}) #{iter}>")
|
140
|
+
reinject(60) if @bdb1.size < 20
|
141
|
+
end
|
142
|
+
10.times do |iter|
|
143
|
+
i = rand(@bdb1.size)
|
144
|
+
assert_equal(@bdb1.slice!(-i), @array.slice!(-i), "<slice!(#{-i})>")
|
145
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice!(#{-i}) #{iter}>")
|
146
|
+
reinject(60) if @bdb1.size < 20
|
147
|
+
end
|
148
|
+
10.times do |iter|
|
149
|
+
i = rand(@bdb1.size)
|
150
|
+
j = rand(@bdb1.size)
|
151
|
+
assert_equal(@bdb1.slice!(i, j), @array.slice!(i, j), "<slice!(#{i}, #{j})>")
|
152
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice!(#{i}, #{j}) #{iter}>")
|
153
|
+
reinject(60) if @bdb1.size < 20
|
154
|
+
end
|
155
|
+
10.times do |iter|
|
156
|
+
i = rand(@bdb1.size)
|
157
|
+
j = i + rand(@bdb1.size - i)
|
158
|
+
assert_equal(@bdb1.slice!(-i, j), @array.slice!(-i, j), "<slice!(#{-i}, #{j})>")
|
159
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice!(#{-i}, #{j}) #{iter}>")
|
160
|
+
reinject(60) if @bdb1.size < 20
|
161
|
+
end
|
162
|
+
reinject(60)
|
163
|
+
another = 0
|
164
|
+
10.times do |iter|
|
165
|
+
i = rand(@bdb1.size)
|
166
|
+
j = i + rand(@bdb1.size - i)
|
167
|
+
if ! @array.slice(i .. j)
|
168
|
+
assert_raises(RangeError, "<invalid range>") { @bdb1.slice!(i .. j) }
|
169
|
+
another += 1
|
170
|
+
redo if another < 10
|
171
|
+
another = 0
|
172
|
+
next
|
173
|
+
end
|
174
|
+
assert_equal(@bdb1.slice!(i .. j), @array.slice!(i .. j), "<slice!(#{i} .. #{j})>")
|
175
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice! #{iter}>")
|
176
|
+
another = 0
|
177
|
+
reinject(60) if @bdb1.size < 20
|
178
|
+
end
|
179
|
+
another = 0
|
180
|
+
10.times do |iter|
|
181
|
+
i = rand(@bdb1.size)
|
182
|
+
j = 1 + rand(@bdb1.size - i)
|
183
|
+
if ! @array.slice(-i .. -j)
|
184
|
+
assert_raises(RangeError, "<invalid range>") { @bdb1.slice!(-i .. -j) }
|
185
|
+
another += 1
|
186
|
+
redo if another < 10
|
187
|
+
another = 0
|
188
|
+
next
|
189
|
+
end
|
190
|
+
assert_equal(@bdb1.slice!(-i .. -j), @array.slice!(-i .. -j), "<slice!(#{-i} .. #{-j})>")
|
191
|
+
assert_equal(@bdb1.size, @array.size, "<size after slice! #{iter}>")
|
192
|
+
another = 0
|
193
|
+
reinject(60) if @bdb1.size < 20
|
194
|
+
end
|
195
|
+
reinject(40) if @bdb1.size < 40
|
196
|
+
assert_equal(@bdb1.size, @array.size, "<size end slice!>")
|
197
|
+
assert_equal(@bdb1.to_a, @array, "<size end slice!>")
|
198
|
+
end
|
199
|
+
|
200
|
+
def sub_reverse
|
201
|
+
assert_equal(@bdb1.reverse, @array.reverse, "<reverse>")
|
202
|
+
@array.reverse! ; @bdb1.reverse!
|
203
|
+
assert_equal(@bdb1.to_a, @array, "<reverse bang>")
|
204
|
+
assert_equal(@bdb1.size, @array.size, "<size after reverse>")
|
205
|
+
end
|
206
|
+
|
207
|
+
def sub_index
|
208
|
+
100.times do
|
209
|
+
i = rand(@bdb1.size)
|
210
|
+
assert_equal(@bdb1.index(i), @array.index(i), "<index #{i}>")
|
211
|
+
assert_equal(@bdb1.index(-i), @array.index(-i), "<negative index #{i}>")
|
212
|
+
end
|
213
|
+
100.times do
|
214
|
+
i = rand(@bdb1.size)
|
215
|
+
assert_equal(@bdb1.rindex(i), @array.rindex(i), "<rindex #{i}>")
|
216
|
+
assert_equal(@bdb1.rindex(-i), @array.rindex(-i), "<negative rindex #{i}>")
|
217
|
+
end
|
218
|
+
100.times do
|
219
|
+
aa = []
|
220
|
+
rand(12).times do
|
221
|
+
aa.push(rand(@bdb1.size))
|
222
|
+
end
|
223
|
+
assert_equal(@array.values_at(*aa), @bdb1.values_at(*aa), "<values_at>")
|
224
|
+
end
|
225
|
+
100.times do
|
226
|
+
aa = []
|
227
|
+
rand(12).times do
|
228
|
+
aa.push(-1 * rand(@bdb1.size))
|
229
|
+
end
|
230
|
+
assert_equal(@array.values_at(*aa), @bdb1.values_at(*aa), "<negative values_at #{aa}>")
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def sub_delete
|
235
|
+
assert_equal(@bdb1.to_a, @array, "<before delete>")
|
236
|
+
100.times do
|
237
|
+
i = rand(@bdb1.size)
|
238
|
+
assert_equal(@bdb1.delete(i), @array.delete(i), "<delete #{i}>")
|
239
|
+
reinject(60) if @bdb1.size < 20
|
240
|
+
end
|
241
|
+
assert_equal(@bdb1.to_a, @array, "<after delete>")
|
242
|
+
100.times do
|
243
|
+
i = rand(@bdb1.size)
|
244
|
+
assert_equal(@bdb1.delete_at(i), @array.delete_at(i), "<delete at #{i}>")
|
245
|
+
reinject(60) if @bdb1.size < 20
|
246
|
+
end
|
247
|
+
assert_equal(@bdb1.to_a, @array, "<after delete_at>")
|
248
|
+
reinject(60) if @bdb1.size < 60
|
249
|
+
assert_equal(@bdb1.delete_if { false }, @bdb1, "<delete_if false>")
|
250
|
+
assert_equal(@bdb1.to_a, @array, "<after delete_if false>")
|
251
|
+
assert_equal(@bdb1.delete_if { true }, @bdb1, "<delete_if true>")
|
252
|
+
assert_equal(@bdb1.size, 0, "<after delete_if true>")
|
253
|
+
@bdb1.push *@array
|
254
|
+
assert_equal(@bdb1.to_a, @array, "<after push>")
|
255
|
+
100.times do
|
256
|
+
i = rand(@bdb1.size)
|
257
|
+
assert_equal(@bdb1.delete_if {|i| i.to_i > 32}, @bdb1, "<delete_if condition>")
|
258
|
+
@array.delete_if {|i| i.to_i > 32}
|
259
|
+
assert_equal(@bdb1.to_a, @array, "<delete_if condition compare>")
|
260
|
+
reinject(60) if @bdb1.size < 60
|
261
|
+
end
|
262
|
+
reinject(99) if @bdb1.size < 99
|
263
|
+
end
|
264
|
+
|
265
|
+
def sub_reject
|
266
|
+
assert_equal(@bdb1.to_a, @array, "<before reject!>")
|
267
|
+
assert_equal(nil, @bdb1.reject! { false }, "<reject! false>")
|
268
|
+
end
|
269
|
+
|
270
|
+
def sub_clear
|
271
|
+
@bdb1.clear ; @array.clear
|
272
|
+
assert_equal(@array.size, @bdb1.size, "<size after clear>")
|
273
|
+
assert_equal(@array, @bdb1.to_a, "<after clear>")
|
274
|
+
end
|
275
|
+
|
276
|
+
def sub_fill
|
277
|
+
@bdb1.fill "32", 0, 99; @array.fill "32", 0, 99
|
278
|
+
assert_equal(@array.size, @bdb1.size, "<size after fill>")
|
279
|
+
assert_equal(@array, @bdb1.to_a, "<after fill>")
|
280
|
+
@bdb1.fill "42"; @array.fill "42"
|
281
|
+
assert_equal(@array.size, @bdb1.size, "<size after fill>")
|
282
|
+
assert_equal(@array, @bdb1.to_a, "<after fill>")
|
283
|
+
10.times do |iter|
|
284
|
+
k = rand(@bdb1.size).to_s
|
285
|
+
i = rand(@bdb1.size)
|
286
|
+
assert_equal(@bdb1.fill(k, i).to_a, @array.fill(k, i), "<#{iter} fill(#{i})>")
|
287
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill(#{i}) #{iter}>")
|
288
|
+
reinject(60) if @bdb1.size < 20
|
289
|
+
end
|
290
|
+
10.times do |iter|
|
291
|
+
k = rand(@bdb1.size).to_s
|
292
|
+
i = rand(@bdb1.size)
|
293
|
+
assert_equal(@bdb1.fill(k, -i).to_a, @array.fill(k, -i), "<fill(#{-i})>")
|
294
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill(#{-i}) #{iter}>")
|
295
|
+
reinject(60) if @bdb1.size < 20
|
296
|
+
end
|
297
|
+
10.times do |iter|
|
298
|
+
k = rand(@bdb1.size).to_s
|
299
|
+
i = rand(@bdb1.size)
|
300
|
+
j = rand(@bdb1.size)
|
301
|
+
assert_equal(@bdb1.fill(k, i, j).to_a, @array.fill(k, i, j), "<fill(#{i}, #{j})>")
|
302
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill(#{i}, #{j}) #{iter}>")
|
303
|
+
reinject(60) if @bdb1.size < 20
|
304
|
+
end
|
305
|
+
10.times do |iter|
|
306
|
+
k = rand(@bdb1.size).to_s
|
307
|
+
i = rand(@bdb1.size)
|
308
|
+
j = i + rand(@bdb1.size - i)
|
309
|
+
assert_equal(@bdb1.fill(k, -i, j).to_a, @array.fill(k, -i, j), "<fill(#{-i}, #{j})>")
|
310
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill(#{-i}, #{j}) #{iter}>")
|
311
|
+
reinject(60) if @bdb1.size < 20
|
312
|
+
end
|
313
|
+
reinject(60)
|
314
|
+
another = 0
|
315
|
+
10.times do |iter|
|
316
|
+
k = rand(@bdb1.size).to_s
|
317
|
+
i = rand(@bdb1.size)
|
318
|
+
j = i + rand(@bdb1.size - i)
|
319
|
+
if ! @array.slice(i .. j)
|
320
|
+
assert_raises(RangeError, "<invalid range>") { @bdb1.fill(k, i .. j) }
|
321
|
+
another += 1
|
322
|
+
redo if another < 10
|
323
|
+
another = 0
|
324
|
+
next
|
325
|
+
end
|
326
|
+
assert_equal(@bdb1.fill(k, i .. j).to_a, @array.fill(k, i .. j), "<fill(#{i} .. #{j})>")
|
327
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill #{iter}>")
|
328
|
+
another = 0
|
329
|
+
reinject(60) if @bdb1.size < 20
|
330
|
+
end
|
331
|
+
another = 0
|
332
|
+
10.times do |iter|
|
333
|
+
k = rand(@bdb1.size).to_s
|
334
|
+
i = rand(@bdb1.size)
|
335
|
+
j = 1 + rand(@bdb1.size - i)
|
336
|
+
if ! @array.slice(-i .. -j)
|
337
|
+
assert_raises(RangeError, "<invalid range>") { @bdb1.fill(k, -i .. -j) }
|
338
|
+
another += 1
|
339
|
+
redo if another < 10
|
340
|
+
another = 0
|
341
|
+
next
|
342
|
+
end
|
343
|
+
assert_equal(@bdb1.fill(k, -i .. -j).to_a, @array.fill(k, -i .. -j), "<fill(#{-i} .. #{-j})>")
|
344
|
+
assert_equal(@bdb1.size, @array.size, "<size after fill #{iter}>")
|
345
|
+
another = 0
|
346
|
+
reinject(60) if @bdb1.size < 20
|
347
|
+
end
|
348
|
+
reinject(60) if @bdb1.size < 60
|
349
|
+
assert_equal(@bdb1.size, @array.size, "<size end fill>")
|
350
|
+
assert_equal(@bdb1.to_a, @array, "<size end fill>")
|
351
|
+
end
|
352
|
+
|
353
|
+
def sub_include
|
354
|
+
@bdb1.clear; @array.clear; reinject(99)
|
355
|
+
assert_equal(@bdb1.size, @array.size, "<size end clear>")
|
356
|
+
assert_equal(@bdb1.to_a, @array, "<size end clear>")
|
357
|
+
100.times do
|
358
|
+
k = rand(@bdb1.size + 20).to_s
|
359
|
+
assert_equal(@array.include?(k), @bdb1.include?(k), "<include(#{k})>")
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def sub_replace
|
364
|
+
@array.replace(('a' .. 'zz').to_a)
|
365
|
+
@bdb1.replace(('a' .. 'zz').to_a)
|
366
|
+
assert_equal(@bdb1.size, @array.size, "<size end fill>")
|
367
|
+
assert_equal(@bdb1.to_a, @array, "<size end fill>")
|
368
|
+
end
|
369
|
+
|
370
|
+
def sub_reopen
|
371
|
+
@bdb1.close
|
372
|
+
assert_kind_of(BDB1::Recnum, @bdb1 = BDB1::Recnum.new(tmpdir("aa"), "a"), "<open>")
|
373
|
+
assert_equal(@bdb1.size, @array.size, "<size end reopen>")
|
374
|
+
assert_equal(@bdb1.to_a, @array, "<size end open>")
|
375
|
+
end
|
376
|
+
|
377
|
+
def sub_collect
|
378
|
+
a = @bdb1.collect
|
379
|
+
assert_equal(@array, a, "<collect>")
|
380
|
+
a = @array.collect {|k| k + "!"}
|
381
|
+
b = @bdb1.collect {|k| k + "!"}
|
382
|
+
assert_equal(a, b, "<collect>")
|
383
|
+
assert_equal(@bdb1.to_a, @array, "<collect bdb>")
|
384
|
+
|
385
|
+
a = @array.collect! {|k| k + "!"}
|
386
|
+
b = @bdb1.collect! {|k| k + "!"}
|
387
|
+
assert_equal(a, b, "<collect!>")
|
388
|
+
assert_equal(@bdb1.to_a, @array, "<collect bdb>")
|
389
|
+
end
|
390
|
+
|
391
|
+
def sub_insert
|
392
|
+
@array.insert(2, "1", "2", "3")
|
393
|
+
@array.insert(-1, "4", "5")
|
394
|
+
@array.insert(-4, "3", "5", "5", "5", "5")
|
395
|
+
@bdb1.insert(2, 1, 2, 3)
|
396
|
+
@bdb1.insert(-1, 4, 5)
|
397
|
+
@bdb1.insert(-4, 3, 5, 5, 5, 5)
|
398
|
+
assert_equal(@bdb1.to_a, @array, "<insert bdb>")
|
399
|
+
end
|
400
|
+
|
401
|
+
def sub_flp
|
402
|
+
assert_equal(@array.first, @bdb1.first, "<first>")
|
403
|
+
assert_equal(@array.last, @bdb1.last, "<last>")
|
404
|
+
@bdb1.concat(@array)
|
405
|
+
@array.concat(@array)
|
406
|
+
assert_equal(@bdb1.to_a, @array, "<insert bdb>")
|
407
|
+
assert_equal(@bdb1, @bdb1 << 12, "<push>")
|
408
|
+
@array << "12"
|
409
|
+
assert_equal(@bdb1.to_a, @array, "<insert bdb>")
|
410
|
+
assert_equal(@array.pop, @bdb1.pop, "<pop>")
|
411
|
+
@array.unshift("5", "6")
|
412
|
+
@bdb1.unshift(5, 6)
|
413
|
+
assert_equal(@bdb1.to_a, @array, "<unshift bdb>")
|
414
|
+
assert_equal(@array.shift, @bdb1.shift, "<shift>")
|
415
|
+
assert_equal(@bdb1.to_a, @array, "<unshift bdb>")
|
416
|
+
assert_equal(0, @bdb1 <=> @array, "<cmp>")
|
417
|
+
end
|
418
|
+
|
419
|
+
def sub_cmp
|
420
|
+
assert_kind_of(BDB1::Recnum, bdb1 = BDB1::Recnum.new(tmpdir("bb"), "a"), "<open>")
|
421
|
+
assert_equal(true, bdb1.empty?, "<empty>")
|
422
|
+
@array.each {|a| bdb1 << a}
|
423
|
+
assert_equal(false, bdb1.empty?, "<empty>")
|
424
|
+
assert_equal(0, @bdb1 <=> bdb1, "<=>")
|
425
|
+
bdb1 << 12
|
426
|
+
assert_equal(1, bdb1 <=> @bdb1, "<=>")
|
427
|
+
assert_equal(-1, @bdb1 <=> bdb1, "<=>")
|
428
|
+
end
|
429
|
+
|
430
|
+
def sub_compact
|
431
|
+
assert_equal(@array.compact, @bdb1.compact, "<compact>")
|
432
|
+
@array.compact!
|
433
|
+
@bdb1.compact!
|
434
|
+
assert_equal(@bdb1.to_a, @array, "<compact!>")
|
435
|
+
end
|
436
|
+
|
437
|
+
def sub_close
|
438
|
+
assert_equal(nil, @bdb1.close, "<close>")
|
439
|
+
end
|
440
|
+
end
|