Sha256: bffa0778bcccc9d3fe5ceef6ec2a4e20f31ed920d803d6f72c29f649702ec807

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'
require 'dentaku'
require 'dentaku/ast/functions/and'

describe 'Dentaku::AST::And' do
  let(:calculator) { Dentaku::Calculator.new }

  it 'returns false if any of the arguments is false' do
    result = Dentaku('AND(1 = 1, 0 = 1)')
    expect(result).to eq false
  end

  it 'supports nested expressions' do
    result = Dentaku('AND(y = 1, x = 1)', x: 1, y: 2)
    expect(result).to eq false
  end

  it 'returns true if all of the arguments are true' do
    result = Dentaku('AND(1 = 1, "2" = "2", true = true, true)')
    expect(result).to eq true
  end

  it 'returns true if all nested AND functions return true' do
    result = Dentaku('AND(AND(1 = 1), AND(true != false, AND(true)))')
    expect(result).to eq true
  end

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

  it 'raises an error if a non logical argument is passed' do
    expect { calculator.evaluate!('AND("r")') }.to raise_error(ArgumentError)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

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