Last active
July 29, 2020 07:41
-
-
Save mrhead/93dc06644a541740a23d74f2f2fbc61d to your computer and use it in GitHub Desktop.
This file contains 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
# Count number of words in a locale file. | |
def word_count(hash) | |
hash.values.sum do |value| | |
if value.is_a?(Hash) | |
word_count(value) | |
else | |
value.split.size | |
end | |
end | |
end | |
# require "yaml" | |
# hash = YAML.load(File.read("config/locales/en.yml")) | |
# puts word_count(hash) | |
require 'minitest/autorun' | |
class Tests < MiniTest::Unit::TestCase | |
def test_1 | |
hash = { | |
a: "one two" | |
} | |
assert_equal 2, word_count(hash) | |
end | |
def test_2 | |
hash = { | |
a: "one two", | |
b: { | |
c: "three four", | |
d: "five" | |
} | |
} | |
assert_equal 5, word_count(hash) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment