* test/sdbm/test_sdbm.rb: renamed from ext/sdbm/testsdbm.rb with

modification to use test/unit.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2005-06-03 16:43:39 +00:00
Родитель 6c4d802e14
Коммит 49f4ef7d03
2 изменённых файлов: 109 добавлений и 145 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed May 25 12:59:48 2005 Tanaka Akira <akr@m17n.org>
* test/sdbm/test_sdbm.rb: renamed from ext/sdbm/testsdbm.rb with
modification to use test/unit.
Fri Jun 3 23:23:02 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* intern.h (rb_fdset_t): deal with fd bit sets over FD_SETSIZE.

Просмотреть файл

@ -1,32 +1,11 @@
require 'runit/testcase'
require 'runit/cui/testrunner'
require 'test/unit'
if $".grep(/\bsdbm.so\b/).empty?
begin
require './sdbm'
rescue LoadError
require 'sdbm'
end
begin
require 'sdbm'
rescue LoadError
end
def uname_s
require 'rbconfig'
case Config::CONFIG['host_os']
when 'cygwin'
require 'Win32API'
uname = Win32API.new('cygwin1', 'uname', 'P', 'I')
utsname = ' ' * 100
raise 'cannot get system name' if uname.call(utsname) == -1
utsname.unpack('A20' * 5)[0]
else
Config::CONFIG['host_os']
end
end
SYSTEM = uname_s
class TestSDBM < RUNIT::TestCase
class TestSDBM < Test::Unit::TestCase
def setup
@path = "tmptest_sdbm_"
assert_instance_of(SDBM, @sdbm = SDBM.new(@path))
@ -39,14 +18,14 @@ class TestSDBM < RUNIT::TestCase
end
def check_size(expect, sdbm=@sdbm)
assert_equals(expect, sdbm.size)
assert_equal(expect, sdbm.size)
n = 0
sdbm.each { n+=1 }
assert_equals(expect, n)
assert_equal(expect, n)
if expect == 0
assert_equals(true, sdbm.empty?)
assert_equal(true, sdbm.empty?)
else
assert_equals(false, sdbm.empty?)
assert_equal(false, sdbm.empty?)
end
end
@ -58,7 +37,7 @@ class TestSDBM < RUNIT::TestCase
# SDBM.new ignore the block
foo = true
assert_instance_of(SDBM, sdbm = SDBM.new("tmptest_sdbm") { foo = false })
assert_equals(foo, true)
assert_equal(foo, true)
assert_nil(sdbm.close)
end
def test_s_open_no_create
@ -67,14 +46,14 @@ class TestSDBM < RUNIT::TestCase
sdbm.close if sdbm
end
def test_s_open_with_block
assert_equals(SDBM.open("tmptest_sdbm") { :foo }, :foo)
assert_equal(SDBM.open("tmptest_sdbm") { :foo }, :foo)
end
=begin
# Is it guaranteed on many OS?
def test_s_open_lock_one_process
# locking on one process
assert_instance_of(SDBM, sdbm = SDBM.open("tmptest_sdbm", 0644))
assert_exception(Errno::EWOULDBLOCK) {
assert_raise(Errno::EWOULDBLOCK) {
begin
SDBM.open("tmptest_sdbm", 0644)
rescue Errno::EAGAIN
@ -128,7 +107,7 @@ class TestSDBM < RUNIT::TestCase
def test_s_open_error
assert_instance_of(SDBM, sdbm = SDBM.open("tmptest_sdbm", 0))
assert_exception(Errno::EACCES) {
assert_raise(Errno::EACCES) {
SDBM.open("tmptest_sdbm", 0)
}
sdbm.close
@ -139,91 +118,84 @@ class TestSDBM < RUNIT::TestCase
assert_nil(sdbm.close)
# closed SDBM file
assert_exception(SDBMError) { sdbm.close }
assert_raise(SDBMError) { sdbm.close }
end
def test_aref
assert_equals('bar', @sdbm['foo'] = 'bar')
assert_equals('bar', @sdbm['foo'])
assert_equal('bar', @sdbm['foo'] = 'bar')
assert_equal('bar', @sdbm['foo'])
assert_nil(@sdbm['bar'])
end
def test_fetch
assert_equals('bar', @sdbm['foo']='bar')
assert_equals('bar', @sdbm.fetch('foo'))
assert_equal('bar', @sdbm['foo']='bar')
assert_equal('bar', @sdbm.fetch('foo'))
# key not found
assert_exception(IndexError) {
assert_raise(IndexError) {
@sdbm.fetch('bar')
}
# test for `ifnone' arg
assert_equals('baz', @sdbm.fetch('bar', 'baz'))
assert_equal('baz', @sdbm.fetch('bar', 'baz'))
# test for `ifnone' block
assert_equals('foobar', @sdbm.fetch('bar') {|key| 'foo' + key })
assert_equal('foobar', @sdbm.fetch('bar') {|key| 'foo' + key })
end
def test_aset
num = 0
2.times {|i|
assert_equals('foo', @sdbm['foo'] = 'foo')
assert_equals('foo', @sdbm['foo'])
assert_equals('bar', @sdbm['foo'] = 'bar')
assert_equals('bar', @sdbm['foo'])
assert_equal('foo', @sdbm['foo'] = 'foo')
assert_equal('foo', @sdbm['foo'])
assert_equal('bar', @sdbm['foo'] = 'bar')
assert_equal('bar', @sdbm['foo'])
num += 1 if i == 0
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
# assign nil
assert_equals('', @sdbm['bar'] = '')
assert_equals('', @sdbm['bar'])
assert_equal('', @sdbm['bar'] = '')
assert_equal('', @sdbm['bar'])
num += 1 if i == 0
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
# empty string
assert_equals('', @sdbm[''] = '')
assert_equals('', @sdbm[''])
assert_equal('', @sdbm[''] = '')
assert_equal('', @sdbm[''])
num += 1 if i == 0
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
# Fixnum
assert_equals('200', @sdbm['100'] = '200')
assert_equals('200', @sdbm['100'])
assert_equal('200', @sdbm['100'] = '200')
assert_equal('200', @sdbm['100'])
num += 1 if i == 0
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
# Big key and value
assert_equals('y' * 100, @sdbm['x' * 100] = 'y' * 100)
assert_equals('y' * 100, @sdbm['x' * 100])
assert_equal('y' * 100, @sdbm['x' * 100] = 'y' * 100)
assert_equal('y' * 100, @sdbm['x' * 100])
num += 1 if i == 0
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
}
end
def test_index
assert_equals('bar', @sdbm['foo'] = 'bar')
assert_equals('foo', @sdbm.index('bar'))
assert_equal('bar', @sdbm['foo'] = 'bar')
assert_equal('foo', @sdbm.index('bar'))
assert_nil(@sdbm['bar'])
end
def test_indexes
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
assert_equals(values.reverse, @sdbm.indexes(*keys.reverse))
end
def test_values_at
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
assert_equals(values.reverse, @sdbm.values_at(*keys.reverse))
assert_equal(values.reverse, @sdbm.values_at(*keys.reverse))
end
def test_select_with_block
@ -231,37 +203,37 @@ class TestSDBM < RUNIT::TestCase
values = %w(FOO BAR BAZ)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
ret = @sdbm.select {|k,v|
assert_equals(k.upcase, v)
assert_equal(k.upcase, v)
k != "bar"
}
assert_equals([['baz', 'BAZ'], ['foo', 'FOO']],
assert_equal([['baz', 'BAZ'], ['foo', 'FOO']],
ret.sort)
end
def test_length
num = 10
assert_equals(0, @sdbm.size)
assert_equal(0, @sdbm.size)
num.times {|i|
i = i.to_s
@sdbm[i] = i
}
assert_equals(num, @sdbm.size)
assert_equal(num, @sdbm.size)
@sdbm.shift
assert_equals(num - 1, @sdbm.size)
assert_equal(num - 1, @sdbm.size)
end
def test_empty?
assert_equals(true, @sdbm.empty?)
assert_equal(true, @sdbm.empty?)
@sdbm['foo'] = 'FOO'
assert_equals(false, @sdbm.empty?)
assert_equal(false, @sdbm.empty?)
end
def test_each_pair
n = 0
@sdbm.each_pair { n += 1 }
assert_equals(0, n)
assert_equal(0, n)
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@ -271,18 +243,18 @@ class TestSDBM < RUNIT::TestCase
n = 0
ret = @sdbm.each_pair {|key, val|
assert_not_nil(i = keys.index(key))
assert_equals(val, values[i])
assert_equal(val, values[i])
n += 1
}
assert_equals(keys.size, n)
assert_equals(@sdbm, ret)
assert_equal(keys.size, n)
assert_equal(@sdbm, ret)
end
def test_each_value
n = 0
@sdbm.each_value { n += 1 }
assert_equals(0, n)
assert_equal(0, n)
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@ -293,18 +265,18 @@ class TestSDBM < RUNIT::TestCase
ret = @sdbm.each_value {|val|
assert_not_nil(key = @sdbm.index(val))
assert_not_nil(i = keys.index(key))
assert_equals(val, values[i])
assert_equal(val, values[i])
n += 1
}
assert_equals(keys.size, n)
assert_equals(@sdbm, ret)
assert_equal(keys.size, n)
assert_equal(@sdbm, ret)
end
def test_each_key
n = 0
@sdbm.each_key { n += 1 }
assert_equals(0, n)
assert_equal(0, n)
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@ -314,24 +286,24 @@ class TestSDBM < RUNIT::TestCase
n = 0
ret = @sdbm.each_key {|key|
assert_not_nil(i = keys.index(key))
assert_equals(@sdbm[key], values[i])
assert_equal(@sdbm[key], values[i])
n += 1
}
assert_equals(keys.size, n)
assert_equals(@sdbm, ret)
assert_equal(keys.size, n)
assert_equal(@sdbm, ret)
end
def test_keys
assert_equals([], @sdbm.keys)
assert_equal([], @sdbm.keys)
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
assert_equals(keys.sort, @sdbm.keys.sort)
assert_equals(values.sort, @sdbm.values.sort)
assert_equal(keys.sort, @sdbm.keys.sort)
assert_equal(values.sort, @sdbm.values.sort)
end
def test_values
@ -340,7 +312,7 @@ class TestSDBM < RUNIT::TestCase
def test_shift
assert_nil(@sdbm.shift)
assert_equals(0, @sdbm.size)
assert_equal(0, @sdbm.size)
keys = %w(foo bar baz)
values = %w(FOO BAR BAZ)
@ -353,11 +325,11 @@ class TestSDBM < RUNIT::TestCase
ret_keys.push ret[0]
ret_values.push ret[1]
assert_equals(keys.size - ret_keys.size, @sdbm.size)
assert_equal(keys.size - ret_keys.size, @sdbm.size)
end
assert_equals(keys.sort, ret_keys.sort)
assert_equals(values.sort, ret_values.sort)
assert_equal(keys.sort, ret_keys.sort)
assert_equal(values.sort, ret_values.sort)
end
def test_delete
@ -366,28 +338,28 @@ class TestSDBM < RUNIT::TestCase
key = keys[1]
assert_nil(@sdbm.delete(key))
assert_equals(0, @sdbm.size)
assert_equal(0, @sdbm.size)
@sdbm[keys[0]], @sdbm[keys[1]], @sdbm[keys[2]] = values
assert_equals('BAR', @sdbm.delete(key))
assert_equal('BAR', @sdbm.delete(key))
assert_nil(@sdbm[key])
assert_equals(2, @sdbm.size)
assert_equal(2, @sdbm.size)
assert_nil(@sdbm.delete(key))
end
def test_delete_with_block
key = 'no called block'
@sdbm[key] = 'foo'
assert_equals('foo', @sdbm.delete(key) {|k| k.replace 'called block'})
assert_equals('no called block', key)
assert_equals(0, @sdbm.size)
assert_equal('foo', @sdbm.delete(key) {|k| k.replace 'called block'})
assert_equal('no called block', key)
assert_equal(0, @sdbm.size)
key = 'no called block'
assert_equals(:blockval,
assert_equal(:blockval,
@sdbm.delete(key) {|k| k.replace 'called block'; :blockval})
assert_equals('called block', key)
assert_equals(0, @sdbm.size)
assert_equal('called block', key)
assert_equal(0, @sdbm.size)
end
def test_delete_if
@ -395,11 +367,11 @@ class TestSDBM < RUNIT::TestCase
100.times {@sdbm[v] = v; v = v.next}
ret = @sdbm.delete_if {|key, val| key.to_i < 50}
assert_equals(@sdbm, ret)
assert_equal(@sdbm, ret)
check_size(50, @sdbm)
ret = @sdbm.delete_if {|key, val| key.to_i >= 50}
assert_equals(@sdbm, ret)
assert_equal(@sdbm, ret)
check_size(0, @sdbm)
# break
@ -412,7 +384,7 @@ class TestSDBM < RUNIT::TestCase
n+=1
true
}
assert_equals(51, n)
assert_equal(51, n)
check_size(49, @sdbm)
@sdbm.clear
@ -430,7 +402,7 @@ class TestSDBM < RUNIT::TestCase
}
rescue
end
assert_equals(51, n)
assert_equal(51, n)
check_size(49, @sdbm)
end
@ -440,30 +412,30 @@ class TestSDBM < RUNIT::TestCase
hash = @sdbm.reject {|key, val| key.to_i < 50}
assert_instance_of(Hash, hash)
assert_equals(100, @sdbm.size)
assert_equal(100, @sdbm.size)
assert_equals(50, hash.size)
assert_equal(50, hash.size)
hash.each_pair {|key,val|
assert_equals(false, key.to_i < 50)
assert_equals(key, val)
assert_equal(false, key.to_i < 50)
assert_equal(key, val)
}
hash = @sdbm.reject {|key, val| key.to_i < 100}
assert_instance_of(Hash, hash)
assert_equals(true, hash.empty?)
assert_equal(true, hash.empty?)
end
def test_clear
v = "1"
100.times {v = v.next; @sdbm[v] = v}
assert_equals(@sdbm, @sdbm.clear)
assert_equal(@sdbm, @sdbm.clear)
# validate SDBM#size
i = 0
@sdbm.each { i += 1 }
assert_equals(@sdbm.size, i)
assert_equals(0, i)
assert_equal(@sdbm.size, i)
assert_equal(0, i)
end
def test_invert
@ -472,9 +444,9 @@ class TestSDBM < RUNIT::TestCase
hash = @sdbm.invert
assert_instance_of(Hash, hash)
assert_equals(100, hash.size)
assert_equal(100, hash.size)
hash.each_pair {|key, val|
assert_equals(key.to_i, val.to_i)
assert_equal(key.to_i, val.to_i)
}
end
@ -485,9 +457,9 @@ class TestSDBM < RUNIT::TestCase
@sdbm["101"] = "101"
@sdbm.update hash
assert_equals(101, @sdbm.size)
assert_equal(101, @sdbm.size)
@sdbm.each_pair {|key, val|
assert_equals(key.to_i, val.to_i)
assert_equal(key.to_i, val.to_i)
}
end
@ -498,22 +470,22 @@ class TestSDBM < RUNIT::TestCase
@sdbm["101"] = "101"
@sdbm.replace hash
assert_equals(100, @sdbm.size)
assert_equal(100, @sdbm.size)
@sdbm.each_pair {|key, val|
assert_equals(key.to_i, val.to_i)
assert_equal(key.to_i, val.to_i)
}
end
def test_haskey?
assert_equals('bar', @sdbm['foo']='bar')
assert_equals(true, @sdbm.has_key?('foo'))
assert_equals(false, @sdbm.has_key?('bar'))
assert_equal('bar', @sdbm['foo']='bar')
assert_equal(true, @sdbm.has_key?('foo'))
assert_equal(false, @sdbm.has_key?('bar'))
end
def test_has_value?
assert_equals('bar', @sdbm['foo']='bar')
assert_equals(true, @sdbm.has_value?('bar'))
assert_equals(false, @sdbm.has_value?('foo'))
assert_equal('bar', @sdbm['foo']='bar')
assert_equal(true, @sdbm.has_value?('bar'))
assert_equal(false, @sdbm.has_value?('foo'))
end
def test_to_a
@ -522,9 +494,9 @@ class TestSDBM < RUNIT::TestCase
ary = @sdbm.to_a
assert_instance_of(Array, ary)
assert_equals(100, ary.size)
assert_equal(100, ary.size)
ary.each {|key,val|
assert_equals(key.to_i, val.to_i)
assert_equal(key.to_i, val.to_i)
}
end
@ -534,23 +506,10 @@ class TestSDBM < RUNIT::TestCase
hash = @sdbm.to_hash
assert_instance_of(Hash, hash)
assert_equals(100, hash.size)
assert_equal(100, hash.size)
hash.each {|key,val|
assert_equals(key.to_i, val.to_i)
assert_equal(key.to_i, val.to_i)
}
end
end
if $0 == __FILE__
if ARGV.size == 0
suite = RUNIT::TestSuite.new
suite.add_test(TestSDBM.suite)
else
suite = RUNIT::TestSuite.new
ARGV.each do |testmethod|
suite.add_test(TestSDBM.new(testmethod))
end
end
RUNIT::CUI::TestRunner.run(suite)
end