Skip to content

Commit 940a144

Browse files
committed
Spec for Real Double
1 parent 97bbd0a commit 940a144

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

lib/symengine.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ def symbols ary_or_string, *params
3636
require 'symengine/basic'
3737
require 'symengine/integer'
3838
require 'symengine/complex'
39+
require 'symengine/real_double'
40+
require 'symengine/complex_double'

lib/symengine/complex_double.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module SymEngine
2+
class ComplexDouble
3+
def to_c
4+
to_s.to_c
5+
end
6+
end
7+
end

spec/real_double_spec.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
describe SymEngine::RealDouble do
2+
describe 'Convert Float to Real Double' do
3+
shared_examples 'simple real check' do
4+
subject { SymEngine(value) }
5+
6+
it { is_expected.to be_a SymEngine::RealDouble }
7+
its(:to_s) { is_expected.to eq value.to_s }
8+
end
9+
10+
context 'positive Float' do
11+
let(:value) { 12.3 }
12+
13+
it_behaves_like 'simple real check'
14+
end
15+
16+
context 'negative Float' do
17+
let(:value) { -12.3 }
18+
19+
it_behaves_like 'simple real check'
20+
end
21+
22+
context 'huge positive float' do
23+
let(:value) { 1.12_345_678_912_345 }
24+
25+
it_behaves_like 'simple real check'
26+
end
27+
28+
context 'huge negative float' do
29+
let(:value) { -1.12_345_678_912_345 }
30+
31+
it_behaves_like 'simple real check'
32+
end
33+
end
34+
35+
describe 'coercion' do
36+
let(:symbol) { sym('x') }
37+
38+
context 'using a ruby float as the second operand' do
39+
context 'commutative operations' do
40+
subject { symbol * 2.2 }
41+
42+
it { is_expected.to be_a SymEngine::Basic }
43+
it { is_expected.to eq(symbol * SymEngine(2.2)) }
44+
end
45+
46+
context 'non commutative operations' do
47+
subject { symbol / 2.2 }
48+
49+
it { is_expected.to be_a SymEngine::Basic }
50+
it { is_expected.to eq(symbol / SymEngine(2.2)) }
51+
end
52+
end
53+
54+
context 'using a ruby float as the first operand' do
55+
context 'commutative operations' do
56+
subject { 2.2 * symbol }
57+
58+
it { is_expected.to be_a SymEngine::Basic }
59+
it { is_expected.to eq(symbol * SymEngine(2.2)) }
60+
end
61+
62+
context 'non commutative operations' do
63+
subject { 2.2 / symbol }
64+
65+
it { is_expected.to be_a SymEngine::Basic }
66+
it { is_expected.to eq(SymEngine(2.2) / symbol) }
67+
end
68+
end
69+
end
70+
end

0 commit comments

Comments
 (0)