[macruby-changes] [1716] MacRuby/branches/experimental/spec/frozen/core/array

source_changes at macosforge.org source_changes at macosforge.org
Wed Jun 3 20:17:23 PDT 2009


Revision: 1716
          http://trac.macosforge.org/projects/ruby/changeset/1716
Author:   lsansonetti at apple.com
Date:     2009-06-03 20:17:23 -0700 (Wed, 03 Jun 2009)
Log Message:
-----------
permutation_spec.rb is now green

Added Paths:
-----------
    MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec.rb

Removed Paths:
-------------
    MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec_disabled.rb

Copied: MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec.rb (from rev 1713, MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec_disabled.rb)
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec.rb	                        (rev 0)
+++ MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec.rb	2009-06-04 03:17:23 UTC (rev 1716)
@@ -0,0 +1,92 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+require File.dirname(__FILE__) + '/fixtures/classes'
+
+
+ruby_version_is "1.8.7" do
+  describe "Array#permutation" do
+
+    before(:each) do
+      @numbers = (1..3).to_a
+      @yielded = []
+    end
+
+    it "returns an Enumerator of all permutations when called without a block or arguments" do
+      enum = @numbers.permutation
+      enum.should be_kind_of(Enumerable)
+      enum.to_a.sort.should == [
+        [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
+      ].sort
+    end
+
+    it "returns an Enumerator of permutations of given length when called with an argument but no block" do
+      enum = @numbers.permutation(1)
+      enum.should be_kind_of(Enumerable)
+      enum.to_a.sort.should == [[1],[2],[3]] 
+    end
+
+    it "yields all permutations to the block then returns self when called with block but no arguments" do
+      array = @numbers.permutation {|n| @yielded << n}
+      array.should be_an_instance_of(Array)
+      array.sort.should == @numbers.sort
+      @yielded.sort.should == [
+        [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
+      ].sort
+    end
+
+    it "yields all permutations of given length to the block then returns self when called with block and argument" do
+      array = @numbers.permutation(2) {|n| @yielded << n}
+      array.should be_an_instance_of(Array)
+      array.sort.should == @numbers.sort
+      @yielded.sort.should == [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]].sort
+    end
+
+    it "returns the empty permutation ([[]]) when the given length is 0" do
+      @numbers.permutation(0).to_a.should == [[]]
+      @numbers.permutation(0) { |n| @yielded << n }
+      @yielded.should == [[]]
+    end
+
+    it "returns the empty permutation([]) when called on an empty Array" do 
+      [].permutation.to_a.should == [[]]
+      [].permutation { |n| @yielded << n }
+      @yielded.should == [[]]
+    end  
+
+    it "returns no permutations when the given length has no permutations" do 
+      @numbers.permutation(9).entries.size == 0
+      @numbers.permutation(9) { |n| @yielded << n }
+      @yielded.should == []
+    end  
+    
+    it "handles duplicate elements correctly" do
+      @numbers << 1
+      @numbers.permutation(2).sort.should == [
+        [1,1],[1,1],[1,2],[1,2],[1,3],[1,3],
+        [2,1],[2,1],[2,3],
+        [3,1],[3,1],[3,2]
+      ].sort
+    end
+
+    it "handles nested Arrays correctly" do
+      # The ugliness is due to the order of permutations returned by
+      # permutation being undefined combined with #sort croaking on Arrays of
+      # Arrays.
+      @numbers << [4,5]
+      got = @numbers.permutation(2).to_a
+      expected = [
+         [1, 2],      [1, 3],      [1, [4, 5]], 
+         [2, 1],      [2, 3],      [2, [4, 5]], 
+         [3, 1],      [3, 2],      [3, [4, 5]], 
+        [[4, 5], 1], [[4, 5], 2], [[4, 5], 3]
+      ]
+      expected.each {|e| got.include?(e).should be_true}
+      got.size.should == expected.size
+    end
+
+    it "truncates Float arguments" do 
+      @numbers.permutation(3.7).to_a.sort.should == 
+        @numbers.permutation(3).to_a.sort
+    end  
+  
+  end
+end

Deleted: MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec_disabled.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec_disabled.rb	2009-06-04 03:14:38 UTC (rev 1715)
+++ MacRuby/branches/experimental/spec/frozen/core/array/permutation_spec_disabled.rb	2009-06-04 03:17:23 UTC (rev 1716)
@@ -1,92 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-require File.dirname(__FILE__) + '/fixtures/classes'
-
-
-ruby_version_is "1.8.7" do
-  describe "Array#permutation" do
-
-    before(:each) do
-      @numbers = (1..3).to_a
-      @yielded = []
-    end
-
-    it "returns an Enumerator of all permutations when called without a block or arguments" do
-      enum = @numbers.permutation
-      enum.should be_kind_of(Enumerable)
-      enum.to_a.sort.should == [
-        [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
-      ].sort
-    end
-
-    it "returns an Enumerator of permutations of given length when called with an argument but no block" do
-      enum = @numbers.permutation(1)
-      enum.should be_kind_of(Enumerable)
-      enum.to_a.sort.should == [[1],[2],[3]] 
-    end
-
-    it "yields all permutations to the block then returns self when called with block but no arguments" do
-      array = @numbers.permutation {|n| @yielded << n}
-      array.should be_an_instance_of(Array)
-      array.sort.should == @numbers.sort
-      @yielded.sort.should == [
-        [1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
-      ].sort
-    end
-
-    it "yields all permutations of given length to the block then returns self when called with block and argument" do
-      array = @numbers.permutation(2) {|n| @yielded << n}
-      array.should be_an_instance_of(Array)
-      array.sort.should == @numbers.sort
-      @yielded.sort.should == [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]].sort
-    end
-
-    it "returns the empty permutation ([[]]) when the given length is 0" do
-      @numbers.permutation(0).to_a.should == [[]]
-      @numbers.permutation(0) { |n| @yielded << n }
-      @yielded.should == [[]]
-    end
-
-    it "returns the empty permutation([]) when called on an empty Array" do 
-      [].permutation.to_a.should == [[]]
-      [].permutation { |n| @yielded << n }
-      @yielded.should == [[]]
-    end  
-
-    it "returns no permutations when the given length has no permutations" do 
-      @numbers.permutation(9).entries.size == 0
-      @numbers.permutation(9) { |n| @yielded << n }
-      @yielded.should == []
-    end  
-    
-    it "handles duplicate elements correctly" do
-      @numbers << 1
-      @numbers.permutation(2).sort.should == [
-        [1,1],[1,1],[1,2],[1,2],[1,3],[1,3],
-        [2,1],[2,1],[2,3],
-        [3,1],[3,1],[3,2]
-      ].sort
-    end
-
-    it "handles nested Arrays correctly" do
-      # The ugliness is due to the order of permutations returned by
-      # permutation being undefined combined with #sort croaking on Arrays of
-      # Arrays.
-      @numbers << [4,5]
-      got = @numbers.permutation(2).to_a
-      expected = [
-         [1, 2],      [1, 3],      [1, [4, 5]], 
-         [2, 1],      [2, 3],      [2, [4, 5]], 
-         [3, 1],      [3, 2],      [3, [4, 5]], 
-        [[4, 5], 1], [[4, 5], 2], [[4, 5], 3]
-      ]
-      expected.each {|e| got.include?(e).should be_true}
-      got.size.should == expected.size
-    end
-
-    it "truncates Float arguments" do 
-      @numbers.permutation(3.7).to_a.sort.should == 
-        @numbers.permutation(3).to_a.sort
-    end  
-  
-  end
-end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090603/69373f07/attachment-0001.html>


More information about the macruby-changes mailing list