File: count_by_test.rb

package info (click to toggle)
ruby-tins 1.32.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,248 kB
  • sloc: ruby: 6,659; makefile: 3
file content (17 lines) | stat: -rw-r--r-- 556 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
require 'test_helper'
require 'tins/xt'

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

    def test_count_by
      assert_equal 0, [].count_by { |x| x % 2 == 0 }
      assert_equal 0, [ 1 ].count_by { |x| x % 2 == 0 }
      assert_equal 1, [ 1 ].count_by { |x| x % 2 == 1 }
      assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 0 }
      assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 1 }
      assert_equal 2, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 0 }
      assert_equal 3, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 1 }
    end
  end
end