Created
February 17, 2015 01:14
-
-
Save SolomonHD/27775d42a3c6f92dbb8c to your computer and use it in GitHub Desktop.
16FEB15 Quiz
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
require 'minitest/autorun' | |
require 'minitest/pride' | |
# Write a method which returns a hash. | |
# WRITE YOUR CODE HERE. Name your method `get_hash`. | |
def get_hash | |
hash= {"Pizza" => "Unhealthy", | |
"French Fries" => "Okay", | |
"Broccoli" => "Healthy", | |
"Chocolate" => "Healthy", | |
} | |
end | |
class HashChallenge < MiniTest::Test | |
def test_keys | |
assert get_hash.keys.include?("Pizza") | |
assert get_hash.keys.include?("French Fries") | |
assert get_hash.keys.include?("Broccoli") | |
refute get_hash.keys.include?("Bricks") | |
refute get_hash.keys.include?("Cars") | |
end | |
def test_values | |
assert get_hash.values.include?("Unhealthy") | |
assert get_hash.values.include?("Okay") | |
assert get_hash.values.include?("Healthy") | |
refute get_hash.values.include?("Blue") | |
refute get_hash.values.include?("Sharp") | |
end | |
def test_lengths | |
assert_equal 4, get_hash.length | |
assert_equal 4, get_hash.values.length | |
end | |
def test_pairs | |
assert_equal "Healthy", get_hash["Broccoli"] | |
assert_equal "Healthy", get_hash["Chocolate"] | |
assert_equal nil, get_hash["Carrots"] | |
end | |
def test_each | |
get_hash.each do |k, v| | |
if k.length > 9 | |
assert_equal "Okay", v | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment