1 # -*- encoding: binary -*-
5 class TestRaindrops < Test::Unit::TestCase
7 def test_raindrop_counter_max
8 assert_kind_of Integer, Raindrops::MAX
9 assert Raindrops::MAX > 0
10 printf "Raindrops::MAX = 0x%x\n", Raindrops::MAX
13 def test_raindrop_size
14 assert_kind_of Integer, Raindrops::SIZE
15 assert Raindrops::SIZE > 0
16 puts "Raindrops::SIZE = #{Raindrops::SIZE}"
21 assert_equal 4, rd.size
26 assert_equal [0, 0, 0, 0] , rd.to_ary
31 assert_equal 1, rd.incr(0)
32 assert_equal [1, 0, 0, 0], rd.to_ary
37 assert_equal 6, rd.incr(3, 6)
38 assert_equal [0, 0, 0, 6], rd.to_ary
44 assert_equal 5, rd.decr(3, 1)
45 assert_equal [0, 0, 0, 5], rd.to_ary
51 pid = fork { rd.incr(1) }
52 _, status = Process.waitpid2(pid)
53 assert status.success?
55 assert_equal [0, 5], rd.to_ary
60 fork { 1000000.times { rd.incr(0) } }
61 1000.times { rd.decr(0) }
62 statuses = Process.waitall
63 statuses.each { |pid, status| assert status.success? }
64 assert_equal [999000], rd.to_ary
69 assert_raises(ArgumentError) { rd.incr(-1) }
70 assert_raises(ArgumentError) { rd.incr(2) }
71 assert_raises(ArgumentError) { rd.incr(0xffffffff) }
75 @rd = Raindrops.new(1)
77 assert_equal 1, @rd.incr(0)
78 assert_equal 1, rd.incr(0)
79 assert_equal 2, rd.incr(0)
81 assert_equal 1, @rd[0]
85 @rd = Raindrops.new(1)
87 assert_equal 1, @rd.incr(0)
88 assert_equal 1, rd.incr(0)
89 assert_equal 2, rd.incr(0)
91 assert_equal 1, @rd[0]
95 expect = (1..256).map { 0 }
96 rd = Raindrops.new(256)
97 assert_equal expect, rd.to_ary
98 assert_nothing_raised { rd[255] = 5 }
99 assert_equal 5, rd[255]
100 assert_nothing_raised { rd[2] = 2 }
104 assert_equal expect, rd.to_ary