From 18f3bd69240f2c32a439499f37bde7f302f31753 Mon Sep 17 00:00:00 2001 From: kamheer8 Date: Tue, 2 Aug 2022 00:50:22 -0500 Subject: [PATCH] updated awards, update_quality, update_quality_spec files, so that all tests passed --- .DS_Store | Bin 0 -> 6148 bytes award.rb | 97 ++++++++++++++++++++++++++++++++++++++++- update_quality.rb | 44 +------------------ update_quality_spec.rb | 1 - 4 files changed, 97 insertions(+), 45 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..1c7ffd31623b400bf559bac7c0209afe8c0a79df GIT binary patch literal 6148 zcmeHKJx;?=47O>8NGu%~7~hN#Qf~05!iKu^0#&J0kXj`J3`}G}9D{3c01npAKdlm? zt_)yHeqWyLFE9CqI3^;Vy{s#uDG`-$LHdwoY?2or*_lTQAj>_rn`-gU?AlS~>40zx zx}gm{(er@M*YkdE*VOfD+pG{P-#@Ra*Zc3=VSatgzkRhAKlANl@7X2^)UZ$>6bJ=E zfl%OIDuA9XR-PNi8VZC0p}b_0xexM*yJw#;f64X9-}E05CgthKRt} zs6eB#j~Hxp#FN)$$Ij5`#CkIB<0rFED6FR=p0u1e8^#(6gaShaCbpeQ|G$HunE!{Q z*o6Y2z@Jipi+WMd@JilWM=vM6Ho=$hgP~T-v1ls>YAeP@TJdGCF3C0W*|9TJI^s$P O#*cvL5*7;lh5~!Y87F1{ literal 0 HcmV?d00001 diff --git a/award.rb b/award.rb index 5208232..c941a22 100644 --- a/award.rb +++ b/award.rb @@ -1 +1,96 @@ -Award = Struct.new(:name, :expires_in, :quality) +# Award = Struct.new(:name, :expires_in, :quality) + +class Award + + attr_accessor :name, :expires_in, :quality + + def initialize(name, int_expires_in, int_quality) + @name = name + @expires_in = int_expires_in + @quality = int_quality + end + + def update_award + case @name + when 'Blue Compare' + update_blue_compare + when 'Blue Distinction Plus' + update_blue_distinction_plus + when 'Blue First' + update_blue_first + when 'Blue Star' + update_blue_star + when 'NORMAL ITEM' + update_normal_item + end + end + + private + + def expired? + @expires_in <= 0 + end + + def max_quality? + if @quality >= 50 + @quality = 50 + return true + else + return false + end + end + + def quality_larger_than_zero? + @quality > 0 + end + + def update_blue_compare + if expired? + @quality = 0 + elsif @expires_in <= 5 + @quality = @quality + 3 + elsif @expires_in <= 10 + @quality = @quality + 2 + else + @quality = @quality + 1 + end + max_quality? + @expires_in = @expires_in - 1 + end + + def update_blue_distinction_plus + @quality = 80 + end + + def update_blue_first + if !expired? + @quality = @quality + 1 + else + @quality = @quality + 2 + end + max_quality? + @expires_in = @expires_in - 1 + end + + def update_blue_star + if quality_larger_than_zero? + @quality = @quality - 2 + end + @expires_in = @expires_in - 1 + if expired? && quality_larger_than_zero? + @quality = @quality - 2 + end + end + + def update_normal_item + if quality_larger_than_zero? + @quality = @quality - 1 + end + @expires_in = expires_in - 1 + if expired? && quality_larger_than_zero? + @quality = @quality - 1 + end + end + +end + diff --git a/update_quality.rb b/update_quality.rb index bd1f10f..93f78ac 100644 --- a/update_quality.rb +++ b/update_quality.rb @@ -2,48 +2,6 @@ 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 - end + award.update_award end end diff --git a/update_quality_spec.rb b/update_quality_spec.rb index 973940d..879da5a 100644 --- a/update_quality_spec.rb +++ b/update_quality_spec.rb @@ -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 }