Module: Array::ParallelMap::Etest

Defined in:
lib/vex/base/array/parallel_map.rb

Constant Summary collapse

MAX =
1000

Instance Method Summary collapse

Instance Method Details

#calculate(repeat, method) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/vex/base/array/parallel_map.rb', line 55

def calculate(repeat, method)
  (1..repeat).to_a.send(method) do |p| 
    (1..MAX).inject(0) do |sum, i| 
      sum + p * i 
    end 
  end
end

#calculate_parallel(repeat) ⇒ Object



67
68
69
# File 'lib/vex/base/array/parallel_map.rb', line 67

def calculate_parallel(repeat)
  calculate(repeat, :pmap)
end

#calculate_serial(repeat) ⇒ Object



63
64
65
# File 'lib/vex/base/array/parallel_map.rb', line 63

def calculate_serial(repeat)
  calculate(repeat, :map)
end

#test_peachObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vex/base/array/parallel_map.rb', line 77

def test_peach
  semaphore = Mutex.new
  
  results = []
  
  array = [ 1, 2, 3, 4]
  r = array.peach do |p|
    semaphore.synchronize { results << p }
  end
  assert_equal(array, results.sort)
  assert_equal(array, r)
end

#test_pmapObject



71
72
73
74
75
# File 'lib/vex/base/array/parallel_map.rb', line 71

def test_pmap
  serial = calculate_serial(4)
  parallel = calculate_parallel(4)
  assert_equal(serial, parallel)
end

#test_pmap_timeoutObject



90
91
92
93
94
95
96
97
# File 'lib/vex/base/array/parallel_map.rb', line 90

def test_pmap_timeout
  r = [1, 2].pmap(:timeout => 0.1) do |p|
    sleep 0.2
    p * p
  end
  
  assert_equal([], r)
end