|
| 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