spec/external_function_spec.rb in dentaku-3.0.0 vs spec/external_function_spec.rb in dentaku-3.1.0
- old
+ new
@@ -9,11 +9,11 @@
c = described_class.new
c.add_function(:now, :string, -> { Time.now.to_s })
fns = [
- [:pow, :numeric, ->(mantissa, exponent) { mantissa ** exponent }],
+ [:pow, :numeric, ->(mantissa, exponent) { mantissa**exponent }],
[:biggest, :numeric, ->(*args) { args.max }],
[:smallest, :numeric, ->(*args) { args.min }],
]
c.add_functions(fns)
@@ -47,11 +47,11 @@
->(haystack, needle) {
haystack.include?(needle)
}
)
- expect(calculator.evaluate("INCLUDES(list, 2)", list: [1,2,3])).to eq(true)
+ expect(calculator.evaluate("INCLUDES(list, 2)", list: [1, 2, 3])).to eq(true)
end
end
it 'allows registering "bang" functions' do
calculator = described_class.new
@@ -59,18 +59,18 @@
expect(calculator.evaluate("hey!()")).to eq("hey!")
end
it 'does not store functions across all calculators' do
calculator1 = Dentaku::Calculator.new
- calculator1.add_function(:my_function, :numeric, ->(x) { 2*x + 1 })
+ calculator1.add_function(:my_function, :numeric, ->(x) { 2 * x + 1 })
calculator2 = Dentaku::Calculator.new
- calculator2.add_function(:my_function, :numeric, ->(x) { 4*x + 3 })
+ calculator2.add_function(:my_function, :numeric, ->(x) { 4 * x + 3 })
- expect(calculator1.evaluate("1 + my_function(2)")). to eq (1 + 2*2 + 1)
- expect(calculator2.evaluate("1 + my_function(2)")). to eq (1 + 4*2 + 3)
+ expect(calculator1.evaluate("1 + my_function(2)")). to eq (1 + 2 * 2 + 1)
+ expect(calculator2.evaluate("1 + my_function(2)")). to eq (1 + 4 * 2 + 3)
- expect{Dentaku::Calculator.new.evaluate("1 + my_function(2)")}.to raise_error(Dentaku::ParseError)
+ expect { Dentaku::Calculator.new.evaluate("1 + my_function(2)") }.to raise_error(Dentaku::ParseError)
end
it 'self.add_function adds to default/global function registry' do
Dentaku::Calculator.add_function(:global_function, :numeric, ->(x) { 10 + x**2 })
expect(Dentaku::Calculator.new.evaluate("global_function(3) + 5")).to eq (10 + 3**2 + 5)