add fiber tests

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-05-23 15:24:55 +09:00
parent 76ddf86c72
commit aa2040fc97
+29
View File
@@ -0,0 +1,29 @@
assert('Fiber.new') {
f = Fiber.new{}
f.class == Fiber
}
assert('Fiber#resume') {
f = Fiber.new{|x| x == 2}
f.resume(2)
}
assert('Fiber.yield') {
f = Fiber.new{|x| Fiber.yield(x == 3)}
f.resume(3)
}
assert('Fiber iteration') {
f1 = Fiber.new{
[1,2,3].each{|x| Fiber.yield(x)}
}
f2 = Fiber.new{
[9,8,7].each{|x| Fiber.yield(x)}
}
a = []
3.times {
a << f1.resume
a << f2.resume
}
a == [1,9,2,8,3,7]
}