public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
benstiglitz (author)
Wed Apr 16 11:32:18 -0700 2008
brixen (committer)
Wed Apr 16 12:07:47 -0700 2008
commit  5c176e50fe962de1095a75221b4d63e75acc505f
tree    4cd83616a49aeb9994a189bde852e463f0876335
parent  6402fcc6308b9136a2d310553f18092549ca65cc
rubinius / spec / ruby / 1.8 / core / numeric / div_spec.rb
100644 42 lines (34 sloc) 1.291 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require File.dirname(__FILE__) + '/../../spec_helper'
 
describe "Numeric#div" do
  it "returns the integer quotient of two Integers" do
    13.div(4).should == 3
    4.div(13).should == 0
  end
  
  it "returns the integer quotient of an Integer and a Float" do
    13.div(4.0).should == 3
    4.div(13.0).should == 0
  end
  
  it "returns the integer quotient of a Float and an Integer" do
    (13.0).div(4).should == 3
    (4.0).div(13).should == 0
  end
  
  it "returns the integer quotient of two Floats" do
    (13.0).div(4.0).should == 3
    (4.0).div(13.0).should == 0
  end
  
  it "returns the integer quotient of a Bignum and an Integer" do
    bignum_value(0).div(100).should == 92233720368547758
  end
  
  it "raises an ArgumentError if not passed one argument" do
    lambda { 13.div }.should raise_error(ArgumentError)
    lambda { 13.div(1, 2) }.should raise_error(ArgumentError)
  end
  
  it "raises a ZeroDivisionError if passed 0" do
    lambda { 13.div(0) }.should raise_error(ZeroDivisionError)
  end
  
  it "raises a TypeError if not passed a Numeric type" do
    lambda { 13.div(nil) }.should raise_error(TypeError)
    lambda { 13.div('test') }.should raise_error(TypeError)
    lambda { 13.div(true) }.should raise_error(TypeError)
  end
end