- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabout_objects.rb
More file actions
Latest commit
56 lines (46 loc) · 1.45 KB
/
Copy pathabout_objects.rb
File metadata and controls
56 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
requireFile.expand_path(File.dirname(__FILE__) + '/edgecase')
classAboutObjects < EdgeCase::Koan
deftest_everything_is_an_object
assert_equaltrue,1.is_a?(Object)
assert_equaltrue,1.5.is_a?(Object)
assert_equaltrue,"string".is_a?(Object)
assert_equaltrue,nil.is_a?(Object)
assert_equaltrue,Object.is_a?(Object)
end
deftest_objects_can_be_converted_to_strings
assert_equal'123',123.to_s
assert_equal'',nil.to_s
end
deftest_objects_can_be_inspected
assert_equal'123',123.inspect
assert_equal'nil',nil.inspect
end
deftest_every_object_has_an_id
obj=Object.new
assert_equalFixnum,obj.object_id.class
end
deftest_every_object_has_different_id
obj=Object.new
another_obj=Object.new
assert_equaltrue,obj.object_id != another_obj.object_id
end
deftest_some_system_objects_always_have_the_same_id
assert_equal0,false.object_id
assert_equal2,true.object_id
assert_equal4,nil.object_id
end
deftest_small_integers_have_fixed_ids
assert_equal1,0.object_id
assert_equal3,1.object_id
assert_equal5,2.object_id
assert_equal201,100.object_id
# THINK ABOUT IT:
# What pattern do the object IDs for small integers follow?
end
deftest_clone_creates_a_different_object
obj=Object.new
copy=obj.clone
assert_equaltrue,obj != copy
assert_equaltrue,obj.object_id != copy.object_id
end
end