Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
describe 'SymEngine::lambdify' do | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
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 |
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?