ext/Yk/test_set.rb in YkESet-0.99.7 vs ext/Yk/test_set.rb in YkESet-0.99.9
- old
+ new
@@ -9,10 +9,72 @@
end
#require 'tz/debug2' rescue nil
include Yk
+
+class Foo
+ attr :f
+ def initialize f
+ @f = f
+ end
+end
+
+s = ESet.new do |o|
+ o.f
+end
+
+s.add Foo.new(rand)
+s.add Foo.new(rand)
+s.add Foo.new(rand)
+s.add Foo.new(rand)
+
+y = rand
+result = s.add Foo.new(y)
+p result # true
+result = s.add Foo.new(y)
+p result # false
+
+ESet.for_each s.begin, s.end do |foo|
+ p foo.f
+end
+
+# use Iterator object
+
+it, result = s.insert Foo.new(y = rand)
+p result # true
+it, result = s.insert Foo.new(y)
+p result # false
+
+s.erase it
+p it.erased? # true
+begin
+ s.erase it #
+rescue ArgumentError
+ p $!
+end
+
+it = s.begin
+while !it.end?
+ p it.item
+ it.inc
+end
+
+begin
+ it.item # already reached the end
+rescue RangeError
+ p $!
+end
+
+jt = it
+it.dec
+p it == jt #true
+jt = it.clone
+jt.dec
+p it != jt #true
+
+
class Item
attr :time, :f, :cnt
@@cnt = 0
def initialize f
@cnt = @@cnt
@@ -47,21 +109,26 @@
bi = s.insert Item.new(r)
p ai
p bi
p s.size
toErase = bi[0]
- found = ESet.find(toErase.item)
+ found = s.find(toErase.item)
+ p found == s.end
p found.item
+ found = s.find(Item.new(1))
+ p found == s.end
ESet.for_each s.begin, s.end do |o|
p [o]
end
s.erase toErase
p s.size
p toErase.item
- toErase.inc
- p toErase.item
- toErase.dec
+ begin
+ toErase.inc
+ rescue => exception
+ p $!
+ end
p toErase.item
p s.size
ESet.for_each s.begin, s.end do |o|
p [o]
end