Created
January 19, 2015 19:49
-
-
Save mikedao/2947fa19be556582fa0b 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 Phoenix | |
attr_reader :name, :age, :lives, :revives | |
def initialize(name, age=0) | |
@name = name | |
@age = age | |
@alive = true | |
@lives = 0 | |
@revives = 0 | |
end | |
def celebrate_birthday | |
@age += 1 | |
end | |
def adult? | |
age > 300 | |
end | |
def infant? | |
!adult? | |
end | |
def alive? | |
@alive | |
end | |
def burn! | |
@alive = false | |
end | |
def dead? | |
!alive? | |
end | |
def revive! | |
if @revives < 10 | |
@alive = true | |
@lives += 1 | |
@revives += 1 | |
else | |
"YOU ARE NOT IMMORTAL" | |
end | |
end | |
def fairykiss | |
@revives += 10 | |
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
class Phoenix | |
attr_reader :name, :age, :lives | |
def initialize(name) | |
@name = name | |
@age = 0 | |
@lives = 1 | |
@alive = true | |
end | |
def adult? | |
@age > 300 | |
end | |
def infant? | |
!adult? | |
end | |
def cakeday! | |
@age += 1 | |
end | |
def revive! | |
unless lives > 10 | |
@lives += 1 | |
@alive = true | |
end | |
end | |
def burn! | |
@alive = false | |
end | |
def alive? | |
@alive | |
end | |
def dead? | |
!alive? | |
end | |
def happy_ending | |
@lives -= 10 | |
end | |
end | |
class Fairy | |
def magic_kiss(phoenix) | |
phoenix.happy_ending | |
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
gem 'minitest', '~> 5.2' | |
require 'minitest/autorun' | |
require 'minitest/pride' | |
require_relative 'phoenix' | |
class PhoenixTest < Minitest::Test | |
def test_it_has_a_name | |
phoenix = Phoenix.new("Frank") | |
assert_equal "Frank", phoenix.name | |
end | |
def test_it_has_an_age | |
phoenix = Phoenix.new("Frank", 74) | |
assert_equal 74, phoenix.age | |
end | |
def test_is_an_adult_after_300_years | |
phoenix = Phoenix.new("Frank", 301) | |
assert phoenix.adult? | |
end | |
def test_phoenix_ages | |
phoenix = Phoenix.new("Frank", 74) | |
phoenix.celebrate_birthday | |
assert_equal 75, phoenix.age | |
end | |
def test_is_it_an_infant | |
phoenix = Phoenix.new("Frank", 74) | |
assert phoenix.infant? | |
end | |
def test_is_it_alive | |
phoenix = Phoenix.new("Frank", 74) | |
assert phoenix.alive? | |
end | |
def test_is_it_dead_and_burn_kills_it | |
phoenix = Phoenix.new("Frank", 74) | |
phoenix.burn! | |
assert phoenix.dead? | |
end | |
def test_when_dead_it_can_revive | |
phoenix = Phoenix.new("Frank", 74) | |
phoenix.burn! | |
assert phoenix.dead? | |
phoenix.revive! | |
refute phoenix.dead? | |
end | |
def test_when_it_revives_lives_gets_incremented | |
phoenix = Phoenix.new("Frank", 74) | |
phoenix.burn! | |
phoenix.revive! | |
assert_equal 1, phoenix.lives | |
end | |
def test_can_only_revive_ten_times | |
phoenix = Phoenix.new("Frank", 74) | |
10.times do | |
phoenix.burn! | |
phoenix.revive! | |
end | |
phoenix.burn! | |
phoenix.revive! | |
assert phoenix.dead? | |
end | |
def test_fairy_kiss_gives_ten_more_revives | |
phoenix = Phoenix.new("Frank", 74) | |
phoenix.fairykiss | |
assert_equal 10, phoenix.revives | |
end | |
end | |
# Will have: | |
# | |
# name | |
# age | |
# it will become an adult after 300 years | |
# adult? | |
# infant? | |
# dead? | |
# burn! kills phoenix | |
# revive! | |
# alive? | |
# lives - count | |
# can only revive 10 times | |
# fairy kisses phoenix it can revive another times | |
# | |
# | |
# | |
# |
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
gem 'minitest', '~> 5.2' | |
require 'minitest/autorun' | |
require 'minitest/pride' | |
require_relative 'phoenix_revised' | |
class PhoenixTest < Minitest::Test | |
def phoenix | |
@phoenix ||=Phoenix.new("Joaquin") | |
end | |
def test_it_has_a_name | |
assert_equal "Joaquin", phoenix.name | |
end | |
def test_it_has_an_age | |
assert_equal 0, phoenix.age | |
end | |
def test_it_becomes_adult_after_300_years | |
assert phoenix.infant? | |
301.times do | |
phoenix.cakeday! | |
end | |
assert phoenix.adult? | |
end | |
def test_is_it_alive_when_created | |
assert phoenix.alive? | |
end | |
def test_is_it_dead_when_burned | |
phoenix.burn! | |
assert phoenix.dead? | |
end | |
def test_it_is_alive_after_revived | |
phoenix.burn! | |
assert phoenix.dead? | |
phoenix.revive! | |
assert phoenix.alive? | |
end | |
def test_it_has_lives | |
assert_equal 1, phoenix.lives | |
end | |
def test_it_can_only_revive_ten_times | |
11.times do | |
phoenix.burn! | |
phoenix.revive! | |
end | |
assert phoenix.dead? | |
end | |
def test_it_can_revive_after_magic_kiss | |
11.times do | |
phoenix.burn! | |
phoenix.revive! | |
end | |
assert phoenix.dead? | |
fairy = Fairy.new() | |
fairy.magic_kiss(phoenix) | |
phoenix.revive! | |
assert phoenix.alive? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment