Module: Enumerable::Etest

Defined in:
lib/vex/base/enumerable/progress.rb,
lib/vex/base/enumerable/enumerable_ext.rb

Instance Method Summary collapse

Instance Method Details

#test_any_none(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vex/base/enumerable/enumerable_ext.rb', line 31

def test_any_none(&block)
  assert_equal(false, [ 1, 2, true, false ].any?(&:nil?))
  assert_equal(true, [ 1, 2, true, false ].none?(&:nil?))
  assert_equal(true, [ 1, 2, true, false, nil ].any?(&:nil?))
  assert_equal(false, [ 1, 2, true, false, nil ].none?(&:nil?))

  assert_equal(true, [ nil ].any?(&:nil?))
  assert_equal(false, [ 1 ].any?(&:nil?))
  assert_equal(false, [ ].any?(&:nil?))

  assert_equal(false, [ nil ].none?(&:nil?))
  assert_equal(true, [ 1 ].none?(&:nil?))
  assert_equal(true, [ ].none?(&:nil?))
end

#test_any_not_all(&block) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/vex/base/enumerable/enumerable_ext.rb', line 46

def test_any_not_all(&block)
  assert_equal(true, [ 1, 2, true, false ].any_not?(&:nil?))
  assert_equal(true, [ 1, 2, nil ].any_not?(&:nil?))
  assert_equal(false, [ nil ].any_not?(&:nil?))
  assert_equal(true, [ 1 ].any_not?(&:nil?))
  assert_equal(false, [ ].any_not?(&:nil?))
end

#test_hmapObject



54
55
56
57
58
# File 'lib/vex/base/enumerable/enumerable_ext.rb', line 54

def test_hmap
  h = %w(1 2 3)

  assert_equal({ "1" => 1, "2" => 4, "3" => 9}, h.hmap do |line| line.to_i * line.to_i end)
end

#test_stable_sort_byObject



23
24
25
26
27
28
29
# File 'lib/vex/base/enumerable/enumerable_ext.rb', line 23

def test_stable_sort_by
  data = [[1, 'b'], [1, 'c'], [0, 'b'], [0, 'a']]

  # This might or might not fail, but is not guaranteed to do so: 
  # assert_equal [[0, 'b'], [0, 'a'], [ 1, 'b'], [1, 'c']], data.stable_sort_by { |t| t[0] }
  assert_equal [[0, 'b'], [0, 'a'], [ 1, 'b'], [1, 'c']], data.stable_sort_by { |t| t[0] }
end

#test_with_progressObject



65
66
67
68
69
70
# File 'lib/vex/base/enumerable/progress.rb', line 65

def test_with_progress
  Enumerable::ConsoleProgress.any_instance.stubs(:print_line).returns(nil)
  
  r = [ 1, 2 ].with_progress.map do |s| s * s end
  assert_equal( [ 1, 4], r)
end