Skip to content

Commit 81ade4c

Browse files
committed
Complex Spec
1 parent 1246cb2 commit 81ade4c

File tree

2 files changed

+46
-57
lines changed

2 files changed

+46
-57
lines changed

spec/complex_spec.rb

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,51 @@
1-
require 'spec_helper'
2-
3-
describe SymEngine do
4-
describe SymEngine::Complex do
5-
describe '.new' do
6-
context 'with a Ruby Complex object as input' do
7-
it 'returns an instance of SymEngine::Complex class' do
8-
a = Complex(2, 3)
9-
a = SymEngine::convert(a)
10-
expect(a).to be_an_instance_of SymEngine::Complex
11-
expect(a.to_s).to eq('2 + 3*I')
12-
end
13-
end
14-
context 'with a Ruby Integer as input' do
15-
it 'returns an instance of SymEngine::Integer class' do
16-
a = Complex(2, 0)
17-
a = SymEngine::convert(a)
18-
expect(a).to be_an_instance_of SymEngine::Integer
19-
expect(a.to_s).to eq('2')
20-
end
21-
end
22-
context 'Obtaining the integer real part' do
23-
it 'returns an instance of SymEngine::Integer class' do
24-
a = Complex(2, 7)
25-
a = SymEngine::convert(a)
26-
a = a.real
27-
expect(a).to be_an_instance_of SymEngine::Integer
28-
expect(a.to_s).to eq('2');
29-
end
1+
describe SymEngine::Complex do
2+
context '#initialize' do
3+
context 'with a Complex' do
4+
subject { SymEngine(Complex(2, 3)) }
5+
6+
it { is_expected.to be_a SymEngine::Complex }
7+
its(:to_s) { is_expected.to eq '2 + 3*I' }
8+
end
9+
10+
context 'with an integer' do
11+
subject { SymEngine(Complex(2, 0)) }
12+
13+
it { is_expected.to be_a SymEngine::Integer }
14+
its(:to_s) { is_expected.to eq '2' }
15+
end
16+
end
17+
18+
context 'real_part and imaginary_part' do
19+
let(:a) { SymEngine(Complex(Rational('2/7'), Rational('3/8'))) }
20+
let(:b) { SymEngine(Complex(2, 3)) }
21+
22+
context 'real_part' do
23+
context 'using SymEngine Rationals' do
24+
subject { a.real }
25+
it { is_expected.to be_a SymEngine::Rational }
26+
its(:to_s) { is_expected.to eq '2/7' }
3027
end
31-
context 'Obtaining the integer imaginary part' do
32-
it 'returns an instance of SymEngine::Integer class' do
33-
a = Complex(2, 7)
34-
a = SymEngine::convert(a)
35-
a = a.imaginary
36-
expect(a).to be_an_instance_of SymEngine::Integer
37-
expect(a.to_s).to eq('7');
38-
end
28+
29+
context 'using SymEngine Integers' do
30+
subject { b.real }
31+
it { is_expected.to be_a SymEngine::Integer }
32+
its(:to_s) { is_expected.to eq '2' }
3933
end
40-
context 'Obtaining the rational real part ' do
41-
it 'returns an instance of SymEngine::Rational class' do
42-
a = Rational('5/4')
43-
a = Complex(a, 7)
44-
a = SymEngine::convert(a)
45-
a = a.real
46-
expect(a).to be_an_instance_of SymEngine::Rational
47-
expect(a.to_s).to eq('5/4');
48-
end
34+
end
35+
36+
context 'imaginary_part' do
37+
context 'using SymEngine Rationals' do
38+
subject { a.imaginary }
39+
it { is_expected.to be_a SymEngine::Rational }
40+
its(:to_s) { is_expected.to eq '3/8' }
4941
end
50-
context 'Obtaining the rational imaginary part' do
51-
it 'returns an instance of SymEngine::Integer class' do
52-
a = Rational('5/4')
53-
a = Complex(2, a)
54-
a = SymEngine::convert(a)
55-
a = a.imaginary
56-
expect(a).to be_an_instance_of SymEngine::Rational
57-
expect(a.to_s).to eq('5/4');
58-
end
42+
43+
context 'using SymEngine Integers' do
44+
subject { b.imaginary }
45+
it { is_expected.to be_a SymEngine::Integer }
46+
its(:to_s) { is_expected.to eq '3' }
5947
end
60-
end
48+
end
6149
end
6250
end
51+

symengine_version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
745b4e4d4d429aa6c08fd561676ef4d5920ada0f
1+
3f58acc1246661323b1daf2adc3f9fa6a8762df4
22

0 commit comments

Comments
 (0)