| Class | OHashTest |
| In: |
lib/o_hash.rb
|
| Parent: | Test::Unit::TestCase |
# File lib/o_hash.rb, line 227 def check_ordered ( h, ref ) h.store(4,3) h.store(2,3) assert_equal(h.to_a, ref) end
# File lib/o_hash.rb, line 288 def test_big_ordered a = (0..501).to_a h = OHash[*a] assert_equal(h.to_s, a.to_s) end
# File lib/o_hash.rb, line 258 def test_dont_preserve # but this don't preserve order hsh = OHash['z'=>1, 'a'=>2, 'c'=>3] hsh2 = OHash['a'=>2, 'z'=>1, 'c'=>3] assert_equal(hsh, hsh2) end
# File lib/o_hash.rb, line 294 def test_eql assert_nothing_raised { OHash.new == {} } assert_not_equal OHash.new, {} assert_equal OHash.new, OHash.new assert_equal OHash[1,2,3,4], OHash[1,2,3,4] assert_not_equal OHash[1,2,3,4], OHash[3,4,1,2] end
# File lib/o_hash.rb, line 269 def test_inspect hsh = OHash['z', 1, 'a', 2, 'c', 3] hsh2 = OHash['a', 2, 'z', 1, 'c', 3] assert_equal('{(ordered) "z"=>1, "a"=>2, "c"=>3 }', hsh.inspect) assert_equal('{(ordered) "a"=>2, "z"=>1, "c"=>3 }', hsh2.inspect) end
# File lib/o_hash.rb, line 282 def test_little_ordered a = (0..11).to_a h = OHash[*a] assert_equal(h.to_s, a.to_s) end
# File lib/o_hash.rb, line 250 def test_preserve # or using OHash[] method hsh = OHash['z', 1, 'a', 2, 'c', 3] hsh2 = OHash['a', 2, 'z', 1, 'c', 3] assert_equal(hsh.keys, ['z','a','c']) assert_not_equal(hsh, hsh2) end
# File lib/o_hash.rb, line 276 def test_pretty_print require 'pp' hsh = OHash['z', 1, 'a', 2, 'c', 3] assert_match(/^\{\(ordered\) /, PP.pp(hsh, '')) end
# File lib/o_hash.rb, line 241 def test_simply # You can do simply hsh = OHash.new hsh['z'] = 1 hsh['a'] = 2 hsh['c'] = 3 assert_equal(hsh.keys, ['z','a','c']) end