Sha256: 027b75adcc6842a25010391e73dd60512fa3376fd7e4aed09cb2d9500647bd70

Contents?: true

Size: 1.28 KB

Versions: 3

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Axiom::Types::NegativeInfinity, '.<=>' do
  subject { object <=> other }

  let(:object) { described_class }

  [
    1,                # Fixnum
    2**63,            # Bignum
    1.0,              # Float
    Rational(1, 1),   # Rational
    BigDecimal('1'),  # BigDecimal
  ].each do |number|
    context "when other object is a #{number.class}" do
      let(:other) { number }

      it { should be(-1) }

      it 'is symmetric' do
        should be(-(other <=> object))
      end
    end
  end

  context 'when the other object is infinity' do
    let(:other) { Axiom::Types::Infinity }

    it { should be(-1) }

    it 'is symmetric' do
      should be(-(other <=> object))
    end
  end

  context 'when the other object is negative infinity' do
    let(:other) { object }

    it { should be(0) }

    it 'is symmetric' do
      should be(other <=> object)
    end
  end

  context 'when the other object is -Float::INFINITY' do
    let(:other) { -Float::INFINITY }

    it { should be(0) }

    it 'is symmetric' do
      should be(other <=> object)
    end
  end

  context 'when the other object is not comparable' do
    let(:other) { 'string' }

    it { should be_nil }

    it 'is symmetric' do
      should be(other <=> object)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
axiom-types-0.0.5 spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb
axiom-types-0.0.4 spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb
axiom-types-0.0.3 spec/unit/axiom/types/negative_infinity/class_methods/spaceship_operator_spec.rb