Created
November 2, 2015 06:51
-
-
Save kangkyu/44b57122b520c50f3d99 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
# She has asked you to create a method print_puzzle that prints the row of dashes for a required, single argument, word. The number of dashes or spaces should equal the amount of characters in the word. print_puzzle can also optionally take a list of characters as a second argument that represents the list of guessed letters. | |
# Given print_puzzle is called with the word "perimeter", your method should output: _ _ _ _ _ _ _ _ _ | |
# Given print_puzzle is called with the word "triangle" and the list of characters guessed: t,s,g, your method should output: t _ _ _ _ g _ _ | |
def print_puzzle(word, guessed_letters = []) | |
word.chars.map {|char| guessed_letters.include?(char) ? " #{char}" : " _"}.join | |
end | |
gem 'minitest' | |
require 'minitest/autorun' | |
class TestHang < Minitest::Test | |
def test_perimeter | |
assert_equal " _ _ _ _ _ _ _ _ _", print_puzzle("perimeter") | |
end | |
def test_triangle | |
assert_equal " t _ _ _ _ g _ _", print_puzzle("triangle", ['t', 's', 'g']) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment