Class: TestKyaniteHash

Inherits
UnitTest
  • Object
show all
Defined in
test/test_hash.rb

Hash Additions

Kyanite definitions

Dictionary, Hash

Kyanite tests and examples

TestKyaniteHash

Usage

require 'kyanite/hash'

Instance Method Summary (collapse)

Instance Method Details

- (Object) test_compact



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'test/test_hash.rb', line 27

def test_compact
  dirty_hash = ({     :a => 1, 
                      :b => nil, 
                      :c => nil, 
                      :d => '', 
                      nil => 3    })
                     
            
  assert_equal 5, dirty_hash.size
  assert_equal 4, dirty_hash.dup.compact_keys!.size    
  assert_equal 3, dirty_hash.dup.compact_values!.size        
  
  dirty_hash.compact_keys!
  assert_equal 4, dirty_hash.size      
  
  dirty_hash.compact_values!
  assert_equal 2, dirty_hash.size   
end

- (Object) test_delete

Rubys delete verändert den Hash!



15
16
17
18
19
20
21
22
23
24
# File 'test/test_hash.rb', line 15

def test_delete
  h = {}
  assert_equal ({}),            h
  
  h[1] = 10
  assert_equal ({ 1 => 10 }),   h    

  assert_equal 10,              h.delete(1)
  assert_equal ({}),            h
end

- (Object) test_slice



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'test/test_hash.rb', line 47

def test_slice
  dirty_hash = ({     :a => 1, 
                      :b => nil, 
                      :c => nil, 
                      :d => ''  })  
                      
  sliced = dirty_hash.slice(:b, :c)
  assert ! sliced.has_key?(:a)
  assert   sliced.has_key?(:b)
  assert   sliced.has_key?(:c)
  assert ! sliced.has_key?(:d)
  
end