|
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' } |
30 | 27 | 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' } |
39 | 33 | 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' } |
49 | 41 | 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' } |
59 | 47 | end |
60 | | - end |
| 48 | + end |
61 | 49 | end |
62 | 50 | end |
| 51 | + |
0 commit comments