Sha256: 06de7b911d74c655cae37ee01700337967ffc44eef2a98dacac72e2a8f564ca3

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Axiom::Types::Infinity, '#<=>' do
  subject { object <=> other }

  let(:object) { described_class.instance }

  [
    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 negative infinity' do
    let(:other) { Axiom::Types::NegativeInfinity.instance }

    it { should be(1) }

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

  context 'when the other object is 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

11 entries across 9 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
axiom-types-0.1.1 spec/unit/axiom/types/infinity/spaceship_operator_spec.rb
axiom-types-0.1.0 spec/unit/axiom/types/infinity/spaceship_operator_spec.rb