source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-objectspace/test/objectspace.rb@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 1.5 KB
Line 
1assert('ObjectSpace.count_objects') do
2 h = {}
3 f = Fiber.new {} if Object.const_defined? :Fiber
4 ObjectSpace.count_objects(h)
5 assert_kind_of(Hash, h)
6 assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
7 assert_true(h.values.all? {|x| x.is_a?(Integer) })
8
9 assert_true(h.has_key?(:TOTAL))
10 assert_true(h.has_key?(:FREE))
11 assert_true(h.has_key?(:T_FIBER)) if Object.const_defined? :Fiber
12
13 assert_equal(h[:TOTAL] * 2, h.values.reduce(:+))
14
15 h = ObjectSpace.count_objects
16 assert_kind_of(Hash, h)
17 assert_true(h.keys.all? {|x| x.is_a?(Symbol) || x.is_a?(Integer) })
18 assert_true(h.values.all? {|x| x.is_a?(Integer) })
19
20 assert_raise(TypeError) { ObjectSpace.count_objects(1) }
21
22 h0 = {:T_FOO=>1000}
23 h = ObjectSpace.count_objects(h0)
24 assert_false(h0.has_key?(:T_FOO))
25
26 GC.start
27 h_after = {}
28 h_before = ObjectSpace.count_objects
29
30 objs = []
31 1000.times do
32 objs << {}
33 end
34 objs = nil
35 ObjectSpace.count_objects(h)
36 GC.start
37 ObjectSpace.count_objects(h_after)
38
39 assert_equal(h[:T_HASH], h_before[:T_HASH] + 1000)
40 assert_equal(h_after[:T_HASH], h_before[:T_HASH])
41end
42
43assert('ObjectSpace.each_object') do
44 objs = []
45 objs_count = ObjectSpace.each_object { |obj|
46 objs << obj
47 }
48 assert_equal objs.length, objs_count
49
50 arys = []
51 arys_count = ObjectSpace.each_object(Array) { |obj|
52 arys << obj
53 }
54 assert_equal arys.length, arys_count
55 assert_true arys.length < objs.length
56end
57
58assert 'Check class pointer of ObjectSpace.each_object.' do
59 ObjectSpace.each_object { |obj| !obj }
60end
Note: See TracBrowser for help on using the repository browser.