Sha256: e2ee836f45cc7dd27b5204a3e6d06fd4e9e9939cc7b9e9b4b496d69a4276f9b5

Contents?: true

Size: 983 Bytes

Versions: 10

Compression:

Stored size: 983 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 'allows access to its sub-trees' do
    node = described_class.new(five, six)
    expect(node.left).to eq(five)
    expect(node.right).to eq(six)
  end

  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::NodeError, /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

10 entries across 10 versions & 2 rubygems

Version Path
dentaku-3.5.2 spec/ast/division_spec.rb
dentaku_zevo-3.5.2 spec/ast/division_spec.rb
dentaku-3.5.1 spec/ast/division_spec.rb
dentaku-3.5.0 spec/ast/division_spec.rb
dentaku-3.4.2 spec/ast/division_spec.rb
dentaku-3.4.1 spec/ast/division_spec.rb
dentaku-3.4.0 spec/ast/division_spec.rb
dentaku-3.3.4 spec/ast/division_spec.rb
dentaku-3.3.3 spec/ast/division_spec.rb
dentaku-3.3.2 spec/ast/division_spec.rb