From 4dd71da770c1392409012e86c04cbbfc2ecad11f Mon Sep 17 00:00:00 2001 From: Ben Hemann Date: Mon, 7 Jun 2021 14:18:49 -0500 Subject: [PATCH] fixed typo in test code, some more simple refactoring done --- TypeScript/app/gilded-rose.ts | 9 ++++---- TypeScript/test/gilded-rose.spec.ts | 32 ++++++++++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/TypeScript/app/gilded-rose.ts b/TypeScript/app/gilded-rose.ts index f4083755..01da7352 100644 --- a/TypeScript/app/gilded-rose.ts +++ b/TypeScript/app/gilded-rose.ts @@ -30,16 +30,16 @@ export class GildedRose { if (this.items[i].quality < maxQuality) { this.items[i].quality += 1; if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { - if (this.items[i].sellIn <= 10) { + if (this.items[i].sellIn <= 10 && this.items[i].sellIn > 5) { // quality goes up by 2 when days are 10 or less if (this.items[i].quality < maxQuality) { this.items[i].quality += 1; } } // quality goes up by 3 when days are 5 of less - if (this.items[i].sellIn <= 5) { + else if (this.items[i].sellIn <= 5) { if (this.items[i].quality < maxQuality) { - this.items[i].quality += 1; + this.items[i].quality += 2; } } } @@ -60,8 +60,9 @@ export class GildedRose { } } + // set quality to 0 after sellIn date passes } else { - this.items[i].quality -= this.items[i].quality; + this.items[i].quality = 0; } // aged brie increases in quality here } else { diff --git a/TypeScript/test/gilded-rose.spec.ts b/TypeScript/test/gilded-rose.spec.ts index 686338b3..0e8c52df 100644 --- a/TypeScript/test/gilded-rose.spec.ts +++ b/TypeScript/test/gilded-rose.spec.ts @@ -167,25 +167,25 @@ describe('Testing with multiple items at once', () => { }); // Expect Sulfuras, Hand of Ragnaros sellIn to stay the same, all others to decrease it('should degrade all SellIn values on update', () => { - const itemss = gildedRose.updateQuality(); - expect(itemss[0].sellIn).to.equal(1); - expect(itemss[1].sellIn).to.equal(99); - expect(itemss[2].sellIn).to.equal(6); - expect(itemss[3].sellIn).to.equal(0); - expect(itemss[4].sellIn).to.equal(19); - expect(itemss[5].sellIn).to.equal(74); - expect(itemss[6].sellIn).to.equal(9); + const items = gildedRose.updateQuality(); + expect(items[0].sellIn).to.equal(1); + expect(items[1].sellIn).to.equal(99); + expect(items[2].sellIn).to.equal(6); + expect(items[3].sellIn).to.equal(0); + expect(items[4].sellIn).to.equal(19); + expect(items[5].sellIn).to.equal(74); + expect(items[6].sellIn).to.equal(9); }); // expect Sulfuras, Hand of Ragnaros quality to stay the same, Aged brie and Concert tickets to increase, all else to decrease it('should degrade all Quality values on update', () => { - const itemss = gildedRose.updateQuality(); - expect(itemss[0].quality).to.equal(80); - expect(itemss[1].quality).to.equal(0); - expect(itemss[2].quality).to.equal(12); - expect(itemss[3].quality).to.equal(49); - expect(itemss[4].quality).to.equal(24); - expect(itemss[5].quality).to.equal(44); - expect(itemss[6].quality).to.equal(14); + const items = gildedRose.updateQuality(); + expect(items[0].quality).to.equal(80); + expect(items[1].quality).to.equal(0); + expect(items[2].quality).to.equal(12); + expect(items[3].quality).to.equal(49); + expect(items[4].quality).to.equal(24); + expect(items[5].quality).to.equal(44); + expect(items[6].quality).to.equal(14); }); }); \ No newline at end of file