summaryrefslogtreecommitdiff
path: root/test/rinda/test_tuplebag.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-27 22:52:21 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-08-27 22:52:21 +0000
commit92b0eb1f42352ccb0ef64c294427a0c7308f9c08 (patch)
tree9da5430008a9571c97d7cb03821021a723d9c6ea /test/rinda/test_tuplebag.rb
parentddec6278cbb19bd1b603dd55c4e17d7383a9916c (diff)
More comprehensive tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10787 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/rinda/test_tuplebag.rb')
-rw-r--r--test/rinda/test_tuplebag.rb68
1 files changed, 45 insertions, 23 deletions
diff --git a/test/rinda/test_tuplebag.rb b/test/rinda/test_tuplebag.rb
index afe32b4dee..eccf372125 100644
--- a/test/rinda/test_tuplebag.rb
+++ b/test/rinda/test_tuplebag.rb
@@ -1,10 +1,6 @@
require 'test/unit'
require 'rinda/tuplespace'
-class Rinda::TupleBag
- attr_reader :hash
-end
-
class TestTupleBag < Test::Unit::TestCase
def setup
@@ -23,6 +19,19 @@ class TestTupleBag < Test::Unit::TestCase
val = @tb.delete t
assert_equal t, val
+
+ assert_equal [], @tb.find_all(tem(:val, 1))
+
+ t1 = tup(:val, 1)
+ t2 = tup(:val, 1)
+ @tb.push t1
+ @tb.push t2
+
+ val = @tb.delete t1
+
+ assert_equal t1, val
+
+ assert_equal [t2], @tb.find_all(tem(:val, 1))
end
def test_delete_unless_alive
@@ -50,19 +59,26 @@ class TestTupleBag < Test::Unit::TestCase
assert_equal nil, @tb.find(template)
- t1 = tup(:val, 1)
- t2 = tup(:val, 2)
-
+ t1 = tup(:other, 1)
@tb.push t1
+
+ assert_equal nil, @tb.find(template)
+
+ t2 = tup(:val, 1)
@tb.push t2
- assert_equal t1, @tb.find(template)
+ assert_equal t2, @tb.find(template)
- t1.cancel
+ t2.cancel
- assert_equal t2, @tb.find(template), 'canceled'
+ assert_equal nil, @tb.find(template), 'canceled'
- t2.renew Object.new
+ t3 = tup(:val, 3)
+ @tb.push t3
+
+ assert_equal t3, @tb.find(template)
+
+ t3.renew Object.new
assert_equal nil, @tb.find(template), 'expired'
end
@@ -70,21 +86,24 @@ class TestTupleBag < Test::Unit::TestCase
def test_find_all
template = tem(:val, nil)
+ t1 = tup(:other, 1)
+ @tb.push t1
+
assert_equal [], @tb.find_all(template)
- t1 = tup(:val, 1)
t2 = tup(:val, 2)
+ t3 = tup(:val, 3)
- @tb.push t1
@tb.push t2
+ @tb.push t3
- assert_equal [t1, t2], @tb.find_all(template)
+ assert_equal [t2, t3], @tb.find_all(template)
- t1.cancel
+ t2.cancel
- assert_equal [t2], @tb.find_all(template), 'canceled'
+ assert_equal [t3], @tb.find_all(template), 'canceled'
- t2.renew Object.new
+ t3.renew Object.new
assert_equal [], @tb.find_all(template), 'expired'
end
@@ -92,21 +111,24 @@ class TestTupleBag < Test::Unit::TestCase
def test_find_all_template
tuple = tup(:val, 1)
+ t1 = tem(:other, nil)
+ @tb.push t1
+
assert_equal [], @tb.find_all_template(tuple)
- t1 = tem(:val, nil)
t2 = tem(:val, nil)
+ t3 = tem(:val, nil)
- @tb.push t1
@tb.push t2
+ @tb.push t3
- assert_equal [t1, t2], @tb.find_all_template(tuple)
+ assert_equal [t2, t3], @tb.find_all_template(tuple)
- t1.cancel
+ t2.cancel
- assert_equal [t2], @tb.find_all_template(tuple), 'canceled'
+ assert_equal [t3], @tb.find_all_template(tuple), 'canceled'
- t2.renew Object.new
+ t3.renew Object.new
assert_equal [], @tb.find_all_template(tuple), 'expired'
end