Sha256: af4c5cc0672e91b214aac8eafbf66ce102df24ca89ec9dba5667171236094f9f

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

require 'dentaku/binary_operation'

describe Dentaku::BinaryOperation do
  let(:operation) { described_class.new(2, 3) }
  let(:logical)   { described_class.new(true, false) }

  it 'raises a number to a power' do
    expect(operation.pow).to eq [:numeric, 8]
  end

  it 'adds two numbers' do
    expect(operation.add).to eq [:numeric, 5]
  end

  it 'subtracts two numbers' do
    expect(operation.subtract).to eq [:numeric, -1]
  end

  it 'multiplies two numbers' do
    expect(operation.multiply).to eq [:numeric, 6]
  end

  it 'divides two numbers' do
    expect(operation.divide).to eq [:numeric, (BigDecimal.new('2.0')/BigDecimal.new('3.0'))]
  end

  it 'compares two numbers' do
    expect(operation.le).to eq [:logical, true]
    expect(operation.lt).to eq [:logical, true]
    expect(operation.ne).to eq [:logical, true]

    expect(operation.ge).to eq [:logical, false]
    expect(operation.gt).to eq [:logical, false]
    expect(operation.eq).to eq [:logical, false]
  end

  it 'performs logical AND and OR' do
    expect(logical.and).to eq [:logical, false]
    expect(logical.or).to  eq [:logical, true]
  end

  it 'mods two numbers' do
    expect(operation.mod).to eq [:numeric, 2%3]
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dentaku-1.2.6 spec/binary_operation_spec.rb
dentaku-1.2.5 spec/binary_operation_spec.rb
dentaku-1.2.4 spec/binary_operation_spec.rb
dentaku-1.2.3 spec/binary_operation_spec.rb
dentaku-1.2.2 spec/binary_operation_spec.rb
dentaku-1.2.1 spec/binary_operation_spec.rb
dentaku-1.2.0 spec/binary_operation_spec.rb
dentaku-1.1.0 spec/binary_operation_spec.rb