Class OHashTest
In: lib/o_hash.rb
Parent: Test::Unit::TestCase

Methods

Public Instance methods

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# File lib/o_hash.rb, line 233
    def test_ordered
      check_ordered(OHash.new, [[4, 3], [2, 3]])
    end

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# File lib/o_hash.rb, line 237
    def test_unorderd
      check_ordered(Hash.new, [[2, 3], [4, 3]])
    end

[Source]

# File lib/o_hash.rb, line 265
    def test_unorderd_empty
      check_ordered({}, [[2, 3], [4, 3]])
    end

[Source]

# File lib/o_hash.rb, line 305
    def test_yaml_dump ( anObject, ref, options={} )
    end

[Source]

# File lib/o_hash.rb, line 302
    def test_yaml_load ( aString, aClass, anObject=nil )
    end

[Validate]