Restrict assert checks to .rb files.
[ruby_koans.git] / koans / about_objects.rb
1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
2
3 class AboutObjects < EdgeCase::Koan
4   def test_everything_is_an_object
5     assert_equal __, 1.is_a?(Object)
6     assert_equal __, 1.5.is_a?(Object)
7     assert_equal __, "string".is_a?(Object)
8     assert_equal __, nil.is_a?(Object)
9     assert_equal __, Object.is_a?(Object)
10   end
11
12   def test_objects_can_be_converted_to_strings
13     assert_equal __, 123.to_s
14     assert_equal __, nil.to_s
15   end
16
17   def test_objects_can_be_inspected
18     assert_equal __, 123.inspect
19     assert_equal __, nil.inspect
20   end
21
22   def test_every_object_has_an_id
23     obj = Object.new
24     assert_equal __, obj.object_id.class
25   end
26
27   def test_every_object_has_different_id
28     obj = Object.new
29     another_obj = Object.new
30     assert_equal __, obj.object_id != another_obj.object_id
31   end
32
33   def test_some_system_objects_always_have_the_same_id
34     assert_equal __, false.object_id
35     assert_equal __, true.object_id
36     assert_equal __, nil.object_id
37   end
38
39   def test_small_integers_have_fixed_ids
40     assert_equal __, 0.object_id
41     assert_equal __, 1.object_id
42     assert_equal __, 2.object_id
43     assert_equal __, 100.object_id
44
45     # THINK ABOUT IT:
46     # What pattern do the object IDs for small integers follow?
47   end
48
49   def test_clone_creates_a_different_object
50     obj = Object.new
51     copy = obj.clone
52
53     assert_equal __, obj           != copy
54     assert_equal __, obj.object_id != copy.object_id
55   end
56 end