File: comparison_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (59 lines) | stat: -rw-r--r-- 1,959 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require File.expand_path('../../../spec_helper', __FILE__)

describe "Float#<=>" do
  it "returns -1, 0, 1 when self is less than, equal, or greater than other" do
    (1.5 <=> 5).should == -1
    (2.45 <=> 2.45).should == 0
    ((bignum_value*1.1) <=> bignum_value).should == 1
  end

  it "returns nil when either argument is NaN" do
    (nan_value <=> 71.2).should be_nil
    (1771.176 <=> nan_value).should be_nil
  end

  it "returns nil when the given argument is not a Float" do
    (1.0 <=> "1").should be_nil
  end

  # TODO: Remove duplicate ruby_bug guards when ruby_bug is fixed.
  ruby_bug "[ruby-dev:38672] [Bug #1645]", "1.8.7" do
    # The 4 tests below are taken from matz's revision 23730 for Ruby trunk
    #
    it "returns 1 when self is Infinity and other is a Bignum" do
      (infinity_value <=> Float::MAX.to_i*2).should == 1
    end

    it "returns -1 when self is negative and other is Infinty" do
      (-Float::MAX.to_i*2 <=> infinity_value).should == -1
    end

    it "returns -1 when self is -Infinity and other is negative" do
      (-infinity_value <=> -Float::MAX.to_i*2).should == -1
    end

    it "returns 1 when self is negative and other is -Infinity" do
      (-Float::MAX.to_i*2 <=> -infinity_value).should == 1
    end
  end

  ruby_bug "[ruby-dev:38672] [Bug #1645]", "1.8.7.302" do
    # The 4 tests below are taken from matz's revision 23730 for Ruby trunk
    #
    it "returns 1 when self is Infinity and other is a Bignum" do
      (infinity_value <=> Float::MAX.to_i*2).should == 1
    end

    it "returns -1 when self is negative and other is Infinty" do
      (-Float::MAX.to_i*2 <=> infinity_value).should == -1
    end

    it "returns -1 when self is -Infinity and other is negative" do
      (-infinity_value <=> -Float::MAX.to_i*2).should == -1
    end

    it "returns 1 when self is negative and other is -Infinity" do
      (-Float::MAX.to_i*2 <=> -infinity_value).should == 1
    end
  end
end