Updated updateQuantity function and test case file

This commit is contained in:
shabarishsomisetty 2022-04-15 21:59:07 +05:30
parent 181b48aff7
commit 3699ebb049
2 changed files with 80 additions and 41 deletions

View File

@ -12,51 +12,31 @@ class Shop {
} }
updateQuality() { updateQuality() {
for (let i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) { if(this.items[i].name !== 'Sulfuras') {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { if (this.items[i].name !== 'Aged Brie' && this.items[i].name !== 'Backstage passes') {
this.items[i].quality = this.items[i].quality - 1; if (this.items[i].sellIn <= 0) {
} if(this.items[i].name === 'Conjured' && this.items[i].quality - 4 > 0) {
} this.items[i].quality = this.items[i].quality - 4;
} else { } else if(this.items[i].quality - 2 > 0){
if (this.items[i].quality < 50) { this.items[i].quality = this.items[i].quality - 2;
this.items[i].quality = this.items[i].quality + 1;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].sellIn < 11) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1;
}
} }
if (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1;
}
}
}
}
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;
}
if (this.items[i].sellIn < 0) {
if (this.items[i].name != 'Aged Brie') {
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1;
}
}
} else {
this.items[i].quality = this.items[i].quality - this.items[i].quality;
} }
} else { } else {
if (this.items[i].quality < 50) { if ((this.items[i].sellIn <= 10 && this.items[i].sellIn >5) && this.items[i].quality + 2 <= 50) {
this.items[i].quality = this.items[i].quality + 2;
} else if ((this.items[i].sellIn <= 5 && this.items[i].sellIn > 0) && this.items[i].quality + 3 <= 50) {
this.items[i].quality = this.items[i].quality + 3;
} else if(this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1; this.items[i].quality = this.items[i].quality + 1;
} }
} }
} else {
if(this.items[i].quality < 80) {
this.items[i].quality = 80;
}
} }
} }
return this.items; return this.items;
} }
} }

View File

@ -1,9 +1,68 @@
const {Shop, Item} = require("../src/gilded_rose"); const {Shop, Item} = require("../src/gilded_rose");
describe("Gilded Rose", function() { describe("Gilded Rose with SellIn Zero", function() {
it("should foo", function() { it("Check Sulfuras quantity", function() {
const gildedRose = new Shop([new Item("foo", 0, 0)]); const gildedRose = new Shop([new Item("Sulfuras", 0, 78)]);
const items = gildedRose.updateQuality(); const items = gildedRose.updateQuality();
expect(items[0].name).toBe("fixme"); expect(items[0].quality).toBe(80);
})
it("Aged Brie to increase if SellIn is 0", function() {
const gildedRose = new Shop([new Item("Aged Brie", 0, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(21);
}); });
it("Other item to decrease twice if SellIn is 0", function() {
const gildedRose = new Shop([new Item("Other item 1", 0, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(18);
});
it("Conjured to decrease twice of normal items if SellIn is 0", function() {
const gildedRose = new Shop([new Item("Conjured", 0, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(16);
});
it("Backstage passes to increase if SellIn is 0", function() {
const gildedRose = new Shop([new Item("Backstage passes", 0, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(21);
});
}); });
describe("Gilded Rose with SellIn Non Zero", function() {
it("Check Sulfuras quantity", function() {
const gildedRose = new Shop([new Item("Sulfuras", 2, 78)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(80);
})
it("Aged Brie to increase if SellIn is 4", function() {
const gildedRose = new Shop([new Item("Aged Brie", 4, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(23);
});
it("Other item quantity no change if SellIn is greater than 0", function() {
const gildedRose = new Shop([new Item("Other item 1", 5, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(20);
});
it("Conjured quantity no change if SellIn is greater than 0", function() {
const gildedRose = new Shop([new Item("Conjured", 6, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(20);
});
it("Backstage passes to increase if SellIn is 8", function() {
const gildedRose = new Shop([new Item("Backstage passes", 8, 20)]);
const items = gildedRose.updateQuality();
expect(items[0].quality).toBe(22);
});
});