Module: Hash::Cross::Etest

Defined in:
lib/vex/base/hash/cross.rb

Instance Method Summary collapse

Instance Method Details

#assert_equal_sets(a, b) ⇒ Object



51
52
53
54
55
56
# File 'lib/vex/base/hash/cross.rb', line 51

def assert_equal_sets(a, b)
  return assert_equal_sets(Set.new(a), b) unless a.is_a?(Set)
  return assert_equal_sets(a, Set.new(b)) unless b.is_a?(Set)
  
  assert_equal(a, b)
end

#test_cross_1Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vex/base/hash/cross.rb', line 58

def test_cross_1    
  uncrossed = { :a => [ 1, 2], :b => [ "bb", "cc"], :c => :cc }
  uncrossed_orig = uncrossed.dup

  crossed = [
    { :a => [1, 2], :b => "bb", :c => :cc },
    { :a => [1, 2], :b => "cc", :c => :cc }
  ]

  assert_equal_sets(crossed, uncrossed.cross(:b))
  assert_equal(uncrossed_orig, uncrossed)
end

#test_cross_2Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vex/base/hash/cross.rb', line 71

def test_cross_2
  uncrossed = { :a => [ 1, 2], :b => [ "bb", "cc"], :c => :cc }
  uncrossed_orig = uncrossed.dup

  crossed = [
      { :a => 1, :b => "bb", :c => :cc },
      { :a => 2, :b => "bb", :c => :cc },
      { :a => 1, :b => "cc", :c => :cc },
      { :a => 2, :b => "cc", :c => :cc }
    ]

  assert_equal_sets(crossed, uncrossed.cross)
  assert_equal(uncrossed_orig, uncrossed)
end

#test_cross_2_w_orderObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/vex/base/hash/cross.rb', line 86

def test_cross_2_w_order
  uncrossed = { :a => [ 1, 2], :b => [ "bb", "cc"], :c => :cc }
  uncrossed_orig = uncrossed.dup

  crossed = [
      { :a => 1, :b => "bb", :c => :cc },
      { :a => 1, :b => "cc", :c => :cc },
      { :a => 2, :b => "bb", :c => :cc },
      { :a => 2, :b => "cc", :c => :cc }
    ]

  assert_equal(crossed, uncrossed.cross(:a, :b))
  assert_equal(uncrossed_orig, uncrossed)
end

#test_cross_simpleObject



101
102
103
104
105
106
107
# File 'lib/vex/base/hash/cross.rb', line 101

def test_cross_simple
  uncrossed = { :a => :b }
  assert_equal([{:a=>:b}], uncrossed.cross)

  uncrossed = { :a => [ 1, :b ] }
  assert_equal([{:a=>1}, {:a=>:b}], uncrossed.cross)
end