combinatorics 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +4 -5
- data/ChangeLog.md +5 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +1 -1
- data/README.md +144 -105
- data/Rakefile +6 -30
- data/combinatorics.gemspec +1 -0
- data/gemspec.yml +7 -3
- data/lib/combinatorics/choose/cardinality.rb +1 -1
- data/lib/combinatorics/generator.rb +1 -1
- data/lib/combinatorics/version.rb +1 -1
- data/spec/cartesian_product/cardinality_spec.rb +13 -13
- data/spec/cartesian_product/mixin_examples.rb +14 -14
- data/spec/choose/cardinality_spec.rb +31 -31
- data/spec/choose/mixin_examples.rb +6 -6
- data/spec/combinatorics_spec.rb +1 -1
- data/spec/derange/mixin_examples.rb +6 -6
- data/spec/enumerator_spec.rb +1 -1
- data/spec/extensions/math_spec.rb +19 -19
- data/spec/extensions/range_spec.rb +12 -12
- data/spec/generator_spec.rb +1 -1
- data/spec/list_comprehension_spec.rb +10 -10
- data/spec/permute/cardinality_spec.rb +28 -28
- data/spec/permute/mixin_examples.rb +5 -5
- data/spec/power_set/mixin_examples.rb +4 -4
- data/spec/spec_helper.rb +0 -2
- metadata +26 -57
@@ -6,117 +6,117 @@ describe Permute do
|
|
6
6
|
|
7
7
|
describe "cardinality" do
|
8
8
|
it "should raise RangeError if n is negative without passing r" do
|
9
|
-
|
9
|
+
expect { subject.cardinality(-1) }.to raise_error(RangeError)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should raise RangeError if n is negative when r is provided" do
|
13
|
-
|
13
|
+
expect { subject.cardinality(-1, 1) }.to raise_error(RangeError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should raise RangeError if r is negative" do
|
17
|
-
|
17
|
+
expect { subject.cardinality(1, -1) }.to raise_error(RangeError)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should raise RangeError if r is greater than n" do
|
21
|
-
|
21
|
+
expect { subject.cardinality(2, 3) }.to raise_error(RangeError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should return 1 for subject.cardinality(0)" do
|
25
|
-
subject.cardinality(0).
|
25
|
+
expect(subject.cardinality(0)).to eq(1)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should return 1 for subject.cardinality(1)" do
|
29
|
-
subject.cardinality(1).
|
29
|
+
expect(subject.cardinality(1)).to eq(1)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return 2 for subject.cardinality(2)" do
|
33
|
-
subject.cardinality(2).
|
33
|
+
expect(subject.cardinality(2)).to eq(2)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should return 6 for subject.cardinality(3)" do
|
37
|
-
subject.cardinality(3).
|
37
|
+
expect(subject.cardinality(3)).to eq(6)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should return 24 for subject.cardinality(4)" do
|
41
|
-
subject.cardinality(4).
|
41
|
+
expect(subject.cardinality(4)).to eq(24)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should return 0 for subject.cardinality(1, 0)" do
|
45
|
-
subject.cardinality(1, 0).
|
45
|
+
expect(subject.cardinality(1, 0)).to eq(0)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should return 1 for subject.cardinality(1, 1)" do
|
49
|
-
subject.cardinality(1, 1).
|
49
|
+
expect(subject.cardinality(1, 1)).to eq(1)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "should return 2 for subject.cardinality(2, 1)" do
|
53
|
-
subject.cardinality(2, 1).
|
53
|
+
expect(subject.cardinality(2, 1)).to eq(2)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "should return 1 for subject.cardinality(2, 2)" do
|
57
|
-
subject.cardinality(2, 2).
|
57
|
+
expect(subject.cardinality(2, 2)).to eq(2)
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should return 3 for subject.cardinality(3, 1)" do
|
61
|
-
subject.cardinality(3, 1).
|
61
|
+
expect(subject.cardinality(3, 1)).to eq(3)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should return 3 for subject.cardinality(3, 2)" do
|
65
|
-
subject.cardinality(3, 2).
|
65
|
+
expect(subject.cardinality(3, 2)).to eq(6)
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should return 1 for subject.cardinality(3, 3)" do
|
69
|
-
subject.cardinality(3, 3).
|
69
|
+
expect(subject.cardinality(3, 3)).to eq(6)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should return 4 for subject.cardinality(4, 1)" do
|
73
|
-
subject.cardinality(4, 1).
|
73
|
+
expect(subject.cardinality(4, 1)).to eq(4)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should return 12 for subject.cardinality(4, 2)" do
|
77
|
-
subject.cardinality(4, 2).
|
77
|
+
expect(subject.cardinality(4, 2)).to eq(12)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should return 24 for subject.cardinality(4, 3)" do
|
81
|
-
subject.cardinality(4, 3).
|
81
|
+
expect(subject.cardinality(4, 3)).to eq(24)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should return 1 for subject.cardinality(4, 4)" do
|
85
|
-
subject.cardinality(4, 4).
|
85
|
+
expect(subject.cardinality(4, 4)).to eq(24)
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should return 360 for subject.cardinality(6, 4)" do
|
89
|
-
subject.cardinality(6, 4).
|
89
|
+
expect(subject.cardinality(6, 4)).to eq(360)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should return 3628800 for subject.cardinality(10)" do
|
93
|
-
subject.cardinality(10).
|
93
|
+
expect(subject.cardinality(10)).to eq(3628800)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
describe "cardinality_all" do
|
98
98
|
it "should return [] for cardinality_all(0)" do
|
99
|
-
subject.cardinality_all(0).
|
99
|
+
expect(subject.cardinality_all(0)).to be_empty
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should return [1] for cardinality_all(1)" do
|
103
|
-
subject.cardinality_all(1).
|
103
|
+
expect(subject.cardinality_all(1)).to eq([1])
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should return [2, 1] for cardinality_all(2)" do
|
107
|
-
subject.cardinality_all(2).
|
107
|
+
expect(subject.cardinality_all(2)).to eq([2, 2])
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should return [3, 6, 1] for cardinality_all(3)" do
|
111
|
-
subject.cardinality_all(3).
|
111
|
+
expect(subject.cardinality_all(3)).to eq([3, 6, 6])
|
112
112
|
end
|
113
113
|
|
114
114
|
it "should return [4, 12, 24, 1] for cardinality_all(4)" do
|
115
|
-
subject.cardinality_all(4).
|
115
|
+
expect(subject.cardinality_all(4)).to eq([4, 12, 24, 24])
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should raise RangeError for cardinality_all(-1)" do
|
119
|
-
|
119
|
+
expect { subject.cardinality_all(-1) }.to raise_error(RangeError)
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should wrap cardinality with Permute.N" do
|
@@ -8,35 +8,35 @@ shared_examples_for "Permute::Mixin" do
|
|
8
8
|
set = subject[]
|
9
9
|
results = set.permute(0).to_a
|
10
10
|
|
11
|
-
results.
|
11
|
+
expect(results).to eq([[]])
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return [[]] for [1].permute(0).to_a" do
|
15
15
|
set = subject[1]
|
16
16
|
results = set.permute(0).to_a
|
17
17
|
|
18
|
-
results.
|
18
|
+
expect(results).to eq([[]])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should return [[1]] for [1].permute(1).to_a" do
|
22
22
|
set = subject[1]
|
23
23
|
results = set.permute(1).to_a
|
24
24
|
|
25
|
-
results.
|
25
|
+
expect(results).to eq([[1]])
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should return [[1], [2]] for [1, 2].permute(1).to_a" do
|
29
29
|
set = subject[1, 2]
|
30
30
|
results = set.permute(1).to_a
|
31
31
|
|
32
|
-
results.
|
32
|
+
expect(results).to match_array([[1], [2]])
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return [[1, 2]] for [1, 2].permute(2).to_a" do
|
36
36
|
set = subject[1, 2]
|
37
37
|
results = set.permute(2).to_a
|
38
38
|
|
39
|
-
results.
|
39
|
+
expect(results).to match_array([[1, 2], [2, 1]])
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -8,13 +8,13 @@ shared_examples_for "PowerSet::Mixin" do
|
|
8
8
|
it "the powerset of an empty Set should only contain the empty Set" do
|
9
9
|
set = subject[]
|
10
10
|
|
11
|
-
set.powerset.to_a.
|
11
|
+
expect(set.powerset.to_a).to eq([empty_set])
|
12
12
|
end
|
13
13
|
|
14
14
|
it "the powerset of a single Set should contain that Set" do
|
15
15
|
set = subject[1]
|
16
16
|
|
17
|
-
set.powerset.to_a.
|
17
|
+
expect(set.powerset.to_a).to eq([empty_set, Set[*set]])
|
18
18
|
end
|
19
19
|
|
20
20
|
it "the powerset of a Set should all be subsets" do
|
@@ -23,12 +23,12 @@ shared_examples_for "PowerSet::Mixin" do
|
|
23
23
|
|
24
24
|
set.powerset { |subset| superset += subset }
|
25
25
|
|
26
|
-
superset.
|
26
|
+
expect(superset).to eq(Set[*set])
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should alias powerset to power_set" do
|
30
30
|
set = subject[1]
|
31
31
|
|
32
|
-
set.
|
32
|
+
expect(set).to respond_to(:power_set)
|
33
33
|
end
|
34
34
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,65 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combinatorics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Postmodern
|
9
8
|
- Duper
|
10
|
-
autorequire:
|
9
|
+
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 2022-01-17 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
15
|
+
name: bundler
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- - ~>
|
18
|
+
- - "~>"
|
21
19
|
- !ruby/object:Gem::Version
|
22
|
-
version: '0
|
20
|
+
version: '2.0'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- - ~>
|
25
|
+
- - "~>"
|
29
26
|
- !ruby/object:Gem::Version
|
30
|
-
version: '0
|
31
|
-
- !ruby/object:Gem::Dependency
|
32
|
-
name: rspec
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ~>
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '2.4'
|
39
|
-
type: :development
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '2.4'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: yard
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0.7'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: '0.7'
|
27
|
+
version: '2.0'
|
63
28
|
description: A collection of modules and methods for performing Combinatoric calculations.
|
64
29
|
email:
|
65
30
|
- postmodern.mod3@gmail.com
|
@@ -72,13 +37,15 @@ extra_rdoc_files:
|
|
72
37
|
- LICENSE.txt
|
73
38
|
- README.md
|
74
39
|
files:
|
75
|
-
- .document
|
76
|
-
- .gemtest
|
77
|
-
- .
|
78
|
-
- .
|
79
|
-
- .
|
40
|
+
- ".document"
|
41
|
+
- ".gemtest"
|
42
|
+
- ".github/workflows/ruby.yml"
|
43
|
+
- ".gitignore"
|
44
|
+
- ".rspec"
|
45
|
+
- ".yardopts"
|
80
46
|
- Benchmarks.md
|
81
47
|
- ChangeLog.md
|
48
|
+
- Gemfile
|
82
49
|
- LICENSE.txt
|
83
50
|
- README.md
|
84
51
|
- Rakefile
|
@@ -157,26 +124,28 @@ files:
|
|
157
124
|
homepage: https://github.com/postmodern/combinatorics#readme
|
158
125
|
licenses:
|
159
126
|
- MIT
|
160
|
-
|
127
|
+
metadata:
|
128
|
+
documentation_uri: https://rubydoc.info/gems/combinatorics
|
129
|
+
source_code_uri: https://github.com/postmodern/combinatorics.rb
|
130
|
+
bug_tracker_uri: https://github.com/postmodern/combinatorics.rb/issues
|
131
|
+
changelog_uri: https://github.com/postmodern/combinatorics.rb/blob/master/ChangeLog.md
|
132
|
+
post_install_message:
|
161
133
|
rdoc_options: []
|
162
134
|
require_paths:
|
163
135
|
- lib
|
164
136
|
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
-
none: false
|
166
137
|
requirements:
|
167
|
-
- -
|
138
|
+
- - ">="
|
168
139
|
- !ruby/object:Gem::Version
|
169
140
|
version: 1.8.7
|
170
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
-
none: false
|
172
142
|
requirements:
|
173
|
-
- -
|
143
|
+
- - ">="
|
174
144
|
- !ruby/object:Gem::Version
|
175
145
|
version: '0'
|
176
146
|
requirements: []
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
specification_version: 3
|
147
|
+
rubygems_version: 3.2.22
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
181
150
|
summary: Bringing (more) Combinatorics to Ruby
|
182
151
|
test_files: []
|