array_pair 0.1.0 → 0.2.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.
- data/VERSION +1 -1
- data/array_pair.gemspec +50 -0
- data/lib/array_pair.rb +16 -0
- data/test/test_array_pair.rb +19 -0
- metadata +38 -19
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/array_pair.gemspec
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{array_pair}
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ben J Woodcroft"]
|
12
|
+
s.date = %q{2011-06-07}
|
13
|
+
s.description = %q{random useful methods for working with Ruby arrays and hashes}
|
14
|
+
s.email = %q{donttrustben near gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"array_pair.gemspec",
|
26
|
+
"lib/array_pair.rb",
|
27
|
+
"test/helper.rb",
|
28
|
+
"test/test_array_pair.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/wwood/array_pair}
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.6.1}
|
33
|
+
s.summary = %q{random useful methods for working with Ruby arrays, hashes and objects}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
40
|
+
s.add_runtime_dependency(%q<rsruby>, [">= 0"])
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
43
|
+
s.add_dependency(%q<rsruby>, [">= 0"])
|
44
|
+
end
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
47
|
+
s.add_dependency(%q<rsruby>, [">= 0"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
data/lib/array_pair.rb
CHANGED
@@ -221,6 +221,22 @@ class Array
|
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
224
|
+
# Like each_lower_triangular_matrix, except iterate over 4 items at once, not 2.
|
225
|
+
def each_lower_triangular_4d_matrix
|
226
|
+
each_with_index do |e1, i1|
|
227
|
+
each_with_index do |e2, i2|
|
228
|
+
next unless i2 > i1
|
229
|
+
each_with_index do |e3, i3|
|
230
|
+
next unless i3 > i2
|
231
|
+
each_with_index do |e4, i4|
|
232
|
+
next unless i4 > i3
|
233
|
+
yield e1, e2, e3, e4
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
224
240
|
# like uniq -c for unix
|
225
241
|
def uniq_count
|
226
242
|
hash = {}
|
data/test/test_array_pair.rb
CHANGED
@@ -111,6 +111,25 @@ class ArrayPairTest < Test::Unit::TestCase
|
|
111
111
|
assert_equal 4, gained.length
|
112
112
|
end
|
113
113
|
|
114
|
+
def test_each_lower_triangular_4d_matrix
|
115
|
+
gained = []
|
116
|
+
[].each_lower_triangular_4d_matrix { |i,j,k,l| gained.push([i,j,k,l]) }
|
117
|
+
assert_equal [], gained
|
118
|
+
|
119
|
+
gained = []
|
120
|
+
[1,2,3,4].each_lower_triangular_4d_matrix { |i,j,k,l| gained.push([i,j,k,l]) }
|
121
|
+
assert_equal [[1,2,3,4]], gained
|
122
|
+
|
123
|
+
gained = []
|
124
|
+
[1,2,3,4,5].each_lower_triangular_4d_matrix { |i,j,k,l| gained.push([i,j,k,l]) }
|
125
|
+
assert_equal [1,2,3,4], gained[0]
|
126
|
+
assert_equal [1,2,3,5], gained[1]
|
127
|
+
assert_equal [1,2,4,5], gained[2]
|
128
|
+
assert_equal [1,3,4,5], gained[3]
|
129
|
+
assert_equal [2,3,4,5], gained[4]
|
130
|
+
assert_equal 5, gained.length
|
131
|
+
end
|
132
|
+
|
114
133
|
def test_standard_deviation
|
115
134
|
assert_nil [].standard_deviation
|
116
135
|
assert_equal 1.0, [1,2,3].standard_deviation
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: array_pair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Ben J Woodcroft
|
@@ -9,29 +15,37 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-06-07 00:00:00 +10:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: thoughtbot-shoulda
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
23
32
|
version: "0"
|
24
|
-
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
25
35
|
- !ruby/object:Gem::Dependency
|
26
36
|
name: rsruby
|
27
|
-
|
28
|
-
|
29
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
30
40
|
requirements:
|
31
41
|
- - ">="
|
32
42
|
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
33
46
|
version: "0"
|
34
|
-
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
description: random useful methods for working with Ruby arrays and hashes
|
36
50
|
email: donttrustben near gmail.com
|
37
51
|
executables: []
|
@@ -43,11 +57,11 @@ extra_rdoc_files:
|
|
43
57
|
- README.rdoc
|
44
58
|
files:
|
45
59
|
- .document
|
46
|
-
- .gitignore
|
47
60
|
- LICENSE
|
48
61
|
- README.rdoc
|
49
62
|
- Rakefile
|
50
63
|
- VERSION
|
64
|
+
- array_pair.gemspec
|
51
65
|
- lib/array_pair.rb
|
52
66
|
- test/helper.rb
|
53
67
|
- test/test_array_pair.rb
|
@@ -56,29 +70,34 @@ homepage: http://github.com/wwood/array_pair
|
|
56
70
|
licenses: []
|
57
71
|
|
58
72
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
73
|
+
rdoc_options: []
|
74
|
+
|
61
75
|
require_paths:
|
62
76
|
- lib
|
63
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
64
79
|
requirements:
|
65
80
|
- - ">="
|
66
81
|
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
67
85
|
version: "0"
|
68
|
-
version:
|
69
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
70
88
|
requirements:
|
71
89
|
- - ">="
|
72
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
73
94
|
version: "0"
|
74
|
-
version:
|
75
95
|
requirements: []
|
76
96
|
|
77
97
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.6.1
|
79
99
|
signing_key:
|
80
100
|
specification_version: 3
|
81
101
|
summary: random useful methods for working with Ruby arrays, hashes and objects
|
82
|
-
test_files:
|
83
|
-
|
84
|
-
- test/test_array_pair.rb
|
102
|
+
test_files: []
|
103
|
+
|