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 (39 lines) | stat: -rw-r--r-- 716 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
require 'spec_helper'

RSpec.describe Array, '#median' do
  let(:ary) { [] }

  subject(:median) { ary.median }

  with_array [] do
    it_is_float_nan
  end

  with_array [1] do
    it_is_int_equal(1)
  end

  with_array [0, 1] do
    it_is_float_equal(0.5)
  end

  with_array [0.0444502, 0.0463301, 0.141249, 0.0606775] do
    it_is_float_equal((0.0463301 + 0.0606775) / 2.0)
  end

  with_array [0.0463301, 0.0444502, 0.141249] do
    it_is_float_equal(0.0463301)
  end

  with_array [0.0444502, 0.141249, 0.0463301] do
    it_is_float_equal(0.0463301)
  end

  with_array [0.0444502, Float::NAN, 0.0463301] do
    it_is_float_nan
  end

  with_array [0.0444502, nil, 0.0463301] do
    it_is_float_nan
  end
end