Last active
August 16, 2024 03:02
-
-
Save raleighlittles/aaa06a1580e833d55ef1c38cd2a1caae to your computer and use it in GitHub Desktop.
Procore Interview
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 'rspec/autorun' | |
=begin | |
You are a Pokemon, hooray! | |
Pokemon have it tough though. Every day in the field of battle they are susceptible to dangerous status effects. Some status effects are stronger than others. | |
You can only be under the effects of one status effect at any time. That depends on the ranking of the status effect. | |
In our case, the status effect hierarchy is as follows: | |
Sleep > Paralyze > Confusion | |
So, if you are both Paralyzed and Confused, Paralyze is your current status effect. Confusion is still active on you, but you won't get harmed by confusion, since the effects of Paralyze outweigh the effects on Confusion. | |
Likewise, if you have all 3 status effects on you, Sleep's effects will outweigh Paralyze and Confusion, so Sleep will be your current active status effect. You will still have the durations of those effects on you and will expire after each of their durations. | |
You'll be writing a class to determine the strongest active status effect on a Pokemon at any given round. Each status effect has a name and duration (number of rounds) and can be applied at any time. | |
# Durations | |
# Sleep duration 7 | |
# Paralyze duration 4 | |
# Confusion duration 10 | |
=end | |
class Pokemon | |
def initialize(name) | |
end | |
def apply(status_effect, round_number) | |
end | |
def status_at(round_number) | |
end | |
RSpec.describe do | |
let(:magikarp) { Pokemon.new('magikarp') } | |
# Sleep duration 7 | |
# Paralyze duration 4 | |
# Confusion duration 10 | |
describe 'status_at' do | |
context 'effects' do | |
it 'handles one effect at a time' do | |
magikarp.apply('sleep', 1) | |
magikarp.apply('paralyze', 9) | |
aggregate_failures do | |
expect(magikarp.status_at(1)).to eq('sleep') | |
expect(magikarp.status_at(2)).to eq('sleep') | |
expect(magikarp.status_at(3)).to eq('sleep') | |
expect(magikarp.status_at(4)).to eq('sleep') | |
expect(magikarp.status_at(5)).to eq('sleep') | |
expect(magikarp.status_at(6)).to eq('sleep') | |
expect(magikarp.status_at(7)).to eq('sleep') | |
expect(magikarp.status_at(8)).to eq(nil) | |
expect(magikarp.status_at(9)).to eq('paralyze') | |
expect(magikarp.status_at(10)).to eq('paralyze') | |
expect(magikarp.status_at(11)).to eq('paralyze') | |
expect(magikarp.status_at(12)).to eq('paralyze') | |
expect(magikarp.status_at(13)).to eq(nil) | |
end | |
end | |
it 'handles two effects' do | |
magikarp.apply('confusion', 1) | |
magikarp.apply('paralyze', 4) | |
aggregate_failures do | |
expect(magikarp.status_at(1)).to eq('confusion') | |
expect(magikarp.status_at(2)).to eq('confusion') | |
expect(magikarp.status_at(3)).to eq('confusion') | |
expect(magikarp.status_at(4)).to eq('paralyze') | |
expect(magikarp.status_at(5)).to eq('paralyze') | |
expect(magikarp.status_at(6)).to eq('paralyze') | |
expect(magikarp.status_at(7)).to eq('paralyze') | |
expect(magikarp.status_at(8)).to eq('confusion') | |
expect(magikarp.status_at(9)).to eq('confusion') | |
expect(magikarp.status_at(10)).to eq('confusion') | |
expect(magikarp.status_at(11)).to eq(nil) | |
end | |
end | |
it 'handles multiple effects' do | |
magikarp.apply('confusion', 2) | |
magikarp.apply('sleep', 3) | |
magikarp.apply('paralyze', 7) | |
aggregate_failures do | |
expect(magikarp.status_at(1)).to eq(nil) | |
expect(magikarp.status_at(2)).to eq('confusion') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nintendo aah interview