Sha256: c3e8f2e8cd7484c484bf79dd860ca03abdd7ad1cf0d9d204275eeb66a896ab6b

Contents?: true

Size: 660 Bytes

Versions: 3

Compression:

Stored size: 660 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/functions/abs'
require 'dentaku'

describe 'Dentaku::AST::Function::Abs' do
  it 'returns the absolute value of number' do
    result = Dentaku('ABS(-4.2)')
    expect(result).to eq(4.2)
  end

  it 'returns the correct value for positive number' do
    result = Dentaku('ABS(1.3)')
    expect(result).to eq(1.3)
  end

  it 'returns the correct value for zero' do
    result = Dentaku('ABS(0)')
    expect(result).to eq(0)
  end

  context 'checking errors' do
    it 'raises an error if argument is not numeric' do
      expect { Dentaku!("ABS(2020-1-1)") }.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/abs_spec.rb
dentaku-3.5.3 spec/ast/abs_spec.rb
dentaku-3.5.2 spec/ast/abs_spec.rb