File: spec_helper.rb

package info (click to toggle)
ruby-multimap 1.1.2%2Bgh-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 228 kB
  • ctags: 96
  • sloc: ruby: 1,464; ansic: 18; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (2)
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
require 'multiset'
require 'multimap'
require 'nested_multimap'

require 'enumerable_examples'
require 'hash_examples'
require 'set_examples'

# Rubinius Hash isn't ordered by insert order
Spec::Matchers.define :sorted_eql do |expected|
  if defined? Rubinius
    sorter = lambda { |a, b| a.hash <=> b.hash }
    match do |actual|
      actual.sort(&sorter).should eql(expected.sort(&sorter))
    end
  else
    match do |actual|
      actual.should eql(expected)
    end
  end
end

require 'set'

if defined? Rubinius
  class Set
    def <=>(other)
      to_a <=> other.to_a
    end
  end
end

require 'forwardable'

class MiniArray
  extend Forwardable

  attr_accessor :data

  def initialize(data = [])
    @data = data
  end

  def initialize_copy(orig)
    @data = orig.data.dup
  end

  def_delegators :@data, :<<, :each, :delete, :delete_if

  def ==(other)
    other.is_a?(self.class) && @data == other.data
  end

  def eql?(other)
    other.is_a?(self.class) && @data.eql?(other.data)
  end

  if defined? Rubinius
    def hash
      @data.hash
    end

    def <=>(other)
      @data <=> other.data
    end
  end
end