From cf0972f5bd30654c0f3ceff4c41a65b8a7be80a2 Mon Sep 17 00:00:00 2001 From: Stuart Kolodner Date: Fri, 31 Jan 2020 01:20:18 -0500 Subject: [PATCH] few more tests --- js-jest/src/gilded_rose.js | 21 +++++++++++++-------- js-jest/test/gilded_rose.test.js | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/js-jest/src/gilded_rose.js b/js-jest/src/gilded_rose.js index 2c893cf8..31eed80d 100644 --- a/js-jest/src/gilded_rose.js +++ b/js-jest/src/gilded_rose.js @@ -11,6 +11,10 @@ class Shop { this.items = items; } + isSulfuras(item) { + return item.name == 'Sulfuras, Hand of Ragnaros'; + } + // Should really be method on Item, but I don't want to offend the goblins. isAgedBrie(item) { return item.name.startsWith('Aged Brie'); @@ -28,22 +32,23 @@ class Shop { updateQuality() { for (let item of this.items) { - if (item.name == 'Sulfuras, Hand of Ragnaros') { - continue; - } - let qualityChange = 0; - if(this.isAgedBrie(item)) { + let sellInChange = -1; + + if (this.isSulfuras(item)) { + sellInChange = 0; + } else if(this.isAgedBrie(item)) { // Does conjured cheese quality increase twice as much? Assume not, but // statement of problem doesn't say cheese quality doubles twice as fast after // the sell by date, but the code implements it that way. qualityChange = item.sellIn <= 0 ? 2 : 1; } else if (this.isConcertTicket(item)) { if(item.sellIn <= 0) { + // This will set quality to 0 qualityChange = -1 * item.quality; - } else if(item.sellIn < 6) { + } else if(item.sellIn <= 5) { qualityChange = 3; - } else if(item.sellIn < 11) { + } else if(item.sellIn <= 10) { qualityChange = 2; } else { qualityChange = 1; @@ -55,7 +60,7 @@ class Shop { } } - item.sellIn--; + item.sellIn = item.sellIn + sellInChange; item.quality = Math.min(Math.max(item.quality + qualityChange, 0), 50); } diff --git a/js-jest/test/gilded_rose.test.js b/js-jest/test/gilded_rose.test.js index 8ff96d93..98ac7981 100644 --- a/js-jest/test/gilded_rose.test.js +++ b/js-jest/test/gilded_rose.test.js @@ -16,11 +16,26 @@ describe("Gilded Rose", function() { const items = gildedRose.updateQuality(); expect(items[0].quality).toBe(0); }); + it("foo quality should be 0", function() { + const gildedRose = new Shop([new Item("foo", 0, 1)]); + const items = gildedRose.updateQuality(); + expect(items[0].quality).toBe(0); + }); + it("foo quality should be 8", function() { + const gildedRose = new Shop([new Item("foo", 0, 10)]); + const items = gildedRose.updateQuality(); + expect(items[0].quality).toBe(8); + }); it("foo quality should be 0", function() { const gildedRose = new Shop([new Item("foo", 10, 10)]); const items = gildedRose.updateQuality(); expect(items[0].quality).toBe(9); }); + it("conjured quality should be 6", function() { + const gildedRose = new Shop([new Item("Conjured foo", 0, 10)]); + const items = gildedRose.updateQuality(); + expect(items[0].quality).toBe(6); + }); it("conjured quality should be 8", function() { const gildedRose = new Shop([new Item("Conjured foo", 10, 10)]); const items = gildedRose.updateQuality();