permutation 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGES +4 -0
  2. data/Rakefile +5 -5
  3. data/VERSION +1 -1
  4. data/lib/permutation.rb +2 -5
  5. data/test/test.rb +223 -217
  6. metadata +29 -25
  7. data/make_doc.rb +0 -6
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 2006-03-11 (0.1.4)
2
+ * Applied two bugfixes. Thanks go to Roel Harbers <roel@roelharbers.com>
3
+ for the report.
4
+ * Disabled autorequire for gem.
1
5
  2004-07-16 (0.1.3)
2
6
  * Moved gemspec into Rakefile
3
7
  * Cleaned up a bit.
data/Rakefile CHANGED
@@ -5,9 +5,7 @@ include Config
5
5
 
6
6
  PKG_NAME = 'permutation'
7
7
  PKG_VERSION = File.read('VERSION').chomp
8
- PKG_FILES = Dir.glob("**/*").delete_if { |item|
9
- item.include?("CVS") or item.include?("pkg")
10
- }
8
+ PKG_FILES = FileList["**/*"].exclude(/(CVS|pkg|doc)/)
11
9
 
12
10
  desc "Installing library"
13
11
  task :install do
@@ -31,7 +29,7 @@ spec = Gem::Specification.new do |s|
31
29
  s.name = 'permutation'
32
30
  s.version = PKG_VERSION
33
31
  s.summary = 'Permutation library in pure Ruby'
34
- s.description = ""
32
+ s.description = "Library to perform different operations with permutations of sequences (strings, arrays, etc.)"
35
33
 
36
34
  #### Dependencies and requirements.
37
35
 
@@ -47,7 +45,7 @@ spec = Gem::Specification.new do |s|
47
45
  #### Load-time details: library and application (you will need one or both).
48
46
 
49
47
  s.require_path = 'lib' # Use these for libraries.
50
- s.autorequire = 'permutation'
48
+ #s.autorequire = 'permutation'
51
49
 
52
50
  #s.bindir = "bin" # Use these for applications.
53
51
  #s.executables = ["bla.rb"]
@@ -75,4 +73,6 @@ Rake::GemPackageTask.new(spec) do |pkg|
75
73
  pkg.need_tar = true
76
74
  pkg.package_files += PKG_FILES
77
75
  end
76
+
77
+ task :release => :package
78
78
  # vim: set et sw=2 ts=2:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -184,10 +184,7 @@ class Permutation
184
184
  # Permutation#value method of this instance is the permutation ranked with
185
185
  # this new <code>rank</code>.
186
186
  def rank=(m)
187
- last = factorial(size) - 1
188
- while m > last do m -= last end
189
- while m < 0 do m += last end
190
- @rank = m
187
+ @rank = m % factorial(size)
191
188
  end
192
189
 
193
190
  # Returns the indices in the range of 0 to Permutation#size - 1
@@ -262,7 +259,7 @@ class Permutation
262
259
  # Switches this Permutation instance to random permutation
263
260
  # of size Permutation#size.
264
261
  def random!
265
- new_rank = rand(last).to_i
262
+ new_rank = rand(last + 1).to_i
266
263
  self.rank = new_rank
267
264
  self
268
265
  end
@@ -4,244 +4,250 @@ require 'test/unit'
4
4
  require 'permutation'
5
5
 
6
6
  class TC_Permutation < Test::Unit::TestCase
7
-
8
- def setup
9
- @perms = (0..4).map { |i| Permutation.new(i) }
10
- @perms_collections = [ "", "a", "ab", "abc", "abcd" ].map do |c|
11
- Permutation.for(c)
12
- end
13
- @perms_each = [
14
- [[]],
15
- [[0]],
16
- [[0, 1], [1, 0]],
17
- [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]],
18
- [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1],
19
- [0, 3, 1, 2], [0, 3, 2, 1], [1, 0, 2, 3], [1, 0, 3, 2],
20
- [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0],
21
- [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0],
22
- [2, 3, 0, 1], [2, 3, 1, 0], [3, 0, 1, 2], [3, 0, 2, 1],
23
- [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]]
24
- ]
25
- @next_pred = [
26
- [ [], [] ],
27
- [ [ 0 ], [ 0 ] ],
28
- [ [ 0, 1 ], [ 1, 0 ] ],
29
- [ [ 1, 0 ], [ 0, 1 ] ],
30
- [ [ 0, 1, 2 ], [ 0, 2, 1 ] ],
31
- [ [ 0, 2, 1 ], [ 1, 0, 2 ] ],
32
- [ [ 1, 0, 2 ], [ 1, 2, 0 ] ],
33
- [ [ 1, 2, 0 ], [ 2, 0, 1 ] ],
34
- [ [ 2, 0, 1 ], [ 2, 1, 0 ] ],
35
- [ [ 2, 1, 0 ], [ 0, 1, 2 ] ],
36
- ]
37
- @projected = [
38
- [ "" ],
39
- [ "a" ],
40
- [ "ab", "ba", ],
41
- [ "abc", "acb", "bac", "bca", "cab", "cba" ],
42
- [ "abcd", "abdc", "acbd", "acdb", "adbc", "adcb", "bacd",
43
- "badc", "bcad", "bcda", "bdac", "bdca", "cabd", "cadb",
44
- "cbad", "cbda", "cdab", "cdba", "dabc", "dacb", "dbac",
45
- "dbca", "dcab", "dcba"]
46
- ]
47
- @products = [
48
- {[0, 0]=>[]},
49
- {[0, 0]=>[0]},
50
- {[0, 0]=>[0, 1], [1, 1]=>[0, 1], [1, 0]=>[1, 0], [0, 1]=>[1, 0]},
51
- {[2, 4]=>[2, 1, 0], [1, 2]=>[2, 0, 1], [0, 0]=>[0, 1, 2],
52
- [5, 4]=>[0, 2, 1], [3, 3]=>[2, 0, 1], [2, 1]=>[1, 2, 0],
53
- [0, 5]=>[2, 1, 0], [3, 5]=>[0, 2, 1], [1, 1]=>[0, 1, 2],
54
- [0, 3]=>[1, 2, 0], [5, 3]=>[1, 0, 2], [4, 1]=>[2, 1, 0],
55
- [3, 2]=>[2, 1, 0], [2, 0]=>[1, 0, 2], [0, 4]=>[2, 0, 1],
56
- [3, 4]=>[0, 1, 2], [1, 0]=>[0, 2, 1], [0, 2]=>[1, 0, 2],
57
- [5, 2]=>[1, 2, 0], [4, 0]=>[2, 0, 1], [3, 1]=>[1, 0, 2],
58
- [2, 3]=>[0, 2, 1], [1, 5]=>[1, 2, 0], [4, 5]=>[1, 0, 2],
59
- [5, 1]=>[2, 0, 1], [4, 3]=>[0, 1, 2], [3, 0]=>[1, 2, 0],
60
- [2, 2]=>[0, 1, 2], [1, 4]=>[1, 0, 2], [4, 4]=>[1, 2, 0],
61
- [5, 0]=>[2, 1, 0], [4, 2]=>[0, 2, 1], [2, 5]=>[2, 0, 1],
62
- [1, 3]=>[2, 1, 0], [0, 1]=>[0, 2, 1], [5, 5]=>[0, 1, 2]}
63
- ]
64
- @cycles = [
65
- [[]],
66
- [[]],
67
- [[], [[0, 1]]],
68
- [[], [[1, 2]], [[0, 1]], [[0, 1, 2]], [[0, 2, 1]], [[0, 2]]],
69
- [[], [[2, 3]], [[1, 2]], [[1, 2, 3]], [[1, 3, 2]], [[1, 3]],
70
- [[0, 1]], [[0, 1], [2, 3]], [[0, 1, 2]], [[0, 1, 2, 3]],
71
- [[0, 1, 3, 2]], [[0, 1, 3]], [[0, 2, 1]], [[0, 2, 3, 1]],
72
- [[0, 2]], [[0, 2, 3]], [[0, 2], [1, 3]], [[0, 2, 1, 3]],
73
- [[0, 3, 2, 1]], [[0, 3, 1]], [[0, 3, 2]], [[0, 3]],
74
- [[0, 3, 1, 2]], [[0, 3], [1, 2]]]
75
- ]
76
- @signum = [
77
- [1],
78
- [1],
79
- [1, -1],
80
- [1, -1, -1, 1, 1, -1],
81
- [1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1,
82
- -1, 1, 1, -1, -1, 1]
83
- ]
7
+ def setup
8
+ @perms = (0..4).map { |i| Permutation.new(i) }
9
+ @perms_collections = [ "", "a", "ab", "abc", "abcd" ].map do |c|
10
+ Permutation.for(c)
84
11
  end
12
+ @perms_each = [
13
+ [[]],
14
+ [[0]],
15
+ [[0, 1], [1, 0]],
16
+ [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]],
17
+ [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1],
18
+ [0, 3, 1, 2], [0, 3, 2, 1], [1, 0, 2, 3], [1, 0, 3, 2],
19
+ [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0],
20
+ [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0],
21
+ [2, 3, 0, 1], [2, 3, 1, 0], [3, 0, 1, 2], [3, 0, 2, 1],
22
+ [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]]
23
+ ]
24
+ @next_pred = [
25
+ [ [], [] ],
26
+ [ [ 0 ], [ 0 ] ],
27
+ [ [ 0, 1 ], [ 1, 0 ] ],
28
+ [ [ 1, 0 ], [ 0, 1 ] ],
29
+ [ [ 0, 1, 2 ], [ 0, 2, 1 ] ],
30
+ [ [ 0, 2, 1 ], [ 1, 0, 2 ] ],
31
+ [ [ 1, 0, 2 ], [ 1, 2, 0 ] ],
32
+ [ [ 1, 2, 0 ], [ 2, 0, 1 ] ],
33
+ [ [ 2, 0, 1 ], [ 2, 1, 0 ] ],
34
+ [ [ 2, 1, 0 ], [ 0, 1, 2 ] ],
35
+ ]
36
+ @projected = [
37
+ [ "" ],
38
+ [ "a" ],
39
+ [ "ab", "ba", ],
40
+ [ "abc", "acb", "bac", "bca", "cab", "cba" ],
41
+ [ "abcd", "abdc", "acbd", "acdb", "adbc", "adcb", "bacd",
42
+ "badc", "bcad", "bcda", "bdac", "bdca", "cabd", "cadb",
43
+ "cbad", "cbda", "cdab", "cdba", "dabc", "dacb", "dbac",
44
+ "dbca", "dcab", "dcba"]
45
+ ]
46
+ @products = [
47
+ {[0, 0]=>[]},
48
+ {[0, 0]=>[0]},
49
+ {[0, 0]=>[0, 1], [1, 1]=>[0, 1], [1, 0]=>[1, 0], [0, 1]=>[1, 0]},
50
+ {[2, 4]=>[2, 1, 0], [1, 2]=>[2, 0, 1], [0, 0]=>[0, 1, 2],
51
+ [5, 4]=>[0, 2, 1], [3, 3]=>[2, 0, 1], [2, 1]=>[1, 2, 0],
52
+ [0, 5]=>[2, 1, 0], [3, 5]=>[0, 2, 1], [1, 1]=>[0, 1, 2],
53
+ [0, 3]=>[1, 2, 0], [5, 3]=>[1, 0, 2], [4, 1]=>[2, 1, 0],
54
+ [3, 2]=>[2, 1, 0], [2, 0]=>[1, 0, 2], [0, 4]=>[2, 0, 1],
55
+ [3, 4]=>[0, 1, 2], [1, 0]=>[0, 2, 1], [0, 2]=>[1, 0, 2],
56
+ [5, 2]=>[1, 2, 0], [4, 0]=>[2, 0, 1], [3, 1]=>[1, 0, 2],
57
+ [2, 3]=>[0, 2, 1], [1, 5]=>[1, 2, 0], [4, 5]=>[1, 0, 2],
58
+ [5, 1]=>[2, 0, 1], [4, 3]=>[0, 1, 2], [3, 0]=>[1, 2, 0],
59
+ [2, 2]=>[0, 1, 2], [1, 4]=>[1, 0, 2], [4, 4]=>[1, 2, 0],
60
+ [5, 0]=>[2, 1, 0], [4, 2]=>[0, 2, 1], [2, 5]=>[2, 0, 1],
61
+ [1, 3]=>[2, 1, 0], [0, 1]=>[0, 2, 1], [5, 5]=>[0, 1, 2]}
62
+ ]
63
+ @cycles = [
64
+ [[]],
65
+ [[]],
66
+ [[], [[0, 1]]],
67
+ [[], [[1, 2]], [[0, 1]], [[0, 1, 2]], [[0, 2, 1]], [[0, 2]]],
68
+ [[], [[2, 3]], [[1, 2]], [[1, 2, 3]], [[1, 3, 2]], [[1, 3]],
69
+ [[0, 1]], [[0, 1], [2, 3]], [[0, 1, 2]], [[0, 1, 2, 3]],
70
+ [[0, 1, 3, 2]], [[0, 1, 3]], [[0, 2, 1]], [[0, 2, 3, 1]],
71
+ [[0, 2]], [[0, 2, 3]], [[0, 2], [1, 3]], [[0, 2, 1, 3]],
72
+ [[0, 3, 2, 1]], [[0, 3, 1]], [[0, 3, 2]], [[0, 3]],
73
+ [[0, 3, 1, 2]], [[0, 3], [1, 2]]]
74
+ ]
75
+ @signum = [
76
+ [1],
77
+ [1],
78
+ [1, -1],
79
+ [1, -1, -1, 1, 1, -1],
80
+ [1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, 1, -1,
81
+ -1, 1, 1, -1, -1, 1]
82
+ ]
83
+ end
85
84
 
86
- def test_created
87
- factorial = 1
88
- @perms.each_with_index do |p, i|
89
- assert_equal(i, p.size)
90
- assert_equal(factorial - 1, p.last)
91
- factorial *= (i + 1)
92
- end
85
+ def test_created
86
+ factorial = 1
87
+ @perms.each_with_index do |p, i|
88
+ assert_equal(i, p.size)
89
+ assert_equal(factorial - 1, p.last)
90
+ factorial *= (i + 1)
93
91
  end
92
+ end
94
93
 
95
- def test_rank_assign
96
- perm = Permutation.new(3)
97
- perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1],
98
- [2, 1, 0]]
99
- (-5...0).each do |i|
100
- perm.rank = i
101
- assert_equal(perms[i + 5], perm.value)
102
- end
103
- (-10...-5).each do |i|
104
- perm.rank = i
105
- assert_equal(perms[i + 10], perm.value)
106
- end
107
- (0..5).each do |i|
108
- perm.rank = i
109
- assert_equal(perms[i], perm.value)
110
- end
111
- (6..10).each do |i|
112
- perm.rank = i
113
- assert_equal(perms[i - 5], perm.value)
114
- end
115
- (11..15).each do |i|
116
- perm.rank = i
117
- assert_equal(perms[i - 10], perm.value)
118
- end
94
+ def test_rank_assign
95
+ perm = Permutation.new(3)
96
+ perms = [
97
+ [0, 1, 2],
98
+ [0, 2, 1],
99
+ [1, 0, 2],
100
+ [1, 2, 0],
101
+ [2, 0, 1],
102
+ [2, 1, 0],
103
+ [0, 1, 2],
104
+ ]
105
+ (-12...-6).each do |i|
106
+ perm.rank = i
107
+ assert_equal(perms[i + 12], perm.value)
119
108
  end
120
-
121
- def test_compare
122
- perm1 = Permutation.new(3)
123
- perm2 = Permutation.new(3)
124
- perm3 = perm1.dup
125
- perm4 = Permutation.new(3, 1)
126
- assert(!perm1.equal?(perm2))
127
- assert(perm1 == perm2)
128
- assert(perm1.eql?(perm2))
129
- assert_equal(0, perm1 <=> perm2)
130
- assert_equal(perm1.hash, perm2.hash)
131
- assert(!perm1.equal?(perm3))
132
- assert(perm1 == perm3)
133
- assert(perm1.eql?(perm3))
134
- assert_equal(0, perm1 <=> perm3)
135
- assert_equal(perm1.hash, perm3.hash)
136
- assert(!perm1.equal?(perm4))
137
- assert(perm1 != perm4)
138
- assert(!perm1.eql?(perm4))
139
- assert_equal(-1, perm1 <=> perm4)
140
- assert_equal(1, perm4 <=> perm1)
141
- assert(perm1 < perm4)
142
- assert(perm4 > perm1)
143
- assert(perm1.hash != perm4.hash)
144
- perms = perm1.to_a
145
- perms[1..-1].each_with_index do |p, i|
146
- assert(p > perms[i])
147
- assert_equal(1, p <=> perms[i])
148
- assert(perms[i] < p)
149
- assert_equal(-1, perms[i] <=> p)
150
- end
109
+ (-6...0).each do |i|
110
+ perm.rank = i
111
+ assert_equal(perms[i + 6], perm.value)
112
+ end
113
+ (0..6).each do |i|
114
+ perm.rank = i
115
+ assert_equal(perms[i], perm.value)
116
+ end
117
+ (6..12).each do |i|
118
+ perm.rank = i
119
+ assert_equal(perms[i - 6], perm.value)
120
+ end
121
+ (12..17).each do |i|
122
+ perm.rank = i
123
+ assert_equal(perms[i - 12], perm.value)
151
124
  end
125
+ end
152
126
 
153
- def test_random
154
- @perms_each.each_with_index do |perms, i|
155
- perm = Permutation.new(i)
156
- 24.times do
157
- assert(perms.member?(perm.random.value))
158
- end
159
- end
127
+ def test_compare
128
+ perm1 = Permutation.new(3)
129
+ perm2 = Permutation.new(3)
130
+ perm3 = perm1.dup
131
+ perm4 = Permutation.new(3, 1)
132
+ assert(!perm1.equal?(perm2))
133
+ assert(perm1 == perm2)
134
+ assert(perm1.eql?(perm2))
135
+ assert_equal(0, perm1 <=> perm2)
136
+ assert_equal(perm1.hash, perm2.hash)
137
+ assert(!perm1.equal?(perm3))
138
+ assert(perm1 == perm3)
139
+ assert(perm1.eql?(perm3))
140
+ assert_equal(0, perm1 <=> perm3)
141
+ assert_equal(perm1.hash, perm3.hash)
142
+ assert(!perm1.equal?(perm4))
143
+ assert(perm1 != perm4)
144
+ assert(!perm1.eql?(perm4))
145
+ assert_equal(-1, perm1 <=> perm4)
146
+ assert_equal(1, perm4 <=> perm1)
147
+ assert(perm1 < perm4)
148
+ assert(perm4 > perm1)
149
+ assert(perm1.hash != perm4.hash)
150
+ perms = perm1.to_a
151
+ perms[1..-1].each_with_index do |p, i|
152
+ assert(p > perms[i])
153
+ assert_equal(1, p <=> perms[i])
154
+ assert(perms[i] < p)
155
+ assert_equal(-1, perms[i] <=> p)
160
156
  end
157
+ end
161
158
 
162
- def test_enumerable
163
- @perms.each_with_index do |perm, i|
164
- assert_equal(@perms_each[i], perm.map { |x| x.value })
165
- end
166
- @perms.each_with_index do |perm, i|
167
- ary = []
168
- old_rank = perm.rank
169
- perm.each! { |x| ary << x.value }
170
- assert_equal(@perms_each[i], ary)
171
- assert_equal(old_rank, perm.rank)
172
- end
159
+ def test_random
160
+ @perms_each.each_with_index do |perms, i|
161
+ perm = Permutation.new(i)
162
+ until perms.empty?
163
+ deleted = perms.delete perm.random.value
164
+ deleted and assert true
165
+ end
173
166
  end
167
+ end
174
168
 
175
- def test_next
176
- @next_pred.each do |before, after|
177
- beforep = Permutation.from_value(before)
178
- afterp = Permutation.from_value(after)
179
- assert_equal(afterp, beforep.next)
180
- assert_equal(beforep, afterp.pred)
181
- assert_equal(afterp, beforep.succ)
182
- end
169
+ def test_enumerable
170
+ @perms.each_with_index do |perm, i|
171
+ assert_equal(@perms_each[i], perm.map { |x| x.value })
183
172
  end
173
+ @perms.each_with_index do |perm, i|
174
+ ary = []
175
+ old_rank = perm.rank
176
+ perm.each! { |x| ary << x.value }
177
+ assert_equal(@perms_each[i], ary)
178
+ assert_equal(old_rank, perm.rank)
179
+ end
180
+ end
184
181
 
185
- def test_project
186
- too_big = Array.new(10)
187
- @perms.each_with_index do |perms, i|
188
- assert_equal(@projected[i],
189
- perms.map { |p| p.project(@projected[i][0]) })
190
- assert_raises(ArgumentError) { perms.project }
191
- assert_raises(ArgumentError) { perms.project(too_big) }
192
- end
193
- @perms_collections.each_with_index do |perms, i|
194
- assert_equal(@projected[i], perms.map { |p| p.project })
195
- end
182
+ def test_next
183
+ @next_pred.each do |before, after|
184
+ beforep = Permutation.from_value(before)
185
+ afterp = Permutation.from_value(after)
186
+ assert_equal(afterp, beforep.next)
187
+ assert_equal(beforep, afterp.pred)
188
+ assert_equal(afterp, beforep.succ)
196
189
  end
190
+ end
197
191
 
198
- def test_compose
199
- too_big = Permutation.new(10)
200
- @perms[0..3].each do |perm|
201
- elements = perm.to_a
202
- for i in 0...elements.size
203
- for j in 0...elements.size
204
- assert_equal(@products[perm.size][[i, j]],
205
- (elements[i].compose(elements[j])).value)
206
- assert_equal(@products[perm.size][[i, j]],
207
- (elements[i] * elements[j]).value)
208
- end
209
- assert_raises(ArgumentError) { elements[i] * too_big }
210
- assert_raises(ArgumentError) { elements[i].compose(too_big) }
211
- end
212
- end
192
+ def test_project
193
+ too_big = Array.new(10)
194
+ @perms.each_with_index do |perms, i|
195
+ assert_equal(@projected[i],
196
+ perms.map { |p| p.project(@projected[i][0]) })
197
+ assert_raises(ArgumentError) { perms.project }
198
+ assert_raises(ArgumentError) { perms.project(too_big) }
199
+ end
200
+ @perms_collections.each_with_index do |perms, i|
201
+ assert_equal(@projected[i], perms.map { |p| p.project })
213
202
  end
203
+ end
214
204
 
215
- def test_invert
216
- @perms.each do |perm|
217
- id = perm
218
- perm.each do |p|
219
- assert_equal(id.value, (p * p.invert).value)
220
- assert_equal(id, p * p.invert)
221
- assert_equal(id.value, (p * -p).value)
222
- assert_equal(id, p * -p)
223
- end
224
- end
205
+ def test_compose
206
+ too_big = Permutation.new(10)
207
+ @perms[0..3].each do |perm|
208
+ elements = perm.to_a
209
+ for i in 0...elements.size
210
+ for j in 0...elements.size
211
+ assert_equal(@products[perm.size][[i, j]],
212
+ (elements[i].compose(elements[j])).value)
213
+ assert_equal(@products[perm.size][[i, j]],
214
+ (elements[i] * elements[j]).value)
215
+ end
216
+ assert_raises(ArgumentError) { elements[i] * too_big }
217
+ assert_raises(ArgumentError) { elements[i].compose(too_big) }
218
+ end
225
219
  end
220
+ end
226
221
 
227
- def test_cycles
228
- @perms.each_with_index do |perm, i|
229
- assert_equal(@cycles[i], perm.map { |p| p.cycles })
230
- assert_equal(perm.to_a,
231
- @cycles[i].map { |c| Permutation.from_cycles(c, i) })
232
- end
222
+ def test_invert
223
+ @perms.each do |perm|
224
+ id = perm
225
+ perm.each do |p|
226
+ assert_equal(id.value, (p * p.invert).value)
227
+ assert_equal(id, p * p.invert)
228
+ assert_equal(id.value, (p * -p).value)
229
+ assert_equal(id, p * -p)
230
+ end
233
231
  end
232
+ end
234
233
 
235
- def test_signum
236
- @perms.each_with_index do |perm, i|
237
- assert_equal(@signum[i], perm.map { |p| p.signum })
238
- assert_equal(@signum[i], perm.map { |p| p.sgn })
239
- assert_equal(@signum[i].map { |x| x == 1 },
240
- perm.map { |p| p.even? })
241
- assert_equal(@signum[i].map { |x| x == -1 },
242
- perm.map { |p| p.odd? })
243
- end
234
+ def test_cycles
235
+ @perms.each_with_index do |perm, i|
236
+ assert_equal(@cycles[i], perm.map { |p| p.cycles })
237
+ assert_equal(perm.to_a,
238
+ @cycles[i].map { |c| Permutation.from_cycles(c, i) })
244
239
  end
240
+ end
245
241
 
242
+ def test_signum
243
+ @perms.each_with_index do |perm, i|
244
+ assert_equal(@signum[i], perm.map { |p| p.signum })
245
+ assert_equal(@signum[i], perm.map { |p| p.sgn })
246
+ assert_equal(@signum[i].map { |x| x == 1 },
247
+ perm.map { |p| p.even? })
248
+ assert_equal(@signum[i].map { |x| x == -1 },
249
+ perm.map { |p| p.odd? })
250
+ end
251
+ end
246
252
  end
247
- # vim: set et sw=4 ts=4:
253
+ # vim: set et sw=2 ts=2:
metadata CHANGED
@@ -3,50 +3,54 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: permutation
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.3
7
- date: 2005-10-05 00:00:00 +02:00
6
+ version: 0.1.4
7
+ date: 2006-03-11 00:00:00 +01:00
8
8
  summary: Permutation library in pure Ruby
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: flori@ping.de
12
12
  homepage: http://permutation.rubyforge.org
13
13
  rubyforge_project: permutation
14
- description: ''
15
- autorequire: permutation
14
+ description: Library to perform different operations with permutations of sequences (strings, arrays, etc.)
15
+ autorequire:
16
16
  default_executable:
17
17
  bindir: bin
18
18
  has_rdoc: true
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">"
23
- - !ruby/object:Gem::Version
24
- version: 0.0.0
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
25
24
  version:
26
25
  platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
29
28
  authors:
30
- - Florian Frank
29
+ - Florian Frank
31
30
  files:
32
- - examples
33
- - install.rb
34
- - GPL
35
- - test
36
- - Rakefile
37
- - VERSION
38
- - CHANGES
39
- - lib
40
- - make_doc.rb
41
- - README.en
42
- - examples/tsp.rb
43
- - test/test.rb
44
- - lib/permutation.rb
31
+ - examples
32
+ - install.rb
33
+ - GPL
34
+ - test
35
+ - Rakefile
36
+ - VERSION
37
+ - CHANGES
38
+ - lib
39
+ - README.en
40
+ - examples/tsp.rb
41
+ - test/test.rb
42
+ - lib/permutation.rb
45
43
  test_files:
46
- - test/test.rb
44
+ - test/test.rb
47
45
  rdoc_options: []
46
+
48
47
  extra_rdoc_files: []
48
+
49
49
  executables: []
50
+
50
51
  extensions: []
52
+
51
53
  requirements: []
52
- dependencies: []
54
+
55
+ dependencies: []
56
+
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $outdir = 'doc/'
4
- puts "Creating documentation in '#$outdir'."
5
- system "rdoc -d -o #$outdir lib/permutation.rb"
6
- # vim: set et sw=4 ts=4: