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

Version Path
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.5.2 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.5.1 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.5.0 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.4.2 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.4.1 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.4.0 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.3.0 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.2.0 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb
virtus-0.1.0 spec/unit/virtus/coercion/string/class_methods/to_float_spec.rb