spec/external_function_spec.rb in dentaku-1.2.6 vs spec/external_function_spec.rb in dentaku-2.0.0

- old
+ new

@@ -6,32 +6,16 @@ describe 'external functions' do let(:with_external_funcs) do c = described_class.new - now = { name: :now, type: :string, signature: [], body: -> { Time.now.to_s } } - c.add_function(now) + c.add_function(:now, -> { Time.now.to_s }) fns = [ - { - name: :exp, - type: :numeric, - signature: [ :numeric, :numeric ], - body: ->(mantissa, exponent) { mantissa ** exponent } - }, - { - name: :max, - type: :numeric, - signature: [ :arguments ], - body: ->(*args) { args.max } - }, - { - name: :min, - type: :numeric, - signature: [ :arguments ], - body: ->(*args) { args.min } - } + [:pow, ->(mantissa, exponent) { mantissa ** exponent }], + [:biggest, ->(*args) { args.max }], + [:smallest, ->(*args) { args.min }], ] c.add_functions(fns) end @@ -39,21 +23,21 @@ now = with_external_funcs.evaluate('NOW()') expect(now).not_to be_nil expect(now).not_to be_empty end - it 'includes EXP' do - expect(with_external_funcs.evaluate('EXP(2,3)')).to eq(8) - expect(with_external_funcs.evaluate('EXP(3,2)')).to eq(9) - expect(with_external_funcs.evaluate('EXP(mantissa,exponent)', mantissa: 2, exponent: 4)).to eq(16) + it 'includes POW' do + expect(with_external_funcs.evaluate('POW(2,3)')).to eq(8) + expect(with_external_funcs.evaluate('POW(3,2)')).to eq(9) + expect(with_external_funcs.evaluate('POW(mantissa,exponent)', mantissa: 2, exponent: 4)).to eq(16) end - it 'includes MAX' do - expect(with_external_funcs.evaluate('MAX(8,6,7,5,3,0,9)')).to eq(9) + it 'includes BIGGEST' do + expect(with_external_funcs.evaluate('BIGGEST(8,6,7,5,3,0,9)')).to eq(9) end - it 'includes MIN' do - expect(with_external_funcs.evaluate('MIN(8,6,7,5,3,0,9)')).to eq(0) + it 'includes SMALLEST' do + expect(with_external_funcs.evaluate('SMALLEST(8,6,7,5,3,0,9)')).to eq(0) end end end end