Sha256: 15ff3135cca2eebffc938e14362e0a19be79dcf7725dba6cb146cc5c8061fe33

Contents?: true

Size: 791 Bytes

Versions: 171

Compression:

Stored size: 791 Bytes

Contents

require 'test_helper'
require 'tins/xt'

module Tins
  class UniqByTest < Test::Unit::TestCase

    unless defined?(Point)
      class Point < Struct.new :x, :y
      end
    end

    def test_uniq_by
      assert_equal [ 1, 2, 3 ], [ 1, 2, 2, 3 ].uniq_by.sort
      a = [ 1, 2, 2, 3 ]; a.uniq_by!
      assert_equal [ 1, 2, 3 ], a.sort
      p1 = Point.new 1, 2
      p2 = Point.new 2, 2
      p3 = Point.new 2, 2
      p4 = Point.new 3, 3
      a = [ p1, p2, p3, p4 ]
      a_uniq = a.uniq_by { |p| p.y }
      assert_equal 2, a_uniq.size
      assert a_uniq.include?(p4)
      assert [ p1, p2, p3 ].any? { |p| a_uniq.include? p }
      a.uniq_by! { |p| p.y }
      assert_equal 2, a.size
      assert a.include?(p4)
      assert [ p1, p2, p3 ].any? { |p| a.include? p }
    end
  end
end

Version data entries

171 entries across 153 versions & 9 rubygems

Version Path
tins-1.38.0 tests/uniq_by_test.rb
tins-1.37.1 tests/uniq_by_test.rb
tins-1.37.0 tests/uniq_by_test.rb
tins-1.36.1 tests/uniq_by_test.rb
tins-1.36.0 tests/uniq_by_test.rb
tins-1.35.0 tests/uniq_by_test.rb
tins-1.34.0 tests/uniq_by_test.rb
tins-1.33.0 tests/uniq_by_test.rb
tdiary-5.2.4 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/uniq_by_test.rb
tins-1.32.1 tests/uniq_by_test.rb
tins-1.32.0 tests/uniq_by_test.rb
tdiary-5.2.3 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/uniq_by_test.rb
tdiary-5.2.2 vendor/bundle/ruby/3.1.0/gems/tins-1.31.1/tests/uniq_by_test.rb
tins-1.31.1 tests/uniq_by_test.rb
tdiary-5.2.1 vendor/bundle/ruby/3.1.0/gems/tins-1.31.0/tests/uniq_by_test.rb
tins-1.31.0 tests/uniq_by_test.rb
tins-1.30.0 tests/uniq_by_test.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/tins-1.29.1/tests/uniq_by_test.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/uniq_by_test.rb
tdiary-5.1.7 vendor/bundle/ruby/3.0.0/gems/tins-1.29.1/tests/uniq_by_test.rb