Sha256: 5d8bb2d1de6eb2f96dbc56fe8994937bedb4ca21f27151d2f54dbb9760870a7c

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

require 'spec_helper'
require 'dentaku/ast/functions/sum'
require 'dentaku'

describe 'Dentaku::AST::Function::Sum' do
  it 'returns the sum of an array of Numeric values' do
    result = Dentaku('SUM(1, x, 1.8)', x: 2.3)
    expect(result).to eq 5.1
  end

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

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

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

  it 'returns the sum of nested sums' do
    result = Dentaku('SUM(1, x, SUM(4, 5))', x: '2.3')
    expect(result).to eq 12.3
  end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dentaku-3.3.0 spec/ast/sum_spec.rb
dentaku-3.2.1 spec/ast/sum_spec.rb
dentaku-3.2.0 spec/ast/sum_spec.rb
dentaku-3.1.0 spec/ast/sum_spec.rb