Sha256: 63eebc9fff1081c4f0a7c1b291f3444f78bd289b4c30437eb773efd43fff5b5b

Contents?: true

Size: 941 Bytes

Versions: 4

Compression:

Stored size: 941 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/functions/avg'
require 'dentaku'

describe 'Dentaku::AST::Function::Avg' do
  it 'returns the average of an array of Numeric values' do
    result = Dentaku('AVG(1, x, 1.8)', x: 2.3)
    expect(result).to eq(1.7)
  end

  it 'returns the average of a single entry array of a Numeric value' do
    result = Dentaku('AVG(x)', x: 2.3)
    expect(result).to eq(2.3)
  end

  it 'returns the average even if a String is passed' do
    result = Dentaku('AVG(1, x, 1.8)', x: '2.3')
    expect(result).to eq(1.7)
  end

  it 'returns the average even if an array is passed' do
    result = Dentaku('AVG(1, x, 2.3)', x: [4, 5])
    expect(result).to eq(3.075)
  end

  context 'checking errors' do
    let(:calculator) { Dentaku::Calculator.new }

    it 'raises an error if no arguments are passed' do
      expect { calculator.evaluate!('AVG()') }.to raise_error(Dentaku::ArgumentError)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dentaku-3.3.4 spec/ast/avg_spec.rb
dentaku-3.3.3 spec/ast/avg_spec.rb
dentaku-3.3.2 spec/ast/avg_spec.rb
dentaku-3.3.1 spec/ast/avg_spec.rb