зеркало из https://github.com/github/ruby.git
check hash tuple size
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6193 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
317547dc5d
Коммит
fb3c76a225
|
@ -1,3 +1,7 @@
|
|||
Wed Apr 21 23:04:42 2004 Masatoshi SEKI <m_seki@mva.biglobe.ne.jp>
|
||||
|
||||
* lib/rinda/rinda.rb, test/rinda/test_rinda.rb: check Hash tuple size.
|
||||
|
||||
Wed Apr 21 20:05:00 2004 Tanaka Akira <akr@m17n.org>
|
||||
|
||||
* lib/open-uri.rb (URI::HTTP#proxy_open): set Host: field explicitly.
|
||||
|
|
|
@ -69,18 +69,15 @@ module Rinda
|
|||
|
||||
private
|
||||
def init_with_ary(ary)
|
||||
@tuple_size = ary.size
|
||||
@tuple = Array.new(@tuple_size)
|
||||
@tuple = Array.new(ary.size)
|
||||
@tuple.size.times do |i|
|
||||
@tuple[i] = ary[i]
|
||||
end
|
||||
end
|
||||
|
||||
def init_with_hash(hash)
|
||||
@tuple_size = hash[:size]
|
||||
@tuple = Hash.new
|
||||
hash.each do |k, v|
|
||||
next if k == :size
|
||||
raise InvalidHashTupleKey unless String === k
|
||||
@tuple[k] = v
|
||||
end
|
||||
|
@ -97,7 +94,7 @@ module Rinda
|
|||
def match(tuple)
|
||||
return false unless tuple.respond_to?(:size)
|
||||
return false unless tuple.respond_to?(:fetch)
|
||||
return false if @tuple_size && (@tuple_size != tuple.size)
|
||||
return false unless self.size == tuple.size
|
||||
each do |k, v|
|
||||
begin
|
||||
it = tuple.fetch(k)
|
||||
|
|
|
@ -20,13 +20,13 @@ module TupleSpaceTestModule
|
|||
assert_equal(3, tmpl[2])
|
||||
assert(tmpl.match([1,2,3]))
|
||||
assert(!tmpl.match([1,nil,3]))
|
||||
|
||||
|
||||
tmpl = Rinda::Template.new([/^rinda/i, nil, :hello])
|
||||
assert_equal(3, tmpl.size)
|
||||
assert(tmpl.match(['Rinda', 2, :hello]))
|
||||
assert(!tmpl.match(['Rinda', 2, Symbol]))
|
||||
assert(!tmpl.match([1, 2, :hello]))
|
||||
assert(tmpl.match([/^rinda/i, nil, :hello]))
|
||||
assert(tmpl.match([/^rinda/i, 2, :hello]))
|
||||
|
||||
tmpl = Rinda::Template.new([Symbol])
|
||||
assert_equal(1, tmpl.size)
|
||||
|
@ -37,8 +37,8 @@ module TupleSpaceTestModule
|
|||
tmpl = Rinda::Template.new({"message"=>String, "name"=>String})
|
||||
assert_equal(2, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
assert_raises(Rinda::InvalidHashTupleKey) do
|
||||
|
@ -46,42 +46,49 @@ module TupleSpaceTestModule
|
|||
end
|
||||
tmpl = Rinda::Template.new({"name"=>String})
|
||||
assert_equal(1, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(tmpl.match({"message"=>:symbol, "name"=>"Foo", "1"=>2}))
|
||||
assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(tmpl.match({"name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>:symbol, "name"=>"Foo", "1"=>2}))
|
||||
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
tmpl = Rinda::Template.new({"message"=>String, "name"=>String, :size=>2})
|
||||
tmpl = Rinda::Template.new({"message"=>String, "name"=>String})
|
||||
assert_equal(2, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
tmpl = Rinda::Template.new({"message"=>String, :size=>2})
|
||||
tmpl = Rinda::Template.new({"message"=>String})
|
||||
assert_equal(1, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(tmpl.match({"message"=>"Hello"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
tmpl = Rinda::Template.new({"message"=>String, "name"=>nil})
|
||||
assert_equal(2, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
tmpl = Rinda::Template.new({:size=>2})
|
||||
assert_equal(0, tmpl.size)
|
||||
assert(tmpl.match({"message"=>"Hello", "name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "name"=>"Foo", "1"=>2}))
|
||||
assert(!tmpl.match({"message"=>"Hi", "name"=>"Foo", "age"=>1}))
|
||||
assert(tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
assert(!tmpl.match({"message"=>"Hello", "no_name"=>"Foo"}))
|
||||
|
||||
assert_raises(Rinda::InvalidHashTupleKey) do
|
||||
@ts.write({:message=>String, "name"=>String})
|
||||
end
|
||||
|
||||
@ts.write([1, 2, 3])
|
||||
assert_equal([1, 2, 3], @ts.take([1, 2, 3]))
|
||||
|
||||
@ts.write({'1'=>1, '2'=>2, '3'=>3})
|
||||
assert_equal({'1'=>1, '2'=>2, '3'=>3}, @ts.take({'1'=>1, '2'=>2, '3'=>3}))
|
||||
|
||||
entry = @ts.write(['1'=>1, '2'=>2, '3'=>3])
|
||||
assert_raises(Rinda::RequestExpiredError) do
|
||||
assert_equal({'1'=>1, '2'=>2, '3'=>3}, @ts.read({'1'=>1}, 0))
|
||||
end
|
||||
entry.cancel
|
||||
end
|
||||
|
||||
def test_00_DRbObject
|
||||
|
|
Загрузка…
Ссылка в новой задаче