Skip to content

Commit

Permalink
Added spec to test Float#/ properly coercing other object
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydurham committed Nov 15, 2010
1 parent d21905a commit cfa72d6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/ruby/core/float/divide_spec.rb
@@ -1,12 +1,34 @@
require File.expand_path('../../../spec_helper', __FILE__)

module Specs
module Float
class CanCoerce
def initialize(a)
@a = a
end

def coerce(b)
[self.class.new(b), @a]
end

def /(b)
@a.to_i % b.to_i
end
end
end
end

describe "Float#/" do
it "returns self divided by other" do
(5.75 / -2).should be_close(-2.875,TOLERANCE)
(451.0 / 9.3).should be_close(48.494623655914,TOLERANCE)
(91.1 / -0xffffffff).should be_close(-2.12108716418061e-08, TOLERANCE)
end

it "properly coerces objects" do
(5.0 / Specs::Float::CanCoerce.new(5)).should be_close(0, TOLERANCE)
end

it "properly handles BigDecimal argument" do
require 'bigdecimal'
(2.0 / BigDecimal.new('5.0')).should be_close(0.4, TOLERANCE)
Expand Down

0 comments on commit cfa72d6

Please sign in to comment.