Class: TestKyaniteArray

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

Array Additions

Kyanite definitions

Array

Kyanite tests and examples

TestKyaniteArray

Usage

require 'kyanite/array'

Instance Method Summary (collapse)

Instance Method Details

- (Object) test_array_diff



72
73
74
75
76
77
78
79
80
81
# File 'test/array/test_array.rb', line 72

def test_array_diff
    a = [1,2,3,4,5, :a, 'b']
    b = [1,2,4,5,6,'a',:c]

    assert_equal [3,:a,'b'],                a - b                
    assert_equal [3,:a,'b', 3,:a,'b'],      a + a - b             
    assert_equal [6, 'a', :c],              b - a
    assert_equal [],                        b - b
    assert_equal [],                        a - a
end

- (Object) test_array_shift_complement



84
85
86
87
88
# File 'test/array/test_array.rb', line 84

def test_array_shift_complement
    assert_equal [2,3],   [1,2,3].shift_complement
    assert_equal 3,       [1,2,3].shift_complement.shift_complement
    assert_equal nil,     [1,2,3].shift_complement.shift_complement.shift_complement
end

- (Object) test_rephrase_index



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'test/array/test_array.rb', line 16

def test_rephrase_index
  test = [ :a, :b, :c, :d]
  0.upto(3) do | i |
    i_inv =  test.rephrase_index(i)
    i_neg =  test.rephrase_index(i, :neg)
    i_pos =  test.rephrase_index(i, :pos)
    i_last = test.rephrase_index(i, :detect_last)
    # print "\n#{test[i]}   #{i}   #{i_inv}"
    
    assert_not_equal  i,      i_inv    
    assert_not_equal  i,      i_neg    
    assert_equal      i_neg,  i_inv    
    assert_equal      i,      i_pos   
    assert_equal test[i],   test[i_inv]
    assert_equal test[i],   test[i_pos]
    assert_equal test[i],   test[i_neg]
    assert_equal test[i],   test[i_last]
  end # do
  
  -4.upto(-1) do | i |
    i_inv = test.rephrase_index(i)
    i_neg = test.rephrase_index(i, :neg)
    i_pos = test.rephrase_index(i, :pos)
    i_last = test.rephrase_index(i, :detect_last)      
    # print "\n#{test[i]}   #{i}   #{i_inv}"
    
    assert_not_equal  i,      i_inv    
    assert_not_equal  i,      i_pos    
    assert_equal      i_pos,  i_inv    
    assert_equal      i,      i_neg   
    assert_equal test[i],   test[i_inv]
    assert_equal test[i],   test[i_pos]
    assert_equal test[i],   test[i_neg]
    assert_equal test[i],   test[i_last]      
  end # do    
  
  [4, 5, -5, -6].each do |i|
    i_inv = test.rephrase_index(i)
    i_neg = test.rephrase_index(i, :neg)
    i_pos = test.rephrase_index(i, :pos)
    i_last = test.rephrase_index(i, :detect_last)      
    # print "\nx   #{i}   #{i_inv}"  
    assert_equal      i,      i_neg         
    assert_equal      i,      i_pos         
    assert_equal      i,      i_neg         
    assert_equal test[i],   test[i_inv]
    assert_equal test[i],   test[i_pos]
    assert_equal test[i],   test[i_neg]    
    assert_equal test[i],   test[i_last]      
  end
  
end