combinatorics 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +28 -0
  3. data/.gitignore +5 -5
  4. data/ChangeLog.md +11 -0
  5. data/Gemfile +16 -0
  6. data/LICENSE.txt +1 -1
  7. data/README.md +144 -107
  8. data/Rakefile +6 -32
  9. data/combinatorics.gemspec +2 -4
  10. data/gemspec.yml +8 -4
  11. data/lib/combinatorics/cartesian_product/cardinality.rb +2 -0
  12. data/lib/combinatorics/cartesian_product/extensions/array.rb +3 -1
  13. data/lib/combinatorics/cartesian_product/extensions/set.rb +3 -1
  14. data/lib/combinatorics/cartesian_product/extensions.rb +4 -2
  15. data/lib/combinatorics/cartesian_product/mixin.rb +3 -1
  16. data/lib/combinatorics/cartesian_product.rb +5 -3
  17. data/lib/combinatorics/choose/cardinality.rb +4 -2
  18. data/lib/combinatorics/choose/extensions/array.rb +3 -1
  19. data/lib/combinatorics/choose/extensions/set.rb +4 -1
  20. data/lib/combinatorics/choose/extensions.rb +4 -2
  21. data/lib/combinatorics/choose/mixin.rb +2 -0
  22. data/lib/combinatorics/choose.rb +5 -3
  23. data/lib/combinatorics/derange/cardinality.rb +3 -1
  24. data/lib/combinatorics/derange/extensions/array.rb +3 -1
  25. data/lib/combinatorics/derange/extensions.rb +3 -1
  26. data/lib/combinatorics/derange/mixin.rb +2 -0
  27. data/lib/combinatorics/derange.rb +5 -3
  28. data/lib/combinatorics/enumerator.rb +2 -0
  29. data/lib/combinatorics/extensions/math.rb +2 -0
  30. data/lib/combinatorics/extensions/range.rb +2 -0
  31. data/lib/combinatorics/extensions.rb +3 -1
  32. data/lib/combinatorics/generator.rb +3 -1
  33. data/lib/combinatorics/list_comprehension.rb +3 -1
  34. data/lib/combinatorics/permute/cardinality.rb +3 -1
  35. data/lib/combinatorics/permute/extensions/array.rb +3 -1
  36. data/lib/combinatorics/permute/extensions/set.rb +3 -1
  37. data/lib/combinatorics/permute/extensions.rb +4 -2
  38. data/lib/combinatorics/permute/mixin.rb +2 -0
  39. data/lib/combinatorics/permute.rb +5 -3
  40. data/lib/combinatorics/power_set/cardinality.rb +3 -1
  41. data/lib/combinatorics/power_set/extensions/array.rb +3 -1
  42. data/lib/combinatorics/power_set/extensions/set.rb +3 -1
  43. data/lib/combinatorics/power_set/extensions.rb +4 -2
  44. data/lib/combinatorics/power_set/mixin.rb +2 -0
  45. data/lib/combinatorics/power_set.rb +5 -3
  46. data/lib/combinatorics/version.rb +3 -1
  47. data/lib/combinatorics.rb +12 -10
  48. data/spec/cartesian_product/cardinality_spec.rb +14 -16
  49. data/spec/cartesian_product/mixin_examples.rb +14 -14
  50. data/spec/choose/cardinality_spec.rb +32 -34
  51. data/spec/choose/mixin_examples.rb +6 -6
  52. data/spec/combinatorics_spec.rb +1 -1
  53. data/spec/derange/cardinality_spec.rb +1 -3
  54. data/spec/derange/mixin_examples.rb +6 -6
  55. data/spec/enumerator_spec.rb +1 -1
  56. data/spec/extensions/math_spec.rb +19 -19
  57. data/spec/extensions/range_spec.rb +12 -12
  58. data/spec/generator_spec.rb +1 -1
  59. data/spec/list_comprehension_spec.rb +10 -10
  60. data/spec/permute/cardinality_spec.rb +29 -31
  61. data/spec/permute/mixin_examples.rb +5 -5
  62. data/spec/power_set/cardinality_spec.rb +1 -3
  63. data/spec/power_set/mixin_examples.rb +4 -4
  64. data/spec/spec_helper.rb +2 -5
  65. metadata +26 -58
  66. data/.gemtest +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #
2
4
  # @author duper <super@manson.vistech.net>
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Range
2
4
 
3
5
  #
@@ -1 +1,3 @@
1
- require 'combinatorics/extensions/range'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/range'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'enumerator'
2
4
  require 'generator' if RUBY_VERSION < '1.9'
3
5
 
@@ -5,7 +7,7 @@ module Combinatorics
5
7
  # auto-detects the `Generator` class.
6
8
  Generator = if defined?(::Generator) # 1.8.7
7
9
  ::Generator
8
- elsif defined?(::Enumerator::Generator) # 1.9
10
+ elsif defined?(::Enumerator::Generator) # >= 1.9.1
9
11
  ::Enumerator::Generator
10
12
  else
11
13
  raise(NameError,"unable to find the Generator class")
@@ -1,4 +1,6 @@
1
- require 'combinatorics/enumerator'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'enumerator'
2
4
 
3
5
  class Array
4
6
 
@@ -1,4 +1,6 @@
1
- require 'combinatorics/extensions/math'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../extensions/math'
2
4
 
3
5
  module Combinatorics
4
6
  #
@@ -1,4 +1,6 @@
1
- require 'combinatorics/permute/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  class Array
4
6
 
@@ -1,4 +1,6 @@
1
- require 'combinatorics/permute/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  require 'set'
4
6
 
@@ -1,2 +1,4 @@
1
- require 'combinatorics/permute/extensions/array'
2
- require 'combinatorics/permute/extensions/set'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/array'
4
+ require_relative 'extensions/set'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Combinatorics
2
4
  module Permute
3
5
  #
@@ -1,3 +1,5 @@
1
- require 'combinatorics/permute/cardinality'
2
- require 'combinatorics/permute/mixin'
3
- require 'combinatorics/permute/extensions'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'permute/cardinality'
4
+ require_relative 'permute/mixin'
5
+ require_relative 'permute/extensions'
@@ -1,4 +1,6 @@
1
- require 'combinatorics/extensions/math'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../extensions/math'
2
4
 
3
5
  module Combinatorics
4
6
  module PowerSet
@@ -1,4 +1,6 @@
1
- require 'combinatorics/power_set/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  class Array
4
6
 
@@ -1,4 +1,6 @@
1
- require 'combinatorics/power_set/mixin'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../mixin'
2
4
 
3
5
  require 'set'
4
6
 
@@ -1,2 +1,4 @@
1
- require 'combinatorics/power_set/extensions/array'
2
- require 'combinatorics/power_set/extensions/set'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'extensions/array'
4
+ require_relative 'extensions/set'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Combinatorics
2
4
  module PowerSet
3
5
  #
@@ -1,3 +1,5 @@
1
- require 'combinatorics/power_set/mixin'
2
- require 'combinatorics/power_set/extensions'
3
- require 'combinatorics/power_set/cardinality'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'power_set/mixin'
4
+ require_relative 'power_set/extensions'
5
+ require_relative 'power_set/cardinality'
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Combinatorics
2
4
  # Combinatorics module revision number
3
- VERSION = '0.4.3'
5
+ VERSION = '0.5.0'
4
6
  end
data/lib/combinatorics.rb CHANGED
@@ -1,11 +1,13 @@
1
- require 'combinatorics/cartesian_product'
2
- require 'combinatorics/choose'
3
- require 'combinatorics/derange'
4
- require 'combinatorics/extensions'
5
- require 'combinatorics/list_comprehension'
6
- require 'combinatorics/power_set'
7
- require 'combinatorics/permute'
8
- require 'combinatorics/version'
1
+ # frozen_string_literal: true
9
2
 
10
- # @todo inversions (permutation mutations)
11
- # @todo set families (approximate power set subsets)
3
+ require_relative 'combinatorics/cartesian_product'
4
+ require_relative 'combinatorics/choose'
5
+ require_relative 'combinatorics/derange'
6
+ require_relative 'combinatorics/extensions'
7
+ require_relative 'combinatorics/list_comprehension'
8
+ require_relative 'combinatorics/power_set'
9
+ require_relative 'combinatorics/permute'
10
+ require_relative 'combinatorics/version'
11
+
12
+ # TODO: inversions (permutation mutations)
13
+ # TODO: set families (approximate power set subsets)
@@ -1,60 +1,58 @@
1
1
  require 'spec_helper'
2
2
  require 'combinatorics/cartesian_product'
3
3
 
4
- describe CartesianProduct do
5
- subject { CartesianProduct }
6
-
4
+ describe Combinatorics::CartesianProduct do
7
5
  describe "cardinality" do
8
6
  it "should return 1 for cardinality(1, 1)" do
9
- subject.cardinality(1, 1).should == 1
7
+ expect(subject.cardinality(1, 1)).to eq(1)
10
8
  end
11
9
 
12
10
  it "should return 2 for cardinality(1, 2)" do
13
- subject.cardinality(1, 2).should == 2
11
+ expect(subject.cardinality(1, 2)).to eq(2)
14
12
  end
15
13
 
16
14
  it "should return 2 for cardinality(2, 1)" do
17
- subject.cardinality(2, 1).should == 2
15
+ expect(subject.cardinality(2, 1)).to eq(2)
18
16
  end
19
17
 
20
18
  it "should return 4 for cardinality(2, 2)" do
21
- subject.cardinality(2, 2).should == 4
19
+ expect(subject.cardinality(2, 2)).to eq(4)
22
20
  end
23
21
 
24
22
  it "should return 3 for cardinality(3, 1)" do
25
- subject.cardinality(3, 1).should == 3
23
+ expect(subject.cardinality(3, 1)).to eq(3)
26
24
  end
27
25
 
28
26
  it "should return 3 for cardinality(1, 3)" do
29
- subject.cardinality(1, 3).should == 3
27
+ expect(subject.cardinality(1, 3)).to eq(3)
30
28
  end
31
29
 
32
30
  it "should return 6 for cardinality(2, 3)" do
33
- subject.cardinality(2, 3).should == 6
31
+ expect(subject.cardinality(2, 3)).to eq(6)
34
32
  end
35
33
 
36
34
  it "should return 6 for cardinality(3, 2)" do
37
- subject.cardinality(3, 2).should == 6
35
+ expect(subject.cardinality(3, 2)).to eq(6)
38
36
  end
39
37
 
40
38
  it "should return 9 for cardinality(3, 3)" do
41
- subject.cardinality(3, 3).should == 9
39
+ expect(subject.cardinality(3, 3)).to eq(9)
42
40
  end
43
41
 
44
42
  it "should raise RangeError if c1 is negative" do
45
- lambda { subject.cardinality(-1, 1) }.should raise_error(RangeError)
43
+ expect { subject.cardinality(-1, 1) }.to raise_error(RangeError)
46
44
  end
47
45
 
48
46
  it "should raise RangeError if c2 is negative" do
49
- lambda { subject.cardinality(1, -1) }.should raise_error(RangeError)
47
+ expect { subject.cardinality(1, -1) }.to raise_error(RangeError)
50
48
  end
51
49
 
52
50
  it "should raise RangeError if c1 is zero" do
53
- lambda { subject.cardinality(0, 1) }.should raise_error(RangeError)
51
+ expect { subject.cardinality(0, 1) }.to raise_error(RangeError)
54
52
  end
55
53
 
56
54
  it "should raise RangeError if c2 is zero" do
57
- lambda { subject.cardinality(1, 0) }.should raise_error(RangeError)
55
+ expect { subject.cardinality(1, 0) }.to raise_error(RangeError)
58
56
  end
59
57
  end
60
58
 
@@ -7,52 +7,52 @@ shared_examples_for "CartesianProduct::Mixin" do
7
7
  set = subject[1]
8
8
  results = set.cartprod(set)
9
9
 
10
- results.should be_kind_of(Enumerator)
10
+ expect(results).to be_kind_of(Enumerator)
11
11
  end
12
12
 
13
13
  it "the cartprod of two empty Set's should return an empty Set" do
14
14
  set = subject[]
15
15
  results = set.cartprod([]).to_a
16
16
 
17
- results.should be_empty
17
+ expect(results).to be_empty
18
18
  end
19
19
 
20
20
  it "the cartprod of a single empty set should return an empty Set" do
21
21
  set = subject[1,2]
22
22
  results = set.cartprod([2,3],[]).to_a
23
23
 
24
- results.should be_empty
24
+ expect(results).to be_empty
25
25
  end
26
26
 
27
27
  it "the cartprod of another empty set should also return an empty Set" do
28
28
  set = subject[]
29
29
  results = set.cartprod([1]).to_a
30
30
 
31
- results.should be_empty
31
+ expect(results).to be_empty
32
32
  end
33
33
 
34
34
  it "the cartprod of [1] and [1] should be [[1, 1]]" do
35
35
  set = subject[1]
36
36
  results = set.cartprod([1]).to_a
37
37
 
38
- results.should == [[1, 1]]
38
+ expect(results).to eq([[1, 1]])
39
39
  end
40
40
 
41
41
  it "the cartprod of [1, 2] and [3] should be [[1, 3], [2, 3]]" do
42
42
  set = subject[1, 2]
43
43
  results = set.cartprod([3]).to_a
44
44
 
45
- results.should =~ [[1, 3], [2, 3]]
45
+ expect(results).to match_array([[1, 3], [2, 3]])
46
46
  end
47
47
 
48
48
  it "the cartprod of [1, 2] and [3, 4] should be [[1, 3], [1, 4], [2, 3], [2, 4]]" do
49
49
  set = subject[1, 2]
50
50
  results = set.cartprod([3, 4]).to_a
51
51
 
52
- results.should =~ [
52
+ expect(results).to match_array([
53
53
  [1, 3], [1, 4],
54
54
  [2, 3], [2, 4]
55
- ]
55
+ ])
56
56
  end
57
57
 
58
58
  it "the cartprod of ['a'].cartprod(['b', 'c', 'd']) should be [['a', 'b'], ['a', 'c'], ['a', 'd']]" do
@@ -60,7 +60,7 @@ shared_examples_for "CartesianProduct::Mixin" do
60
60
  set2 = subject['b', 'c', 'd']
61
61
  results = set1.cartprod(set2).to_a
62
62
 
63
- results.should =~ [['a', 'b'], ['a', 'c'], ['a', 'd']]
63
+ expect(results).to match_array([['a', 'b'], ['a', 'c'], ['a', 'd']])
64
64
  end
65
65
 
66
66
  it "the cartprod of [0, 1] and [[2, 3], [4, 5]] should be [[0, 2, 4], [1, 2, 4], [0, 3, 4], [1, 3, 4], [0, 2, 5], [1, 2, 5], [0, 3, 5], [1, 3, 5]]" do
@@ -69,10 +69,10 @@ shared_examples_for "CartesianProduct::Mixin" do
69
69
  set3 = subject[4, 5]
70
70
  results = set1.cartprod(set2, set3).to_a
71
71
 
72
- results.should =~ [
72
+ expect(results).to match_array([
73
73
  [0, 2, 4], [0, 2, 5], [0, 3, 4], [0, 3, 5],
74
74
  [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5],
75
- ]
75
+ ])
76
76
  end
77
77
 
78
78
  it "should take an optional block argument" do
@@ -81,18 +81,18 @@ shared_examples_for "CartesianProduct::Mixin" do
81
81
 
82
82
  set.cartprod(set) { |result| results << result }
83
83
 
84
- results.should == [[1, 1]]
84
+ expect(results).to eq([[1, 1]])
85
85
  end
86
86
 
87
87
  it "should alias cartprod to cartesian_product" do
88
88
  aset = subject[1]
89
89
 
90
- aset.should respond_to(:cartesian_product)
90
+ expect(aset).to respond_to(:cartesian_product)
91
91
  end
92
92
 
93
93
  it "should alias cartprod to cartesian" do
94
94
  aset = subject[1]
95
95
 
96
- aset.should respond_to(:cartesian)
96
+ expect(aset).to respond_to(:cartesian)
97
97
  end
98
98
  end
@@ -1,128 +1,126 @@
1
1
  require 'spec_helper'
2
2
  require 'combinatorics/choose'
3
3
 
4
- describe Choose do
5
- subject { Choose }
6
-
4
+ describe Combinatorics::Choose do
7
5
  describe "cardinality" do
8
6
  it "should raise RangeError if n is negative" do
9
- lambda { subject.cardinality(-1) }.should raise_error(RangeError)
7
+ expect { subject.cardinality(-1) }.to raise_error(RangeError)
10
8
  end
11
9
 
12
10
  it "should raise RangeError if n is negative" do
13
- lambda { subject.cardinality(-1, 1) }.should raise_error(RangeError)
11
+ expect { subject.cardinality(-1, 1) }.to raise_error(RangeError)
14
12
  end
15
13
 
16
14
  it "should raise RangeError if r is negative" do
17
- lambda { subject.cardinality(1, -1) }.should raise_error(RangeError)
15
+ expect { subject.cardinality(1, -1) }.to raise_error(RangeError)
18
16
  end
19
17
 
20
18
  it "should raise RangeError if r is greater than n" do
21
- lambda { subject.cardinality(2, 3) }.should raise_error(RangeError)
19
+ expect { subject.cardinality(2, 3) }.to raise_error(RangeError)
22
20
  end
23
21
 
24
22
  it "should return 1 for subject.cardinality(0)" do
25
- subject.cardinality(0).should == 1
23
+ expect(subject.cardinality(0)).to eq(1)
26
24
  end
27
25
 
28
26
  it "should return 1 for subject.cardinality(1)" do
29
- subject.cardinality(1).should == 1
27
+ expect(subject.cardinality(1)).to eq(1)
30
28
  end
31
29
 
32
30
  it "should return 2 for subject.cardinality(2)" do
33
- subject.cardinality(2).should == 2
31
+ expect(subject.cardinality(2)).to eq(2)
34
32
  end
35
33
 
36
34
  it "should return 6 for subject.cardinality(3)" do
37
- subject.cardinality(3).should == 6
35
+ expect(subject.cardinality(3)).to eq(6)
38
36
  end
39
37
 
40
38
  it "should return 24 for subject.cardinality(4)" do
41
- subject.cardinality(4).should == 24
39
+ expect(subject.cardinality(4)).to eq(24)
42
40
  end
43
41
 
44
- it "should return 0 for subject.cardinality(1, 0)" do
45
- subject.cardinality(1, 0).should == 0
42
+ it "should return 1 for subject.cardinality(1, 0)" do
43
+ expect(subject.cardinality(1, 0)).to eq(1)
46
44
  end
47
45
 
48
46
  it "should return 1 for subject.cardinality(1, 1)" do
49
- subject.cardinality(1, 1).should == 1
47
+ expect(subject.cardinality(1, 1)).to eq(1)
50
48
  end
51
49
 
52
50
  it "should return 2 for subject.cardinality(2, 1)" do
53
- subject.cardinality(2, 1).should == 2
51
+ expect(subject.cardinality(2, 1)).to eq(2)
54
52
  end
55
53
 
56
54
  it "should return 1 for subject.cardinality(2, 2)" do
57
- subject.cardinality(2, 2).should == 1
55
+ expect(subject.cardinality(2, 2)).to eq(1)
58
56
  end
59
57
 
60
58
  it "should return 3 for subject.cardinality(3, 1)" do
61
- subject.cardinality(3, 1).should == 3
59
+ expect(subject.cardinality(3, 1)).to eq(3)
62
60
  end
63
61
 
64
62
  it "should return 3 for subject.cardinality(3, 2)" do
65
- subject.cardinality(3, 2).should == 3
63
+ expect(subject.cardinality(3, 2)).to eq(3)
66
64
  end
67
65
 
68
66
  it "should return 1 for subject.cardinality(3, 3)" do
69
- subject.cardinality(3, 3).should == 1
67
+ expect(subject.cardinality(3, 3)).to eq(1)
70
68
  end
71
69
 
72
70
  it "should return 4 for subject.cardinality(4, 1)" do
73
- subject.cardinality(4, 1).should == 4
71
+ expect(subject.cardinality(4, 1)).to eq(4)
74
72
  end
75
73
 
76
74
  it "should return 6 for subject.cardinality(4, 2)" do
77
- subject.cardinality(4, 2).should == 6
75
+ expect(subject.cardinality(4, 2)).to eq(6)
78
76
  end
79
77
 
80
78
  it "should return 4 for subject.cardinality(4, 3)" do
81
- subject.cardinality(4, 3).should == 4
79
+ expect(subject.cardinality(4, 3)).to eq(4)
82
80
  end
83
81
 
84
82
  it "should return 1 for subject.cardinality(4, 4)" do
85
- subject.cardinality(4, 4).should == 1
83
+ expect(subject.cardinality(4, 4)).to eq(1)
86
84
  end
87
85
 
88
86
  it "should return 15 for subject.cardinality(6, 4)" do
89
- subject.cardinality(6, 4).should == 15
87
+ expect(subject.cardinality(6, 4)).to eq(15)
90
88
  end
91
89
 
92
90
  it "should return 3628800 for subject.cardinality(10)" do
93
- subject.cardinality(10).should == 3628800
91
+ expect(subject.cardinality(10)).to eq(3628800)
94
92
  end
95
93
  end
96
94
 
97
95
  describe "cardinality_all" do
98
96
  it "should return [] for subject.cardinality_all(0)" do
99
- subject.cardinality_all(0).should be_empty
97
+ expect(subject.cardinality_all(0)).to be_empty
100
98
  end
101
99
 
102
100
  it "should return [1] for subject.cardinality_all(1)" do
103
- subject.cardinality_all(1).should == [1]
101
+ expect(subject.cardinality_all(1)).to eq([1])
104
102
  end
105
103
 
106
104
  it "should return [2, 1] for subject.cardinality_all(2)" do
107
- subject.cardinality_all(2).should == [2, 1]
105
+ expect(subject.cardinality_all(2)).to eq([2, 1])
108
106
  end
109
107
 
110
108
  it "should return [3, 3, 1] for subject.cardinality_all(3)" do
111
- subject.cardinality_all(3).should == [3, 3, 1]
109
+ expect(subject.cardinality_all(3)).to eq([3, 3, 1])
112
110
  end
113
111
 
114
112
  it "should return [4, 6, 4, 1] for subject.cardinality_all(4)" do
115
- subject.cardinality_all(4).should == [4, 6, 4, 1]
113
+ expect(subject.cardinality_all(4)).to eq([4, 6, 4, 1])
116
114
  end
117
115
 
118
116
  it "should allow specifying the range of `r` values" do
119
- subject.cardinality_all(10,5..10).should == [
117
+ expect(subject.cardinality_all(10,5..10)).to eq([
120
118
  252, 210, 120, 45, 10, 1
121
- ]
119
+ ])
122
120
  end
123
121
 
124
122
  it "should raise RangeError for subject.cardinality_all(-1)" do
125
- lambda { subject.cardinality_all(-1) }.should raise_error(RangeError)
123
+ expect { subject.cardinality_all(-1) }.to raise_error(RangeError)
126
124
  end
127
125
 
128
126
  it "should wrap cardinality with Choose.C" do
@@ -8,41 +8,41 @@ shared_examples_for "Choose::Mixin" do
8
8
  set = subject[]
9
9
  results = set.choose(0).to_a
10
10
 
11
- results.should == [empty_set]
11
+ expect(results).to eq([empty_set])
12
12
  end
13
13
 
14
14
  it "should return [[]] for [1].choose(0).to_a" do
15
15
  set = subject[1]
16
16
  results = set.choose(0).to_a
17
17
 
18
- results.should == [empty_set]
18
+ expect(results).to eq([empty_set])
19
19
  end
20
20
 
21
21
  it "should return [[1]] for [1].choose(1).to_a" do
22
22
  set = subject[1]
23
23
  results = set.choose(1).to_a
24
24
 
25
- results.should == [Set[1]]
25
+ expect(results).to eq([Set[1]])
26
26
  end
27
27
 
28
28
  it "should return [[1], [2]] for [1, 2].choose(1).to_a" do
29
29
  set = subject[1, 2]
30
30
  results = set.choose(1).to_a
31
31
 
32
- results.should =~ [Set[1], Set[2]]
32
+ expect(results).to match_array([Set[1], Set[2]])
33
33
  end
34
34
 
35
35
  it "should return [[1, 2]] for [1, 2].choose(2).to_a" do
36
36
  set = subject[1, 2]
37
37
  results = set.choose(2).to_a
38
38
 
39
- results.should == [Set[1, 2]]
39
+ expect(results).to eq([Set[1, 2]])
40
40
  end
41
41
 
42
42
  it "should filter out repeated elements" do
43
43
  set1 = subject[1,1,2,3]
44
44
  set2 = subject[1,2,3]
45
45
 
46
- set1.choose(2).to_a.should == set2.choose(2).to_a
46
+ expect(set1.choose(2).to_a).to eq(set2.choose(2).to_a)
47
47
  end
48
48
  end
@@ -3,6 +3,6 @@ require 'combinatorics/version'
3
3
 
4
4
  describe Combinatorics do
5
5
  it "should have a VERSION constant" do
6
- subject.const_get('VERSION').should_not be_empty
6
+ expect(subject.const_get('VERSION')).not_to be_empty
7
7
  end
8
8
  end
@@ -1,9 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'combinatorics/derange/cardinality'
3
3
 
4
- describe Derange do
5
- subject { Derange }
6
-
4
+ describe Combinatorics::Derange do
7
5
  it "should alias cardinality to subfactorial" do
8
6
  should respond_to(:cardinality)
9
7
  end
@@ -7,28 +7,28 @@ shared_examples_for "Derange::Mixin" do
7
7
  set = subject[]
8
8
  results = set.derange.to_a
9
9
 
10
- results.should == [[]]
10
+ expect(results).to eq([[]])
11
11
  end
12
12
 
13
13
  it "should return [[]] for [1].derange.to_a" do
14
14
  set = subject[1]
15
15
  results = set.derange.to_a
16
16
 
17
- results.should == [[]]
17
+ expect(results).to eq([[]])
18
18
  end
19
19
 
20
20
  it "should return [[2, 1]] for [1, 2].derange.to_a" do
21
21
  set = subject[1, 2]
22
22
  results = set.derange.to_a
23
23
 
24
- results.should == [[2, 1]]
24
+ expect(results).to eq([[2, 1]])
25
25
  end
26
26
 
27
27
  it "should return [[2, 1, 4, 3], [2, 3, 4, 1], [2, 4, 1, 3], [3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 3, 1, 2], [4, 3, 2, 1]] for [1, 2, 3, 4].derange.to_a" do
28
28
  set = [1, 2, 3, 4]
29
29
  results = set.derange.to_a
30
30
 
31
- results.should == [
31
+ expect(results).to eq([
32
32
  [2, 1, 4, 3],
33
33
  [2, 3, 4, 1],
34
34
  [2, 4, 1, 3],
@@ -38,7 +38,7 @@ shared_examples_for "Derange::Mixin" do
38
38
  [4, 1, 2, 3],
39
39
  [4, 3, 1, 2],
40
40
  [4, 3, 2, 1]
41
- ]
41
+ ])
42
42
  end
43
43
 
44
44
  it "should take an optional block argument" do
@@ -47,6 +47,6 @@ shared_examples_for "Derange::Mixin" do
47
47
 
48
48
  set.derange { |deranged| results << deranged }
49
49
 
50
- results.should == [[2, 3, 1], [3, 1, 2]]
50
+ expect(results).to eq([[2, 3, 1], [3, 1, 2]])
51
51
  end
52
52
  end
@@ -3,6 +3,6 @@ require 'combinatorics/enumerator'
3
3
 
4
4
  describe Combinatorics::Enumerator do
5
5
  it "should auto-detect the Enumerator class" do
6
- Combinatorics::Enumerator.should_not be_nil
6
+ expect(Combinatorics::Enumerator).not_to be_nil
7
7
  end
8
8
  end