Class: TestKyaniteDictionary
- Defined in
 - test/test_dictionary.rb
 
Dictionary Additions
- Kyanite definitions
 - Kyanite tests and examples
 - Base class
 - 
Hashery::Dictionary (A Dictionary is a Hash that preserves order.)
 - Usage
 - 
require 'kyanite/dictionary'
 
Instance Method Summary (collapse)
- - (Object) test_create
 - - (Object) test_each
 - - (Object) test_insert
 - - (Object) test_is_collection
 - - (Object) test_merge
 - - (Object) test_op_store
 - - (Object) test_order_by
 - - (Object) test_push
 - - (Object) test_to_dictionary
 - - (Object) test_update
 
Instance Method Details
- (Object) test_create
      49 50 51 52  | 
    
      # File 'test/test_dictionary.rb', line 49 def test_create hsh = Dictionary['z', 1, 'a', 2, 'c', 3] assert_equal( ['z','a','c'], hsh.keys ) end  | 
  
- (Object) test_each
      33 34 35 36 37 38 39 40 41 42 43 44 45 46  | 
    
      # File 'test/test_dictionary.rb', line 33 def test_each test = Dictionary[ 'a', 1, 'b', 2, 'c', 3 ] test.each do | k, v| assert_equal String, k.class assert_equal Fixnum, v.class end test.each_with_index do | k, v, i| assert_equal String, k.class assert_equal Fixnum, v.class assert_equal Fixnum, i.class end end  | 
  
- (Object) test_insert
      79 80 81 82 83 84 85 86 87 88 89 90  | 
    
      # File 'test/test_dictionary.rb', line 79 def test_insert # front h = Dictionary['a', 1, 'b', 2, 'c', 3] r = Dictionary['d', 4, 'a', 1, 'b', 2, 'c', 3] assert_equal( 4, h.insert(0,'d',4) ) assert_equal( r, h ) # back h = Dictionary['a', 1, 'b', 2, 'c', 3] r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4] assert_equal( 4, h.insert(-1,'d',4) ) assert_equal( r, h ) end  | 
  
- (Object) test_is_collection
      14 15 16  | 
    
      # File 'test/test_dictionary.rb', line 14 def test_is_collection assert Dictionary[1,2,3,4].is_collection? end  | 
  
- (Object) test_merge
      109 110 111 112 113 114 115 116 117 118 119 120  | 
    
      # File 'test/test_dictionary.rb', line 109 def test_merge # with other orderred hash h1 = Dictionary['a', 1, 'b', 2, 'c', 3] h2 = Dictionary['d', 4] r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4] assert_equal( r, h1.merge(h2) ) # with other hash h1 = Dictionary['a', 1, 'b', 2, 'c', 3] h2 = { 'd' => 4 } r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4] assert_equal( r, h1.merge(h2) ) end  | 
  
- (Object) test_op_store
      55 56 57 58 59 60 61  | 
    
      # File 'test/test_dictionary.rb', line 55 def test_op_store hsh = Dictionary.new hsh['z'] = 1 hsh['a'] = 2 hsh['c'] = 3 assert_equal( ['z','a','c'], hsh.keys ) end  | 
  
- (Object) test_order_by
      123 124 125 126 127 128  | 
    
      # File 'test/test_dictionary.rb', line 123 def test_order_by h1 = Dictionary['a', 3, 'b', 2, 'c', 1] h1.order_by{ |k,v| v } assert_equal( [1,2,3], h1.values ) assert_equal( ['c','b','a'], h1.keys ) end  | 
  
- (Object) test_push
      64 65 66 67 68 69 70 71 72 73 74 75 76  | 
    
      # File 'test/test_dictionary.rb', line 64 def test_push hsh = Dictionary['a', 1, 'c', 2, 'z', 3] assert( hsh.push('end', 15) ) assert_equal( 15, hsh['end'] ) assert( ! hsh.push('end', 30) ) assert( hsh.unshift('begin', 50) ) assert_equal( 50, hsh['begin'] ) assert( ! hsh.unshift('begin', 60) ) assert_equal( ["begin", "a", "c", "z", "end"], hsh.keys ) assert_equal( ["end", 15], hsh.pop ) assert_equal( ["begin", "a", "c", "z"], hsh.keys ) assert_equal( ["begin", 50], hsh.shift ) end  | 
  
- (Object) test_to_dictionary
      19 20 21 22 23 24 25 26 27 28  | 
    
      # File 'test/test_dictionary.rb', line 19 def test_to_dictionary test = { :a => 1, :b => 2, :c => 3 } dict = test.to_dictionary assert_equal 3, dict.size assert_equal 1, dict[:a] assert_equal 2, dict[:b] assert_equal 3, dict[:c] end  | 
  
- (Object) test_update
      93 94 95 96 97 98 99 100 101 102 103 104 105 106  | 
    
      # File 'test/test_dictionary.rb', line 93 def test_update # with other orderred hash h1 = Dictionary['a', 1, 'b', 2, 'c', 3] h2 = Dictionary['d', 4] r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4] assert_equal( r, h1.update(h2) ) assert_equal( r, h1 ) # with other hash h1 = Dictionary['a', 1, 'b', 2, 'c', 3] h2 = { 'd' => 4 } r = Dictionary['a', 1, 'b', 2, 'c', 3, 'd', 4] assert_equal( r, h1.update(h2) ) assert_equal( r, h1 ) end  |