Sha256: 6fac4f62a58d3d140395d6218985139ede409b507d4d5119a6c06ac39b73c9c4
Contents?: true
Size: 956 Bytes
Versions: 10
Compression:
Stored size: 956 Bytes
Contents
require 'spec_helper' describe Virtus::Coercion::String, '.to_float' do subject { described_class.to_float(string) } { '1' => 1.0, '+1' => 1.0, '-1' => -1.0, '1.0' => 1.0, '1.0e+1' => 10.0, '1.0e-1' => 0.1, '1.0E+1' => 10.0, '1.0E-1' => 0.1, '+1.0' => 1.0, '+1.0e+1' => 10.0, '+1.0e-1' => 0.1, '+1.0E+1' => 10.0, '+1.0E-1' => 0.1, '-1.0' => -1.0, '-1.0e+1' => -10.0, '-1.0e-1' => -0.1, '-1.0E+1' => -10.0, '-1.0E-1' => -0.1, '.1' => 0.1, '.1e+1' => 1.0, '.1e-1' => 0.01, '.1E+1' => 1.0, '.1E-1' => 0.01, }.each do |value, expected| context "with #{value.inspect}" do let(:string) { value } it { should be_instance_of(Float) } it { should eql(expected) } end end context 'with an invalid float string' do let(:string) { 'non-float' } it { should equal(string) } end end
Version data entries
10 entries across 10 versions & 2 rubygems