Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby code test for Zelis #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Pretty basic. But here is where it gets interesting...

- The quality of an award is never negative.

- "Blue First" awards actually increase in quality the older they get
- "Blue First" awards actually increase in quality the older they get.

- The quality of an award is never more than 50
- The quality of an award is never more than 50.

- "Blue Distinction Plus", being a highly sought distinction, never decreases in quality
- "Blue Distinction Plus", being a highly sought distinction, never decreases in quality.

- "Blue Compare", similar to "Blue First", increases in quality as the expiration date approaches; Quality increases by 2 when there are 10 days or less left, and by 3 where there are 5 days or less left, but quality value drops to 0 after the expiration date.

Expand Down
102 changes: 60 additions & 42 deletions update_quality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,66 @@

def update_quality(awards)
awards.each do |award|
if award.name != 'Blue First' && award.name != 'Blue Compare'
if award.quality > 0
if award.name != 'Blue Distinction Plus'
award.quality -= 1
end
end
else
if award.quality < 50
award.quality += 1
if award.name == 'Blue Compare'
if award.expires_in < 11
if award.quality < 50
award.quality += 1
end
end
if award.expires_in < 6
if award.quality < 50
award.quality += 1
end
end
end
end
end
if award.name != 'Blue Distinction Plus'
award.expires_in -= 1
end
if award.expires_in < 0
if award.name != 'Blue First'
if award.name != 'Blue Compare'
if award.quality > 0
if award.name != 'Blue Distinction Plus'
award.quality -= 1
end
end
else
award.quality = award.quality - award.quality
end
else
if award.quality < 50
award.quality += 1
end
end
case award.name
when 'Blue First'
blue_first(award)
expire_decay(award)

when 'Blue Compare'
blue_compare(award)
expire_decay(award)

when 'Blue Distinction Plus'
blue_dist_plus(award)

when 'Blue Star'
blue_star(award)
expire_decay(award)

else
normal_award(award)
expire_decay(award)
end

check_quality_upper(award)
check_quality_lower(award)
end
end

def check_quality_upper(award)
award.quality = 50 if award.quality > 50 and award.name != 'Blue Distinction Plus'
end

def check_quality_lower(award)
award.quality = 0 if award.quality < 0
end

def expire_decay(award)
award.expires_in -= 1
end

def normal_award(award)
award.quality -= 1
award.quality -= 1 if award.expires_in <= 0
end

def blue_first(award)
award.quality += 1
award.quality += 1 if award.expires_in <= 0
end

def blue_compare(award)
award.quality += 1
award.quality += 1 if award.expires_in < 11
award.quality += 1 if award.expires_in < 6
award.quality = award.quality - award.quality if award.expires_in <= 0
end

def blue_dist_plus(award)
award.quality = 80
end

def blue_star(award)
award.quality -= 2
award.quality -= 2 if award.expires_in <= 0
end
1 change: 0 additions & 1 deletion update_quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
end

context 'given a Blue Star award' do
before { pending }
let(:name) { 'Blue Star' }
before { award.expires_in.should == initial_expires_in-1 }

Expand Down