Sha256: 5dbc52a4ad5164500c8c333f3b621e1f16d31dd91a98786ed5403ff0aa4a284f

Contents?: true

Size: 825 Bytes

Versions: 5

Compression:

Stored size: 825 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/arithmetic'

require 'dentaku/token'

describe Dentaku::AST::Division do
  let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) }
  let(:six)  { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 6) }

  let(:t)    { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) }

  it 'performs division' do
    node = described_class.new(five, six)
    expect(node.value.round(4)).to eq 0.8333
  end

  it 'requires numeric operands' do
    expect {
      described_class.new(five, t)
    }.to raise_error(Dentaku::ParseError, /requires numeric operands/)

    expression = Dentaku::AST::Multiplication.new(five, five)
    group = Dentaku::AST::Grouping.new(expression)

    expect {
      described_class.new(group, five)
    }.not_to raise_error
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dentaku-2.0.11 spec/ast/division_spec.rb
dentaku-2.0.10 spec/ast/division_spec.rb
dentaku-2.0.9 spec/ast/division_spec.rb
dentaku-2.0.8 spec/ast/division_spec.rb
dentaku-2.0.7 spec/ast/division_spec.rb