|
| 1 | +require 'bigdecimal' |
| 2 | + |
| 3 | +describe SymEngine::RealMPFR do |
| 4 | + describe 'Convert BigDemcimal to RealMPFR' do |
| 5 | + shared_examples 'simple real check' do |
| 6 | + subject { SymEngine(value) } |
| 7 | + |
| 8 | + it { is_expected.to be_a SymEngine::RealMPFR } |
| 9 | + its(:to_f) { is_expected.to eq value.to_f } |
| 10 | + end |
| 11 | + |
| 12 | + context 'positive BigDecimal' do |
| 13 | + let(:value) { BigDecimal("12.3") } |
| 14 | + |
| 15 | + it_behaves_like 'simple real check' |
| 16 | + end |
| 17 | + |
| 18 | + context 'negative BigDecimal' do |
| 19 | + let(:value) { BigDecimal("-12.3") } |
| 20 | + |
| 21 | + it_behaves_like 'simple real check' |
| 22 | + end |
| 23 | + end |
| 24 | + |
| 25 | + describe 'Initialize RealMPFR' do |
| 26 | + shared_examples 'simple real check' do |
| 27 | + subject { SymEngine::RealMPFR.new(value, 200) } |
| 28 | + |
| 29 | + it { is_expected.to be_a SymEngine::RealMPFR } |
| 30 | + its(:to_f) { is_expected.to eq value.to_f } |
| 31 | + end |
| 32 | + |
| 33 | + context 'positive BigDecimal' do |
| 34 | + let(:value) { BigDecimal("12.3") } |
| 35 | + |
| 36 | + it_behaves_like 'simple real check' |
| 37 | + end |
| 38 | + |
| 39 | + context 'negative BigDecimal' do |
| 40 | + let(:value) { BigDecimal("-12.3") } |
| 41 | + |
| 42 | + it_behaves_like 'simple real check' |
| 43 | + end |
| 44 | + |
| 45 | + context 'positive Float' do |
| 46 | + let(:value) { 12.3 } |
| 47 | + |
| 48 | + it_behaves_like 'simple real check' |
| 49 | + end |
| 50 | + |
| 51 | + context 'negative Float' do |
| 52 | + let(:value) { 12.3 } |
| 53 | + |
| 54 | + it_behaves_like 'simple real check' |
| 55 | + end |
| 56 | + |
| 57 | + context 'String representation of positive value' do |
| 58 | + let(:value) { "12.3" } |
| 59 | + |
| 60 | + it_behaves_like 'simple real check' |
| 61 | + end |
| 62 | + |
| 63 | + context 'String representation of negative value' do |
| 64 | + let(:value) { "-12.3" } |
| 65 | + |
| 66 | + it_behaves_like 'simple real check' |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + |
| 71 | +end |
0 commit comments