Sha256: 4b680aefac1acad2a33eef8751456f6268957b16f2b7b86097b4a1bc156ef4d9
Contents?: true
Size: 1.22 KB
Versions: 3
Compression:
Stored size: 1.22 KB
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 as BigDecimal' do result = Dentaku('AVG(1, 2)') expect(result).to eq(1.5) end 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 it 'raises an error if an empty array is passed' do expect { calculator.evaluate!('AVG(x)', x: []) }.to raise_error(Dentaku::ArgumentError) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dentaku-3.5.4 | spec/ast/avg_spec.rb |
dentaku-3.5.3 | spec/ast/avg_spec.rb |
dentaku-3.5.2 | spec/ast/avg_spec.rb |