spec/calculator_spec.rb in dentaku-2.0.7 vs spec/calculator_spec.rb in dentaku-2.0.8
- old
+ new
@@ -29,10 +29,11 @@
expect(calculator.evaluate('3 + 0 / -3')).to eq(3)
expect(calculator.evaluate('15 % 8')).to eq(7)
expect(calculator.evaluate('(((695759/735000)^(1/(1981-1991)))-1)*1000').round(4)).to eq(5.5018)
expect(calculator.evaluate('0.253/0.253')).to eq(1)
expect(calculator.evaluate('0.253/d', d: 0.253)).to eq(1)
+ expect(calculator.evaluate('10 + x', x: 'abc')).to be_nil
end
describe 'memory' do
it { expect(calculator).to be_empty }
it { expect(with_memory).not_to be_empty }
@@ -278,10 +279,16 @@
choice: 2,
bar: nil,
foo: nil
)
end
+
+ it 'raises errors when used in arithmetic operation' do
+ expect {
+ calculator.solve!(more_apples: "apples + 1", apples: nil)
+ }.to raise_error(Dentaku::ArgumentError)
+ end
end
describe 'case statements' do
it 'handles complex then statements' do
formula = <<-FORMULA
@@ -367,8 +374,16 @@
expect(calculator.evaluate("#{method}(1,2)")).to eq Math.send(method, 1, 2)
else
expect(calculator.evaluate("#{method}(1)")).to eq Math.send(method, 1)
end
end
+ end
+ end
+
+ describe 'string functions' do
+ it 'concatenates two strings' do
+ expect(
+ calculator.evaluate('CONCAT(s1, s2)', 's1' => 'abc', 's2' => 'def')
+ ).to eq 'abcdef'
end
end
end