File: array_spec.rb

package info (click to toggle)
ruby-enumerable-statistics 2.0.7%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,132 kB
  • sloc: ruby: 2,220; ansic: 1,921; javascript: 408; makefile: 8; sh: 4
file content (61 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'spec_helper'

RSpec.describe Array, '#percentile' do
  let(:ary) { [] }
  let(:args) { [0, 25, 50, 75, 100] }

  subject(:percentile) { ary.percentile(args) }

  with_array [] do
    specify do
      expect { percentile }.to raise_error(ArgumentError)
    end
  end

  with_array [1] do
    specify do
      expect(percentile).to eq([1.0, 1.0, 1.0, 1.0, 1.0])
    end
  end

  with_array [1, 2, 3] do
    specify do
      expect(percentile).to eq([1.0, 1.5, 2.0, 2.5, 3.0])
    end
  end

  with_array [1, 2] do
    let(:args) { 50 }
    specify do
      expect(percentile).to eq(1.5)
    end
  end

  with_array [1, 2] do
    let(:args) { [50] }
    specify do
      expect(percentile).to eq([1.5])
    end
  end

  with_array [1, 2, 3] do
    let(:args) { [100, 25, 0, 75, 50] }
    specify do
      expect(percentile).to eq([3.0, 1.5, 1.0, 2.5, 2.0])
    end
  end

  with_array [1, Float::NAN, 3] do
    let(:args) { [100, 25] }
    specify do
      expect(percentile).to match([be_nan, be_nan])
    end
  end

  with_array [1, nil, 3] do
    let(:args) { [100, 25] }
    specify do
      expect(percentile).to match([be_nan, be_nan])
    end
  end
end