File: exclusion_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 (47 lines) | stat: -rw-r--r-- 1,336 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
require 'spec_helper'

describe Immutable::Set do
  [:exclusion, :^].each do |method|
    describe "##{method}" do
      [
        [[], [], []],
        [['A'], [], ['A']],
        [['A'], ['A'], []],
        [%w[A B C], ['B'], %w[A C]],
        [%w[A B C], %w[B C D], %w[A D]],
        [%w[A B C], %w[D E F], %w[A B C D E F]],
      ].each do |a, b, expected|
        context "for #{a.inspect} and #{b.inspect}" do
          let(:set_a) { S[*a] }
          let(:set_b) { S[*b] }
          let(:result) { set_a.send(method, set_b) }

          it "doesn't modify the original Sets" do
            result
            set_a.should eql(S.new(a))
            set_b.should eql(S.new(b))
          end

          it "returns #{expected.inspect}"  do
            result.should eql(S[*expected])
          end
        end

        context 'when passed a Ruby Array' do
          it 'returns the expected Set' do
            S[*a].exclusion(b.freeze).should eql(S[*expected])
          end
        end
      end

      it 'works for a wide variety of inputs' do
        50.times do
          array1 = (1..400).to_a.sample(100)
          array2 = (1..400).to_a.sample(100)
          result = S.new(array1) ^ S.new(array2)
          result.to_a.sort.should eql(((array1 | array2) - (array1 & array2)).sort)
        end
      end
    end
  end
end