Sha256: a1ee4f47fa2252f7b2d13d4f677500a9488ed51fe0c0571cc077160290f73e88
Contents?: true
Size: 853 Bytes
Versions: 7
Compression:
Stored size: 853 Bytes
Contents
# frozen_string_literal: true require 'spec_helper' describe Math do describe '.average' do context 'when passing an array of values' do let(:values) { [0, 1, 2, 3, 4] } it 'returns the average' do expect(described_class.average(values)).to eq(2) end context 'when average is not a round number' do let(:values) { [0, 1, 2, 3] } it 'returns the average' do expect(described_class.average(values)).to eq(1.5) end end end context 'when passing a hash' do let(:values) do { 0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5 } end it 'uses the keys as values and the values as weights (frequency)' do expect(described_class.average(values)).to eq(8 / 3.0) end end end end
Version data entries
7 entries across 7 versions & 1 rubygems