Sha256: 4ff621858861adea07c5981e01dcb52a2db482b92ea6ca5c9067d0c6927d546e
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
# encoding: utf-8 require 'spec_helper' require 'inactive_support/numeric' describe Numeric do describe '#precision' do it 'behaves exactly like Float#round when invoked with no arguments', :brute do 1_000_000.times do n = rand(1.0..100.0) puts n if n.precision != n.round expect(n.precision).to eq n.round end end it 'behaves exactly like Float#round when invoked with no arguments' do 1_000.times do n = rand(1.0..100.0) puts n if n.precision != n.round expect(n.precision).to eq n.round end end describe 'reality checks' do it 'case#1' do expect(3.904605.precision(0)).to eq 4 expect(3.904605.precision(1)).to eq 3.9 expect(3.904605.precision(2)).to eq 3.91 expect(3.904605.precision(3)).to eq 3.905 expect(3.904605.precision(4)).to eq 3.9046 end it 'case#2' do expect(37.9945.precision(0)).to eq 38 expect(37.9945.precision(1)).to eq 38 expect(37.9945.precision(2)).to eq 38 end it 'case#3' do expect(37.9944.precision(0)).to eq 38 expect(37.9944.precision(1)).to eq 38 expect(37.9944.precision(2)).to eq 37.99 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
inactive_support-1.3.0 | spec/lib/numeric_spec.rb |
inactive_support-1.2.0 | spec/lib/numeric_spec.rb |