Revision
3445
Author
ernest.prabhakar@gmail.com
Date
2010-02-08 15:03:48 -0800 (Mon, 08 Feb 2010)

Log Message

Initial enumerable spec

Added Paths

Diff

Added: MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb (0 => 3445)


--- MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb	                        (rev 0)
+++ MacRuby/trunk/spec/macruby/library/dispatch/enumerable_spec.rb	2010-02-08 23:03:48 UTC (rev 3445)
@@ -0,0 +1,68 @@
+require File.dirname(__FILE__) + "/../../spec_helper"
+require 'dispatch'
+
+if MACOSX_VERSION >= 10.6
+  describe "parallel Enumerable" do
+    before :each do
+      @ary = (1..3).to_a
+    end
+
+    describe :p_each do
+      it "exists on objects that support Enumerable" do
+        @ary.respond_to?(:p_each).should == true
+      end
+
+      it "behaves like each" do
+        @sum1 = 0
+        @ary.each {|v| @sum1 += v*v}
+        @sum2 = 0
+        @q = Dispatch.queue_for(@sum2)
+        @ary.p_each {|v| temp = v*v; @q.sync {@sum2 += temp} }
+        @sum1.should == @sum2
+      end
+      
+      it "executes concurrently" do
+        true.should == true
+      end
+    end
+    
+    describe :p_each_with_index do
+      it "exists on objects that support Enumerable" do
+        @ary.respond_to?(:p_each).should == true
+      end
+      it "behaves like each_with_index" do
+        @ary.should.respond_to? :p_each_with_index
+      end
+      
+      it "executes concurrently" do
+        true.should == true
+      end
+    end
+    
+    describe :p_inject do
+      it "exists on objects that support Enumerable" do
+        @ary.respond_to?(:p_each).should == true
+      end
+      it "behaves like inject" do
+        @ary.should.respond_to? :p_inject
+      end
+      
+      it "executes concurrently" do
+        true.should == true
+      end
+    end
+
+    describe :p_map do
+      it "exists on objects that support Enumerable" do
+        @ary.respond_to?(:p_each).should == true
+      end
+      it "behaves like map" do
+        @ary.should.respond_to? :p_map
+      end
+      
+      it "executes concurrently" do
+        true.should == true
+      end
+    end
+  end
+end
\ No newline at end of file