Created
March 18, 2016 00:02
-
-
Save kkchu791/ddeb240abe8b4c157816 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_num(arr) | |
arr.each_with_object({}) { |i, hash| hash[i] = arr.count(i) } | |
end | |
gem 'minitest', '>= 5.0.0' | |
require 'minitest/autorun' | |
class CountTest < Minitest::Test | |
def test_count | |
count = count_num([1, 1, 1, 2, 5, 5]) | |
correct_count = { 1 => 3, 2 => 1, 5 => 2 } | |
assert_equal correct_count, count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment