1- $: << File . join ( File . expand_path ( File . dirname ( __FILE__ ) ) , '..' , 'lib' )
2- require 'algorithms'
3-
4- if defined? Containers ::CBst
5- describe "CBst" do
6- it "should mark ruby object references" do
7- anon_key_class = Class . new do
8- attr :value
9- def initialize ( x ) ; @value = x ; end
10- def <=>( other ) ; value <=> other . value ; end
11- end
12- anon_val_class = Class . new
13- @bst = Containers ::CBst . new
14- 100 . times { |x | @bst . push ( anon_key_class . new ( x ) , anon_val_class . new ) }
15- # Mark and sweep
16- ObjectSpace . garbage_collect
17- # Check if any instances were swept
18- count = 0
19- ObjectSpace . each_object ( anon_key_class ) { |x | count += 1 }
20- count . should eql ( 100 )
21- ObjectSpace . each_object ( anon_val_class ) { |x | count += 1 }
22- count . should eql ( 200 )
23- end
24- end
25- end
1+ # $: << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
2+ # require 'algorithms'
3+ #
4+ # if defined? Containers::CBst
5+ # describe "CBst" do
6+ # it "should mark ruby object references" do
7+ # anon_key_class = Class.new do
8+ # attr :value
9+ # def initialize(x); @value = x; end
10+ # def <=>(other); value <=> other.value; end
11+ # end
12+ # anon_val_class = Class.new
13+ # @bst = Containers::CBst.new
14+ # 100.times { |x| @bst.push(anon_key_class.new(x), anon_val_class.new) }
15+ # # Mark and sweep
16+ # ObjectSpace.garbage_collect
17+ # # Check if any instances were swept
18+ # count = 0
19+ # ObjectSpace.each_object(anon_key_class) { |x| count += 1 }
20+ # count.should eql(100)
21+ # ObjectSpace.each_object(anon_val_class) { |x| count += 1 }
22+ # count.should eql(200)
23+ # end
24+ # end
25+ # end
0 commit comments