fixed typo in test code, some more simple refactoring done

This commit is contained in:
Ben Hemann 2021-06-07 14:18:49 -05:00
parent ba05d9fb40
commit 4dd71da770
2 changed files with 21 additions and 20 deletions

View File

@ -30,16 +30,16 @@ export class GildedRose {
if (this.items[i].quality < maxQuality) { if (this.items[i].quality < maxQuality) {
this.items[i].quality += 1; this.items[i].quality += 1;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { 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 // quality goes up by 2 when days are 10 or less
if (this.items[i].quality < maxQuality) { if (this.items[i].quality < maxQuality) {
this.items[i].quality += 1; this.items[i].quality += 1;
} }
} }
// quality goes up by 3 when days are 5 of less // 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) { 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 { } else {
this.items[i].quality -= this.items[i].quality; this.items[i].quality = 0;
} }
// aged brie increases in quality here // aged brie increases in quality here
} else { } else {

View File

@ -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 // Expect Sulfuras, Hand of Ragnaros sellIn to stay the same, all others to decrease
it('should degrade all SellIn values on update', () => { it('should degrade all SellIn values on update', () => {
const itemss = gildedRose.updateQuality(); const items = gildedRose.updateQuality();
expect(itemss[0].sellIn).to.equal(1); expect(items[0].sellIn).to.equal(1);
expect(itemss[1].sellIn).to.equal(99); expect(items[1].sellIn).to.equal(99);
expect(itemss[2].sellIn).to.equal(6); expect(items[2].sellIn).to.equal(6);
expect(itemss[3].sellIn).to.equal(0); expect(items[3].sellIn).to.equal(0);
expect(itemss[4].sellIn).to.equal(19); expect(items[4].sellIn).to.equal(19);
expect(itemss[5].sellIn).to.equal(74); expect(items[5].sellIn).to.equal(74);
expect(itemss[6].sellIn).to.equal(9); 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 // 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', () => { it('should degrade all Quality values on update', () => {
const itemss = gildedRose.updateQuality(); const items = gildedRose.updateQuality();
expect(itemss[0].quality).to.equal(80); expect(items[0].quality).to.equal(80);
expect(itemss[1].quality).to.equal(0); expect(items[1].quality).to.equal(0);
expect(itemss[2].quality).to.equal(12); expect(items[2].quality).to.equal(12);
expect(itemss[3].quality).to.equal(49); expect(items[3].quality).to.equal(49);
expect(itemss[4].quality).to.equal(24); expect(items[4].quality).to.equal(24);
expect(itemss[5].quality).to.equal(44); expect(items[5].quality).to.equal(44);
expect(itemss[6].quality).to.equal(14); expect(items[6].quality).to.equal(14);
}); });
}); });