average 2.0 → 3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,15 @@
1
1
  require 'average/mean'
2
2
  require 'average/median'
3
3
  class Array
4
- def get_mean
5
- mean(self)
4
+ def mean
5
+ get_mean(self)
6
6
  end
7
7
 
8
- def get_mode
9
- mode(self)
8
+ def mode
9
+ get_mode(self)
10
10
  end
11
11
 
12
- def get_median
13
- median(self)
12
+ def median
13
+ get_median(self)
14
14
  end
15
15
  end
@@ -1,4 +1,4 @@
1
- def mean(array)
1
+ def get_mean(array)
2
2
  return if not valid_array?(array)
3
3
  array = clean_array(array)
4
4
  array.inject(0) { |sum, x| sum += x } / array.size.to_f
@@ -1,4 +1,4 @@
1
- def median(array)
1
+ def get_median(array)
2
2
  return if not valid_array?(array)
3
3
  array = clean_array(array)
4
4
  calculate_median(array)
@@ -7,7 +7,7 @@ end
7
7
  def calculate_median(array)
8
8
  array.sort!
9
9
  if array.length.even?
10
- mean( middle_items_to_average(array) )
10
+ get_mean( middle_items_to_average(array) )
11
11
  else
12
12
  array[ array.length / 2.to_f ]
13
13
  end
@@ -1,4 +1,4 @@
1
- def mode(array)
1
+ def get_mode(array)
2
2
  return if not valid_array?(array)
3
3
  array = clean_array(array)
4
4
  result = repetition_hash(array)
@@ -1,3 +1,3 @@
1
1
  module Average
2
- VERSION = "2.0"
2
+ VERSION = "3.0"
3
3
  end
@@ -4,28 +4,28 @@ describe Average do
4
4
 
5
5
  let(:int_array) { [3,4,5] }
6
6
 
7
- describe '.get_mean' do
7
+ describe '.mean' do
8
8
  context 'should give back the same result as' do
9
- it 'mean([X,X,X,X])' do
10
- expect(int_array.get_mean).to eq(mean(int_array))
9
+ it 'get_mean([X,X,X,X])' do
10
+ expect(int_array.mean).to eq(get_mean(int_array))
11
11
  end
12
- end
12
+ end
13
13
  end
14
14
 
15
- describe '.get_mode' do
15
+ describe '.mode' do
16
16
  context 'should give back the same result as ' do
17
- it 'mode([X,X,X,X])' do
18
- expect(int_array.get_mode).to eq(mode(int_array))
17
+ it 'get_mode([X,X,X,X])' do
18
+ expect(int_array.mode).to eq(get_mode(int_array))
19
19
  end
20
- end
20
+ end
21
21
  end
22
22
 
23
- describe '.get_median' do
23
+ describe '.median' do
24
24
  context 'should give back the same result as ' do
25
- it 'median([X,X,X,X])' do
26
- expect(int_array.get_median).to eq(median(int_array))
25
+ it 'get_median([X,X,X,X])' do
26
+ expect(int_array.median).to eq(get_median(int_array))
27
27
  end
28
- end
28
+ end
29
29
  end
30
30
 
31
31
  end
@@ -6,23 +6,23 @@ describe Average do
6
6
 
7
7
  let(:mixed_array) { [3, 4.0, 5, 2.0, 3, 1.0] }
8
8
 
9
- describe '#mean' do
9
+ describe '#get_mean' do
10
10
 
11
11
  context 'with a array of integers' do
12
12
  it 'should calculate the correct mean' do
13
- expect(mean(int_array)).to eq(4)
13
+ expect(get_mean(int_array)).to eq(4)
14
14
  end
15
15
  end
16
16
 
17
17
  context 'with a mixed array of integers and floats' do
18
18
  it 'should calculate the correct mean' do
19
- expect(mean(mixed_array)).to eq(3)
19
+ expect(get_mean(mixed_array)).to eq(3)
20
20
  end
21
21
  end
22
22
 
23
23
  context 'with a empty array' do
24
24
  it 'should give back a nil' do
25
- expect(mean([])).to eq(nil)
25
+ expect(get_mean([])).to eq(nil)
26
26
  end
27
27
  end
28
28
 
@@ -12,23 +12,23 @@ describe Average do
12
12
 
13
13
  let(:mode_array_not_pair) { [1, 1, 2, 2, 3, 4, 5] }
14
14
 
15
- describe '#median' do
15
+ describe '#get_median' do
16
16
 
17
17
  context 'with a array of integers' do
18
18
  it 'should calculate the correct median' do
19
- expect(median(int_array)).to eq(4)
19
+ expect(get_median(int_array)).to eq(4)
20
20
  end
21
21
  end
22
22
 
23
23
  context 'with a mixed array of integers and floats' do
24
24
  it 'should calculate the correct median' do
25
- expect(median(mixed_array)).to eq(3)
25
+ expect(get_median(mixed_array)).to eq(3)
26
26
  end
27
27
  end
28
28
 
29
29
  context 'with an empty array' do
30
30
  it 'should gives back a nil' do
31
- expect(median([])).to eq(nil)
31
+ expect(get_median([])).to eq(nil)
32
32
  end
33
33
  end
34
34
 
@@ -8,23 +8,23 @@ describe Average do
8
8
 
9
9
  let(:mixed_array) { [3, 4.0, 5, 2.0, 3, 1.0] }
10
10
 
11
- describe '#mode' do
11
+ describe '#get_mode' do
12
12
 
13
13
  context 'with a array of integers' do
14
14
  it 'should calculate the correct mode' do
15
- expect(mode(mode_array)).to eq([1, 2])
15
+ expect(get_mode(mode_array)).to eq([1, 2])
16
16
  end
17
17
  end
18
18
 
19
19
  context 'with a empty array' do
20
20
  it 'should return a empty array' do
21
- expect(mode([])).to eq(nil)
21
+ expect(get_mode([])).to eq(nil)
22
22
  end
23
23
  end
24
24
 
25
25
  context 'with a nil object' do
26
26
  it 'should return a empty array' do
27
- expect(mode([])).to eq(nil)
27
+ expect(get_mode([])).to eq(nil)
28
28
  end
29
29
  end
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: average
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.0'
4
+ version: '3.0'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: