Skip to content

Commit

Permalink
Tests for lambdify
Browse files Browse the repository at this point in the history
  • Loading branch information
rajithv committed Jul 13, 2016
1 parent a63684d commit a91d406
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions spec/lambdify_spec.rb
@@ -0,0 +1,38 @@
describe 'SymEngine::lambdify' do

This comment has been minimized.

Copy link
@zverok

zverok Jul 13, 2016

Collaborator

BTW, for such a complicated case, I assume "direct" tests (what exactly is produced) are better than indirect (what will be calculated by that lambda). So, something like lambda_code method could be exposed and tested for exactly right code produced even for most complicated cases.

WDYT?


let(:x) { SymEngine::Symbol.new('x') }
let(:y) { SymEngine::Symbol.new('y') }
let(:z) { SymEngine::Symbol.new('z') }

describe 'lambda for Addition' do
let(:func) { x + y + z }
let(:lamb) { SymEngine::lambdify(func) }
it 'performs addition with a lambda function' do
expect(lamb.call(1, 1, 1)).to eq(3)
expect(lamb.call(1, -1, 1)).to eq(1)
expect(lamb.call(-1, -1, -1)).to eq(-3)
end
end

describe 'lambda for Addition with FixNums' do
let(:func) { x + 5}
let(:lamb) { SymEngine::lambdify(func) }
it 'performs addition with a lambda function' do
expect(lamb.call(1)).to eq(6)
expect(lamb.call(0)).to eq(5)
expect(lamb.call(-1)).to eq(4)
expect(lamb.call(Math::PI)).to be_within(0.000000000000001).of(8.141592653589793)
end
end

describe 'lambda for sin' do
let(:func) { SymEngine::sin(x) }
let(:lamb) { SymEngine::lambdify(func) }
it 'performs sin calculation with a lambda function' do
expect(lamb.call(0)).to be_within(0.000000000000001).of(0.0)
expect(lamb.call(Math::PI)).to be_within(0.000000000000001).of(0.0)
expect(lamb.call(Math::PI/2)).to be_within(0.000000000000001).of(1.0)
end
end

end

0 comments on commit a91d406

Please sign in to comment.