-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpn_methods_spec.rb
41 lines (35 loc) · 1.26 KB
/
rpn_methods_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require './expression_tree'
require './rpn_methods'
describe RpnMethods do
include RpnMethods
describe '#rpn' do
context 'with a valid input' do
it { expect(rpn('1 2 +')).to eq 3 }
it { expect(rpn('4 2 /')).to eq 2 }
it { expect(rpn('2 3 4 + *')).to eq 14 }
it { expect(rpn('3 4 + 5 6 + *')).to eq 77 }
it { expect(rpn('13 4 -')).to eq 9 }
it { expect(rpn('1 2 3 4 + + +')).to eq 10 }
end
context 'with invalid input' do
it { expect(rpn('1 +')).to eq "not enough arguments" }
it { expect(rpn('a b +')).to eq "invalid number" }
end
end
context 'using a tree' do
describe '#rpn_expression_tree' do
context 'with a valid input' do
it { expect(rpn('1 2 +', tree=true)).to eq 3 }
it { expect(rpn('4 2 /', tree=true)).to eq 2 }
it { expect(rpn('2 3 4 + *', tree=true)).to eq 14 }
it { expect(rpn('3 4 + 5 6 + *', tree=true)).to eq 77 }
it { expect(rpn('13 4 -', tree=true)).to eq 9 }
it { expect(rpn('1 2 3 4 + + +', tree=true)).to eq 10 }
end
context 'with invalid input' do
it { expect(rpn('1 +', tree=true)).to eq "not enough arguments" }
it { expect(rpn('a b +', tree=true)).to eq "invalid number" }
end
end
end
end