fix test to work with MRI futures
[concurrent.git] / test / test_parallel.rb
blob59431f2f8991fefc60bb3430ae26688d2b93ad1d
1 require 'test/unit'
2 require 'concurrent/parallel'
3 require 'thread'
5 class TestParallel < Test::Unit::TestCase
6   def check_parallel( enum, n, meth, *args, &block )
7     regular = enum.send( meth, *args, &block )
8     parallel = enum.send( "parallel_#{ meth }", n, *args, &block )
9     assert_equal regular, parallel
10   end
12   def test_map
13     check_parallel( 0..100, 2, "map" ) { |x| x * 2 }
14   end
16   def test_any?
17     check_parallel( 0..100, 2, "any?" ) { |x| ( ( x + 1 ) % 48 ).zero? }
18     check_parallel( 0..100, 2, "any?" )
19     check_parallel( [ false ] * 100, 2, "any?" )
20     check_parallel( [ true ] * 100, 2, "any?" )
21   end
23   def test_all?
24     check_parallel( 0..100, 2, "all?" ) { |x| ( ( x + 1 ) % 48 ).zero? }
25     check_parallel( 0..100, 2, "all?" )
26     check_parallel( [ false ] * 100, 2, "all?" )
27     check_parallel( [ true ] * 100, 2, "all?" )
28   end
30   def test_include?
31     check_parallel( 0..100, 2, "include?", 5 )
32     check_parallel( 0..100, 2, "include?", 1000 )
33   end
34 end