33class AboutHashes < EdgeCase ::Koan
44 def test_creating_hashes
55 empty_hash = Hash . new
6- assert_equal __ , empty_hash . class
6+ assert_equal Hash , empty_hash . class
77 assert_equal ( { } , empty_hash )
8- assert_equal __ , empty_hash . size
8+ assert_equal 0 , empty_hash . size
99 end
1010
1111 def test_hash_literals
1212 hash = { :one => "uno" , :two => "dos" }
13- assert_equal __ , hash . size
13+ assert_equal 2 , hash . size
1414 end
1515
1616 def test_accessing_hashes
1717 hash = { :one => "uno" , :two => "dos" }
18- assert_equal __ , hash [ :one ]
19- assert_equal __ , hash [ :two ]
20- assert_equal __ , hash [ :doesnt_exist ]
18+ assert_equal 'uno' , hash [ :one ]
19+ assert_equal 'dos' , hash [ :two ]
20+ assert_equal nil , hash [ :doesnt_exist ]
2121 end
2222
2323 def test_accessing_hashes_with_fetch
2424 hash = { :one => "uno" }
25- assert_equal __ , hash . fetch ( :one )
26- assert_raise ( ___ ) do
25+ assert_equal 'uno' , hash . fetch ( :one )
26+ assert_raise ( KeyError ) do
2727 hash . fetch ( :doesnt_exist )
2828 end
2929
@@ -36,8 +36,8 @@ def test_changing_hashes
3636 hash = { :one => "uno" , :two => "dos" }
3737 hash [ :one ] = "eins"
3838
39- expected = { :one => __ , :two => "dos" }
40- assert_equal __ , expected == hash
39+ expected = { :one => 'eins' , :two => "dos" }
40+ assert_equal true , expected == hash
4141
4242 # Bonus Question: Why was "expected" broken out into a variable
4343 # rather than used as a literal?
@@ -47,47 +47,47 @@ def test_hash_is_unordered
4747 hash1 = { :one => "uno" , :two => "dos" }
4848 hash2 = { :two => "dos" , :one => "uno" }
4949
50- assert_equal __ , hash1 == hash2
50+ assert_equal true , hash1 == hash2
5151 end
5252
5353 def test_hash_keys
5454 hash = { :one => "uno" , :two => "dos" }
55- assert_equal __ , hash . keys . size
56- assert_equal __ , hash . keys . include? ( :one )
57- assert_equal __ , hash . keys . include? ( :two )
58- assert_equal __ , hash . keys . class
55+ assert_equal 2 , hash . keys . size
56+ assert_equal true , hash . keys . include? ( :one )
57+ assert_equal true , hash . keys . include? ( :two )
58+ assert_equal Array , hash . keys . class
5959 end
6060
6161 def test_hash_values
6262 hash = { :one => "uno" , :two => "dos" }
63- assert_equal __ , hash . values . size
64- assert_equal __ , hash . values . include? ( "uno" )
65- assert_equal __ , hash . values . include? ( "dos" )
66- assert_equal __ , hash . values . class
63+ assert_equal 2 , hash . values . size
64+ assert_equal true , hash . values . include? ( "uno" )
65+ assert_equal true , hash . values . include? ( "dos" )
66+ assert_equal Array , hash . values . class
6767 end
6868
6969 def test_combining_hashes
7070 hash = { "jim" => 53 , "amy" => 20 , "dan" => 23 }
7171 new_hash = hash . merge ( { "jim" => 54 , "jenny" => 26 } )
7272
73- assert_equal __ , hash != new_hash
73+ assert_equal true , hash != new_hash
7474
75- expected = { "jim" => __ , "amy" => 20 , "dan" => 23 , "jenny" => __ }
76- assert_equal __ , expected == new_hash
75+ expected = { "jim" => 54 , "amy" => 20 , "dan" => 23 , "jenny" => 26 }
76+ assert_equal true , expected == new_hash
7777 end
7878
7979 def test_default_value
8080 hash1 = Hash . new
8181 hash1 [ :one ] = 1
8282
83- assert_equal __ , hash1 [ :one ]
84- assert_equal __ , hash1 [ :two ]
83+ assert_equal 1 , hash1 [ :one ]
84+ assert_equal nil , hash1 [ :two ]
8585
8686 hash2 = Hash . new ( "dos" )
8787 hash2 [ :one ] = 1
8888
89- assert_equal __ , hash2 [ :one ]
90- assert_equal __ , hash2 [ :two ]
89+ assert_equal 1 , hash2 [ :one ]
90+ assert_equal 'dos' , hash2 [ :two ]
9191 end
9292
9393 def test_default_value_is_the_same_object
@@ -96,11 +96,11 @@ def test_default_value_is_the_same_object
9696 hash [ :one ] << "uno"
9797 hash [ :two ] << "dos"
9898
99- assert_equal __ , hash [ :one ]
100- assert_equal __ , hash [ :two ]
101- assert_equal __ , hash [ :three ]
99+ assert_equal [ 'uno' , 'dos' ] , hash [ :one ]
100+ assert_equal [ 'uno' , 'dos' ] , hash [ :two ]
101+ assert_equal [ 'uno' , 'dos' ] , hash [ :three ]
102102
103- assert_equal __ , hash [ :one ] . object_id == hash [ :two ] . object_id
103+ assert_equal true , hash [ :one ] . object_id == hash [ :two ] . object_id
104104 end
105105
106106 def test_default_value_with_block
@@ -109,8 +109,8 @@ def test_default_value_with_block
109109 hash [ :one ] << "uno"
110110 hash [ :two ] << "dos"
111111
112- assert_equal __ , hash [ :one ]
113- assert_equal __ , hash [ :two ]
114- assert_equal __ , hash [ :three ]
112+ assert_equal [ 'uno' ] , hash [ :one ]
113+ assert_equal [ 'dos' ] , hash [ :two ]
114+ assert_equal [ ] , hash [ :three ]
115115 end
116116end
0 commit comments