Sha256: fe2f8a4e92849425d3ec6c3e7451bfb66bc3242fded22ad0d02e0facca15ba08

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require './spec/spec_helper'

describe ShuntingYard do
	def returns(tokens, postfix)
		expect(ShuntingYard.new(tokens).postfix).to eq(postfix)
	end

	it 'empty input' do
		returns [], []
	end

	it 'single operand' do
		returns ['drevo'], ['drevo']
	end

	it 'wrong input' do
		expect { ShuntingYard.new({}).postfix }.to raise_error(ArgumentError)
		expect { ShuntingYard.new(5).postfix }.to raise_error(ArgumentError)
		expect { ShuntingYard.new(nil).postfix }.to raise_error(ArgumentError)
		expect { ShuntingYard.new('ahoj').postfix }.to raise_error(ArgumentError)
	end

	it 'private constant' do
		expect { ShuntingYard::OPERATORS }.to raise_error(NameError)
	end

	it 'simple eq' do
		returns %w(material = drevo), %w(material drevo =)
	end

	it 'empty brackets' do
		returns %w(( )), []
	end

	it 'brackets' do
		returns %w(( cena > 180 )), %w(cena 180 >)
		returns %w(( ( cena ) > ( 180 ) )), %w(cena 180 >)
		expect { ShuntingYard.new(%w{( cena ) > 180 )}).postfix }.to raise_error(MissingLeftParenthesesError )
		expect { ShuntingYard.new(%w{( ( ( cena ) > 180 )}).postfix }.to raise_error(MissingRightParenthesesError)
	end

	it 'difficult cases' do
		returns %w{material = drevo && ( cena > 180 || cena >= 250 )},
		        %w{material drevo = cena 180 > cena 250 >= || &&}
		returns %w{( A || - B ) && C}, %w{A B - || C &&}
		returns %w{( ) ( ( cena = - 150 ) ) ( )}, %w{cena 150 - =}
		returns %w{- A = 150 || B && C}, %w{A - 150 = B C && ||}
	end

	it 'czech operands' do
		returns %w{dřevo < polička}, %w{dřevo polička <}
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lamep-0.2.1 spec/lib/shunting_yard_spec.rb
lamep-0.2 spec/lib/shunting_yard_spec.rb