Refactor: add test cases

This commit is contained in:
Gayun00 2023-09-26 08:09:16 +09:00
parent b7857cb77b
commit 833f59f2ba
3 changed files with 58 additions and 11 deletions

View File

@ -9,9 +9,9 @@ export class GildedRose {
updateQuality() {
const updatedItems = this.items.map((item) => {
item.handleSellIn();
item.handleQuality();
item.handleSellIn();
return item;
});
return updatedItems as ItemClasses;

View File

@ -15,7 +15,11 @@ export class AgedBrie extends Item {
super("Aged Brie", sellIn, quality);
}
handleQuality() {
if (this.quality >= 50) return;
if (this.quality >= 50 || this.quality === 0) return;
if (this.sellIn === 0) {
this.quality = this.quality / 2;
return;
}
this.quality++;
}
@ -30,14 +34,20 @@ export class Passes extends Item {
}
handleQuality() {
if (this.quality >= 50 || this.quality === 0) return;
if (this.sellIn === 0) {
this.quality = 0;
return;
}
if (6 <= this.sellIn && this.sellIn < 11) {
this.quality += 1;
this.quality += 2;
}
if (this.sellIn < 6) {
this.quality += 2;
this.quality += 3;
}
this.quality++;
}
handleSellIn() {
@ -49,11 +59,8 @@ export class Surfras extends Item {
constructor(sellIn, quality) {
super("Sulfuras, Hand of Ragnaros", sellIn, quality);
}
handleQuality() {
//
}
handleSellIn() {
//
}
handleQuality() {}
handleSellIn() {}
}

View File

@ -22,6 +22,22 @@ describe("Aged Brie 테스트", () => {
expect(items[0].sellIn).toBe(1);
expect(items[0].quality).toBe(50);
});
it("quality는 음수가 될 수 없음", () => {
const gildedRose = new GildedRose([new AgedBrie(2, 0)]);
const items = gildedRose.updateQuality();
expect(items[0].sellIn).toBe(1);
expect(items[0].quality).toBe(0);
});
it("sellIn값이 0이 되면 Quality는 2배로 감소", () => {
const gildedRose = new GildedRose([new AgedBrie(1, 4)]);
const items = gildedRose.updateQuality();
expect(items[0].sellIn).toBe(0);
expect(items[0].quality).toBe(2);
});
});
describe("Surfras 테스트", () => {
@ -68,4 +84,28 @@ describe("Backstage passes 테스트", () => {
expect(items[0].sellIn).toBe(4);
expect(items[0].quality).toBe(6);
});
it("Backstage passes의 sellIn값 0일 때, quality 0으로 변경", () => {
const gildedRose = new GildedRose([new Passes(1, 3)]);
const items = gildedRose.updateQuality();
expect(items[0].sellIn).toBe(0);
expect(items[0].quality).toBe(0);
});
it("quality는 50을 초과할 수 없음", () => {
const gildedRose = new GildedRose([new AgedBrie(2, 50)]);
const items = gildedRose.updateQuality();
expect(items[0].sellIn).toBe(1);
expect(items[0].quality).toBe(50);
});
it("quality는 음수가 될 수 없음", () => {
const gildedRose = new GildedRose([new Passes(1, 0)]);
const items = gildedRose.updateQuality();
expect(items[0].sellIn).toBe(0);
expect(items[0].quality).toBe(0);
});
});