Created
April 18, 2018 17:57
-
-
Save barangerbenjamin/4c708fab4b16651c071532f69169ee8e 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 Citizen | |
def initialize(first_name, last_name, age) | |
@first_name = first_name | |
@last_name = last_name | |
@age = age | |
end | |
def can_vote? | |
@age >= 18 | |
end | |
def full_name | |
@first_name.capitalize + " " + @last_name.capitalize | |
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
# GUIDELINES | |
# require the proper file | |
require_relative "../citizen" | |
describe Citizen do | |
describe "#can_vote?" do | |
it "should be true if the citizen is more than 18 years old" do | |
my_citizen = Citizen.new("", "", 19) | |
expect(my_citizen.can_vote?).to eq(true) | |
end | |
it "should be true if the citizen is 18 years old" do | |
my_citizen = Citizen.new("", "", 18) | |
expect(my_citizen.can_vote?).to eq(true) | |
end | |
it "should be false if the citizen is less than 18 years old" do | |
my_citizen = Citizen.new("", "", 17) | |
expect(my_citizen.can_vote?).to eq(false) | |
end | |
end | |
describe "#full_name" do | |
it "should return the full name" do | |
my_citizen = Citizen.new("John", "Lennon", 0) | |
expect(my_citizen.full_name).to eq("John Lennon") | |
end | |
it "should return the full name for lower-cased inputs" do | |
my_citizen = Citizen.new("john", "lennon", 0) | |
expect(my_citizen.full_name).to eq("John Lennon") | |
end | |
it "should return the full name for upper-cased inputs" do | |
my_citizen = Citizen.new("JOHN", "LENNON", 0) | |
expect(my_citizen.full_name).to eq("John Lennon") | |
end | |
it "should return the full name for 'crasy'-inputs" do | |
my_citizen = Citizen.new("JoHN", "LEnNOn", 0) | |
expect(my_citizen.full_name).to eq("John Lennon") | |
end | |
end | |
end | |
# tests for can_vote? method | |
# should be true if the citizen is more than 18 years old | |
# should be true if the citizen is 18 years old | |
# should be false if the citizen is less than 18 years old | |
# tests for full_name method | |
# should return the full name | |
# should return the full name for lower-cased inputs | |
# should return the full name for upper-cased inputs | |
# should return the full name for crasy-inputs |
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 SlotMachine | |
SYMBOLS = ["cherry", "seven", "bell", "star", "joker"].freeze | |
result = [] | |
def score(reels) | |
if reels.uniq.size == 1 | |
return (SYMBOLS.index(reels[0]) + 1) * 10 | |
elsif reels.uniq.size == 3 | |
return 0 | |
elsif reels.uniq.size == 2 | |
return (SYMBOLS.index(reels.sort[1]) + 1) * 5 | |
end | |
end | |
end | |
my_slot_machine = SlotMachine.new | |
p my_slot_machine.score(["cherry", "cherry", "bell"]) | |
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_relative '../slot_machine' | |
def test_scenario(reels, expected_score) | |
it "returns #{expected_score} for #{reels[0]}/#{reels[1]}/#{reels[2]}" do | |
slot_machine = SlotMachine.new | |
score = slot_machine.score(reels) | |
expect(score).to eq(expected_score) | |
end | |
end | |
describe SlotMachine do | |
describe '#score' do | |
it 'returns 0 for three different symbols' do | |
slot_machine = SlotMachine.new | |
score = slot_machine.score(%w[joker star bell]) | |
expect(score).to eq(0) | |
end | |
test_scenario(%w[joker joker joker], 50) | |
test_scenario(%w[star star star], 40) | |
test_scenario(%w[bell bell bell], 30) | |
test_scenario(%w[seven seven seven], 20) | |
test_scenario(%w[cherry cherry cherry], 10) | |
test_scenario(%w[joker joker star], 25) | |
test_scenario(%w[joker joker bell], 25) | |
test_scenario(%w[joker joker seven], 25) | |
test_scenario(%w[joker joker cherry], 25) | |
test_scenario(%w[star star joker], 20) | |
test_scenario(%w[bell bell joker], 15) | |
test_scenario(%w[seven seven joker], 10) | |
test_scenario(%w[cherry cherry joker], 5) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment