spec/calculator_spec.rb in dentaku-1.2.6 vs spec/calculator_spec.rb in dentaku-2.0.0
- old
+ new
@@ -1,5 +1,6 @@
+require 'spec_helper'
require 'dentaku/calculator'
describe Dentaku::Calculator do
let(:calculator) { described_class.new }
let(:with_memory) { described_class.new.store(apples: 3) }
@@ -17,11 +18,11 @@
expect(calculator.evaluate('2 ^ - 1')).to eq(0.5)
expect(calculator.evaluate('2 ^ -(3 - 2)')).to eq(0.5)
expect(calculator.evaluate('(2 + 3) - 1')).to eq(4)
expect(calculator.evaluate('(-2 + 3) - 1')).to eq(0)
expect(calculator.evaluate('(-2 - 3) - 1')).to eq(-6)
- expect(calculator.evaluate('1 + -2 ^ 2')).to eq(-3)
+ expect(calculator.evaluate('1 + -(2 ^ 2)')).to eq(-3)
expect(calculator.evaluate('3 + -num', num: 2)).to eq(1)
expect(calculator.evaluate('-num + 3', num: 2)).to eq(1)
expect(calculator.evaluate('10 ^ 2')).to eq(100)
expect(calculator.evaluate('0 * 10 ^ -5')).to eq(0)
expect(calculator.evaluate('3 + 0 * -3')).to eq(3)
@@ -194,8 +195,20 @@
it 'evaluates functions with negative numbers' do
expect(calculator.evaluate('if (-1 < 5, -1, 5)')).to eq(-1)
expect(calculator.evaluate('if (-1 = -1, -1, 5)')).to eq(-1)
expect(calculator.evaluate('round(-1.23, 1)')).to eq(BigDecimal.new('-1.2'))
expect(calculator.evaluate('NOT(some_boolean) AND -1 > 3', some_boolean: true)).to be_falsey
+ end
+ end
+
+ describe 'math functions' do
+ Math.methods(false).each do |method|
+ it method do
+ if Math.method(method).arity == 2
+ 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
end