1 require File.expand_path(File.dirname(__FILE__) + '/edgecase')
3 class AboutHashes < EdgeCase::Koan
4 def test_creating_hashes
6 assert_equal __, empty_hash.class
7 assert_equal({}, empty_hash)
8 assert_equal __, empty_hash.size
11 def test_hash_literals
12 hash = { :one => "uno", :two => "dos" }
13 assert_equal __, hash.size
16 def test_accessing_hashes
17 hash = { :one => "uno", :two => "dos" }
18 assert_equal __, hash[:one]
19 assert_equal __, hash[:two]
20 assert_equal __, hash[:doesnt_exist]
23 def test_changing_hashes
24 hash = { :one => "uno", :two => "dos" }
27 expected = { :one => __, :two => "dos" }
28 assert_equal __, expected == hash
30 # Bonus Question: Why was "expected" broken out into a variable
31 # rather than used as a literal?
34 def test_hash_is_unordered
35 hash1 = { :one => "uno", :two => "dos" }
36 hash2 = { :two => "dos", :one => "uno" }
38 assert_equal __, hash1 == hash2
42 hash = { :one => "uno", :two => "dos" }
43 assert_equal __, hash.keys.size
44 assert_equal __, hash.keys.include?(:one)
45 assert_equal __, hash.keys.include?(:two)
46 assert_equal __, hash.keys.class
50 hash = { :one => "uno", :two => "dos" }
51 assert_equal __, hash.values.size
52 assert_equal __, hash.values.include?("uno")
53 assert_equal __, hash.values.include?("dos")
54 assert_equal __, hash.values.class
57 def test_combining_hashes
58 hash = { "jim" => 53, "amy" => 20, "dan" => 23 }
59 new_hash = hash.merge({ "jim" => 54, "jenny" => 26 })
61 assert_equal __, hash != new_hash
63 expected = { "jim" => __, "amy" => 20, "dan" => 23, "jenny" => __ }
64 assert_equal __, expected == new_hash