means 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 (6) hide show
  1. data/Gemfile +2 -2
  2. data/Gemfile.lock +10 -10
  3. data/VERSION +1 -1
  4. data/means.gemspec +8 -8
  5. data/spec/Mean_spec.rb +75 -84
  6. metadata +15 -15
data/Gemfile CHANGED
@@ -6,8 +6,8 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "rspec", "~> 2.3.0"
10
- gem "yard", "~> 0.6.0"
9
+ gem "rspec", "~> 2.7.0"
10
+ gem "yard", "~> 0.7.4"
11
11
  gem "bundler", "~> 1.0.0"
12
12
  gem "jeweler", "~> 1.6.4"
13
13
  gem "rcov", ">= 0"
data/Gemfile.lock CHANGED
@@ -9,15 +9,15 @@ GEM
9
9
  rake
10
10
  rake (0.9.2.2)
11
11
  rcov (0.9.11)
12
- rspec (2.3.0)
13
- rspec-core (~> 2.3.0)
14
- rspec-expectations (~> 2.3.0)
15
- rspec-mocks (~> 2.3.0)
16
- rspec-core (2.3.1)
17
- rspec-expectations (2.3.0)
12
+ rspec (2.7.0)
13
+ rspec-core (~> 2.7.0)
14
+ rspec-expectations (~> 2.7.0)
15
+ rspec-mocks (~> 2.7.0)
16
+ rspec-core (2.7.1)
17
+ rspec-expectations (2.7.0)
18
18
  diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.3.0)
20
- yard (0.6.8)
19
+ rspec-mocks (2.7.0)
20
+ yard (0.7.4)
21
21
 
22
22
  PLATFORMS
23
23
  ruby
@@ -26,5 +26,5 @@ DEPENDENCIES
26
26
  bundler (~> 1.0.0)
27
27
  jeweler (~> 1.6.4)
28
28
  rcov
29
- rspec (~> 2.3.0)
30
- yard (~> 0.6.0)
29
+ rspec (~> 2.7.0)
30
+ yard (~> 0.7.4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/means.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "means"
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nigel Lowry"]
12
- s.date = "2011-12-11"
12
+ s.date = "2012-01-02"
13
13
  s.description = "Calculates the different means for a data set (arithmetic, geometric and harmonic)."
14
14
  s.email = "nigel-lowry@ultra.eclipse.co.uk"
15
15
  s.extra_rdoc_files = [
@@ -40,21 +40,21 @@ Gem::Specification.new do |s|
40
40
  s.specification_version = 3
41
41
 
42
42
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
44
- s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
43
+ s.add_development_dependency(%q<rspec>, ["~> 2.7.0"])
44
+ s.add_development_dependency(%q<yard>, ["~> 0.7.4"])
45
45
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
46
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
47
47
  s.add_development_dependency(%q<rcov>, [">= 0"])
48
48
  else
49
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
50
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
49
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
50
+ s.add_dependency(%q<yard>, ["~> 0.7.4"])
51
51
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
52
52
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
53
53
  s.add_dependency(%q<rcov>, [">= 0"])
54
54
  end
55
55
  else
56
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
57
- s.add_dependency(%q<yard>, ["~> 0.6.0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.7.0"])
57
+ s.add_dependency(%q<yard>, ["~> 0.7.4"])
58
58
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
59
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
60
60
  s.add_dependency(%q<rcov>, [">= 0"])
data/spec/Mean_spec.rb CHANGED
@@ -1,110 +1,95 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Mean" do
4
-
5
- describe "#arithmetic" do
6
- it "should be nil for an empty array" do
7
- Mean.arithmetic([]).should be_nil
3
+ shared_examples_for "all means" do
4
+ [:arithmetic, :geometric, :harmonic].each do |mean|
5
+ it "is nil for an empty array" do
6
+ Mean.send(mean, []).should be_nil
8
7
  end
9
8
 
10
- it "should be the singleton element of a singleton array" do
9
+ it "is the singleton element of a singleton array" do
11
10
  element = 5.5
12
- Mean.arithmetic([element]).should == element
11
+ Mean.send(mean, [element]).should == element
13
12
  end
14
13
 
15
- it "should be the common value in an array when all values are equal" do
14
+ it "is the common value in an array when all values are equal" do
16
15
  element = 5.5
17
- Mean.arithmetic([element, element]).should == element
16
+ Mean.send(mean, [element, element]).should == element
17
+ end
18
+ end
19
+ end
20
+
21
+ shared_examples_for "non-arithmetic means" do
22
+ [:geometric, :harmonic].each do |mean|
23
+ it "is zero when there are any zeroes" do
24
+ data = [1.1, 2.2, 0.0]
25
+ Mean.send(mean, data).should == 0
18
26
  end
27
+ end
28
+ end
29
+
30
+ describe "Mean" do
31
+
32
+ describe ".arithmetic" do
33
+ it_behaves_like "all means"
19
34
 
20
- it "should be 1.5 for [1, 2]" do
35
+ it "is 1.5 for [1, 2]" do
21
36
  data = [1.0, 2.0]
22
37
  Mean.arithmetic(data).should be_within(0.01).of(1.5)
23
38
  end
24
39
 
25
- it "should work with integers" do
40
+ it "works with integers" do
26
41
  data = [1, 2]
27
42
  Mean.arithmetic(data).should be_within(0.01).of(1.5)
28
43
  end
29
44
 
30
- it "should work with an int then a float" do
45
+ it "works with an int then a float" do
31
46
  data = [1, 2.0]
32
47
  Mean.arithmetic(data).should be_within(0.01).of(1.5)
33
48
  end
34
49
 
35
- it "should work with a float then an int" do
50
+ it "works with a float then an int" do
36
51
  data = [1.0, 2]
37
52
  Mean.arithmetic(data).should be_within(0.01).of(1.5)
38
53
  end
39
54
 
40
- it "should work with three numbers" do
55
+ it "works with three numbers" do
41
56
  data = [1, 2, 3]
42
57
  Mean.arithmetic(data).should == 2
43
58
  end
44
59
  end
45
60
 
46
- describe "#geometric" do
47
- it "should be nil for an empty array" do
48
- Mean.geometric([]).should be_nil
49
- end
50
-
51
- it "should be the singleton element of a singleton array" do
52
- element = 5.5
53
- Mean.geometric([element]).should == element
54
- end
55
-
56
- it "should be the common value in a when all values are equal" do
57
- element = 5.5
58
- Mean.geometric([element, element]).should == element
59
- end
61
+ describe ".geometric" do
62
+ it_behaves_like "all means"
60
63
 
61
- it "should be zero when there is even a single zero" do
62
- data = [1.1, 2.2, 0.0]
63
- Mean.geometric(data).should == 0
64
- end
64
+ it_behaves_like "non-arithmetic means"
65
65
 
66
- it "should be the square root of the product of two numbers" do
66
+ it "is the square root of the product of two numbers" do
67
67
  d1, d2 = 2, 8
68
68
  data = [d1, d2]
69
- Mean.geometric(data).should == 4
69
+ Mean.geometric(data).should == Math.sqrt(d1 * d2)
70
70
  end
71
71
 
72
- it "should be the cube root of the product of three numbers" do
72
+ it "is the cube root of the product of three numbers" do
73
73
  d1, d2, d3 = 4, 1, 1.0 / 32.0
74
74
  data = [d1, d2, d3]
75
- Mean.geometric(data).should == 1.0 / 2.0
75
+ Mean.geometric(data).should == Math.cbrt(d1 * d2 * d3)
76
76
  end
77
77
  end
78
78
 
79
- describe "#harmonic" do
80
- it "should be nil for an empty array" do
81
- Mean.harmonic([]).should be_nil
82
- end
83
-
84
- it "should be the singleton element of a singleton array" do
85
- element = 5.5
86
- Mean.harmonic([element]).should == element
87
- end
79
+ describe ".harmonic" do
80
+ it_behaves_like "all means"
88
81
 
89
- it "should be the common value in a when all values are equal" do
90
- element = 5.5
91
- Mean.harmonic([element, element]).should == element
92
- end
82
+ it_behaves_like "non-arithmetic means"
93
83
 
94
- it "should be be according to the formula with two elements" do
84
+ it "is according to the formula with two elements" do
95
85
  d1, d2 = 1.0, 2.0
96
86
  data = [d1, d2]
97
87
  Mean.harmonic(data).should be_within(0.01).of((2.0 * d1 * d2) / (d1 + d2))
98
88
  end
99
89
 
100
- it "should be 12/7 for [1, 2, 4]" do
90
+ it "is 12/7 for [1, 2, 4]" do
101
91
  data = [1.0, 2.0, 4.0]
102
- Mean.harmonic(data).should be_within(0.01).of(1.7142)
103
- end
104
-
105
- it "should be zero if there is even one zero" do
106
- data = [1.0, 2.0, 0.0]
107
- Mean.harmonic(data).should == 0
92
+ Mean.harmonic(data).should be_within(0.01).of(12/7)
108
93
  end
109
94
  end
110
95
 
@@ -113,49 +98,55 @@ describe "Mean" do
113
98
  @m = Mean.new()
114
99
  end
115
100
 
116
- it "should accumulate the arithmetic mean" do
117
- @m.arithmetic_mean.should be_nil
118
- @m.push 1
119
- @m.arithmetic_mean.should == 1
120
- @m.push 2
121
- @m.arithmetic_mean.should == 1.5
122
- @m.push 3
123
- @m.arithmetic_mean.should == 2
124
- end
125
-
126
- it "should accumulate the geometric mean" do
127
- @m.geometric_mean.should be_nil
128
- @m.push 2
129
- @m.geometric_mean.should == 2
130
- @m.push 8
131
- @m.geometric_mean.should == 4
132
- end
133
-
134
- it "should accumulate the harmonic mean" do
135
- @m.harmonic_mean.should be_nil
136
- @m.push 1
137
- @m.harmonic_mean.should == 1
138
- @m.push 2
139
- @m.harmonic_mean.should == 4.0 / 3.0
101
+ describe "#arithmetic_mean" do
102
+ it "accumulates the arithmetic mean" do
103
+ @m.arithmetic_mean.should be_nil
104
+ @m.push 1
105
+ @m.arithmetic_mean.should == 1
106
+ @m.push 2
107
+ @m.arithmetic_mean.should == 1.5
108
+ @m.push 3
109
+ @m.arithmetic_mean.should == 2
110
+ end
111
+ end
112
+
113
+ describe "#geometric_mean" do
114
+ it "accumulates the geometric mean" do
115
+ @m.geometric_mean.should be_nil
116
+ @m.push 2
117
+ @m.geometric_mean.should == 2
118
+ @m.push 8
119
+ @m.geometric_mean.should == 4
120
+ end
121
+ end
122
+
123
+ describe "#harmonic_mean" do
124
+ it "accumulates the harmonic mean" do
125
+ @m.harmonic_mean.should be_nil
126
+ @m.push 1
127
+ @m.harmonic_mean.should == 1
128
+ @m.push 2
129
+ @m.harmonic_mean.should == 4.0 / 3.0
130
+ end
140
131
  end
141
132
  end
142
133
 
143
134
  describe "initialising accumulator" do
144
- it "should resurrect the arithmetic mean using the count and sum" do
135
+ it "resurrects the arithmetic mean using the count and sum" do
145
136
  m = Mean.new(count: 1, sum: 1)
146
137
  m.arithmetic_mean.should == 1
147
138
  m.push 2
148
139
  m.arithmetic_mean.should == 1.5
149
140
  end
150
141
 
151
- it "should resurrect the geometric mean using the count and product" do
142
+ it "resurrects the geometric mean using the count and product" do
152
143
  m = Mean.new(count: 1, product: 2)
153
144
  m.geometric_mean.should == 2
154
145
  m.push 8
155
146
  m.geometric_mean.should == 4
156
147
  end
157
148
 
158
- it "should resurrect the harmonic mean using the count and sum of the reciprocals" do
149
+ it "resurrects the harmonic mean using the count and sum of the reciprocals" do
159
150
  m = Mean.new(count: 1, sum_of_reciprocals: 1)
160
151
  m.harmonic_mean.should == 1
161
152
  m.push 2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: means
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,33 +9,33 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-11 00:00:00.000000000Z
12
+ date: 2012-01-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70168930981980 !ruby/object:Gem::Requirement
16
+ requirement: &70121412973800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.3.0
21
+ version: 2.7.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70168930981980
24
+ version_requirements: *70121412973800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &70168930981500 !ruby/object:Gem::Requirement
27
+ requirement: &70121412973300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 0.6.0
32
+ version: 0.7.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70168930981500
35
+ version_requirements: *70121412973300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &70168930981020 !ruby/object:Gem::Requirement
38
+ requirement: &70121412972800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70168930981020
46
+ version_requirements: *70121412972800
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &70168930980540 !ruby/object:Gem::Requirement
49
+ requirement: &70121412972300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70168930980540
57
+ version_requirements: *70121412972300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &70168930980060 !ruby/object:Gem::Requirement
60
+ requirement: &70121412971800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70168930980060
68
+ version_requirements: *70121412971800
69
69
  description: Calculates the different means for a data set (arithmetic, geometric
70
70
  and harmonic).
71
71
  email: nigel-lowry@ultra.eclipse.co.uk
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 824942231782093681
105
+ hash: 4236443169670694727
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements: