File: eql_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (109 lines) | stat: -rw-r--r-- 2,484 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
require 'spec_helper'
require 'set'

describe Immutable::Set do
  let(:set) { S[*values] }
  let(:comparison) { S[*comparison_values] }

  describe '#eql?' do
    let(:eql?) { set.eql?(comparison) }

    shared_examples 'comparing non-sets' do
      let(:values) { %w[A B C] }

      it 'returns false' do
        expect(eql?).to eq(false)
      end
    end

    context 'when comparing to a standard set' do
      let(:comparison) { ::Set.new(%w[A B C]) }

      include_examples 'comparing non-sets'
    end

    context 'when comparing to a arbitrary object' do
      let(:comparison) { Object.new }

      include_examples 'comparing non-sets'
    end

    context 'when comparing with a subclass of Immutable::Set' do
      let(:comparison) { Class.new(Immutable::Set).new(%w[A B C]) }

      include_examples 'comparing non-sets'
    end

    context 'with an empty set for each comparison' do
      let(:values) { [] }
      let(:comparison_values) { [] }

      it 'returns true' do
        expect(eql?).to eq(true)
      end
    end

    context 'with an empty set and a set with nil' do
      let(:values) { [] }
      let(:comparison_values) { [nil] }

      it 'returns false' do
        expect(eql?).to eq(false)
      end
    end

    context 'with a single item array and empty array' do
      let(:values) { ['A'] }
      let(:comparison_values) { [] }

      it 'returns false' do
        expect(eql?).to eq(false)
      end
    end

    context 'with matching single item array' do
      let(:values) { ['A'] }
      let(:comparison_values) { ['A'] }

      it 'returns true' do
        expect(eql?).to eq(true)
      end
    end

    context 'with mismatching single item array' do
      let(:values) { ['A'] }
      let(:comparison_values) { ['B'] }

      it 'returns false' do
        expect(eql?).to eq(false)
      end
    end

    context 'with a multi-item array and single item array' do
      let(:values) { %w[A B] }
      let(:comparison_values) { ['A'] }

      it 'returns false' do
        expect(eql?).to eq(false)
      end
    end

    context 'with matching multi-item array' do
      let(:values) { %w[A B] }
      let(:comparison_values) { %w[A B] }

      it 'returns true' do
        expect(eql?).to eq(true)
      end
    end

    context 'with a mismatching multi-item array' do
      let(:values) { %w[A B] }
      let(:comparison_values) { %w[B A] }

      it 'returns true' do
        expect(eql?).to eq(true)
      end
    end
  end
end