Refactor: check test, delete previous functions

This commit is contained in:
Gayun00 2023-09-26 00:07:59 +09:00
parent 77c82c95b3
commit b7857cb77b
2 changed files with 12 additions and 74 deletions

View File

@ -1,69 +1,19 @@
import { ITEMS } from "./constants";
import { Item } from "./itemClasses";
import { AgedBrie, Passes, Surfras } from "./itemClasses";
type ItemClasses = AgedBrie[] | Surfras[] | Passes[];
export class GildedRose {
items: Array<Item>;
constructor(items = [] as Array<Item>) {
items: ItemClasses;
constructor(items = [] as ItemClasses) {
this.items = items;
}
handleSellIn(item) {
//
if (item.name != ITEMS.SURFRAS) {
item.sellIn -= 1;
}
if (item.sellIn >= 0) return;
if (item.quality >= 50) return;
//
switch (item.name) {
case ITEMS.BRIE:
item.quality = item.quality + 1;
break;
case ITEMS.SURFRAS:
item.quality = 0;
break;
default:
item.quality -= 1;
break;
}
}
handlePassesQuality(item) {
//
if (item.name !== ITEMS.PASSES) return;
if (6 <= item.sellIn && item.sellIn < 11) {
item.quality += 1;
}
if (item.sellIn < 6) {
item.quality += 2;
}
}
handleQuality(item) {
//
switch (item.name) {
case ITEMS.PASSES:
this.handlePassesQuality(item);
break;
case ITEMS.SURFRAS:
item.quality -= 1;
break;
}
if (item.quality >= 50) return;
item.quality += 1;
}
updateQuality() {
for (const item of this.items) {
if (!item.quality) break;
this.handleSellIn(item);
this.handleQuality(item);
}
const updatedItems = this.items.map((item) => {
item.handleQuality();
return this.items;
item.handleSellIn();
return item;
});
return updatedItems as ItemClasses;
}
}

View File

@ -8,14 +8,6 @@ export class Item {
this.sellIn = sellIn;
this.quality = quality;
}
handleQuality() {
//
}
handleSellIn() {
//
}
}
export class AgedBrie extends Item {
@ -23,7 +15,7 @@ export class AgedBrie extends Item {
super("Aged Brie", sellIn, quality);
}
handleQuality() {
this.quality++;
if (this.quality >= 50) return;
this.quality++;
}
@ -38,8 +30,6 @@ export class Passes extends Item {
}
handleQuality() {
this.quality--;
if (6 <= this.sellIn && this.sellIn < 11) {
this.quality += 1;
}
@ -60,9 +50,7 @@ export class Surfras extends Item {
super("Sulfuras, Hand of Ragnaros", sellIn, quality);
}
handleQuality() {
this.quality = 0;
this.quality--;
this.quality++;
//
}
handleSellIn() {