Created
August 21, 2014 03:49
-
-
Save guilleiguaran/3c18ee61a29bb6ec4121 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
class User | |
attr_accessor :first_name, :last_name, :age | |
def initialize(first_name, last_name, age) | |
@first_name = first_name | |
@last_name = last_name | |
@age = age | |
end | |
def full_name | |
"#{@first_name} #{@last_name}" | |
end | |
def greet(name) | |
"#{first_name}: Hola #{name}" | |
end | |
def adult? | |
@age >= 18 | |
end | |
end |
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
require 'minitest/autorun' | |
require './user' | |
class UserTest < Minitest::Test | |
def setup | |
@user = User.new("Paola", "Garcia", 15) | |
end | |
def test_full_name | |
assert_equal "Paola Garcia", @user.full_name | |
end | |
def test_greet | |
assert_equal "Paola: Hola Leydis", @user.greet("Leydis") | |
end | |
def test_adult | |
@user.age = 18 | |
assert @user.adult? | |
end | |
def test_no_adult | |
@user.age = 17 | |
assert_equal false, @user.adult? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment