mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
commit
c36fb2b4ee
1
TypeScript/.gitignore
vendored
1
TypeScript/.gitignore
vendored
@ -9,4 +9,3 @@ test/**/*.js.map
|
||||
coverage
|
||||
.nyc_output
|
||||
.yarn
|
||||
.DS_Store
|
||||
5
TypeScript/app/constants.ts
Normal file
5
TypeScript/app/constants.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export const ITEMS = {
|
||||
BRIE: "Aged Brie",
|
||||
SURFRAS: "Sulfuras, Hand of Ragnaros",
|
||||
PASSES: "Backstage passes to a TAFKAL80ETC concert",
|
||||
};
|
||||
@ -1,3 +1,5 @@
|
||||
import { ITEMS } from "./constants";
|
||||
|
||||
export class Item {
|
||||
name: string;
|
||||
sellIn: number;
|
||||
@ -17,51 +19,52 @@ export class GildedRose {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
handleIfSellInIs0(item) {
|
||||
if (item.sellIn >= 0) return;
|
||||
|
||||
switch (item.name) {
|
||||
case ITEMS.BRIE:
|
||||
if (item.quality >= 50) return;
|
||||
item.quality = item.quality + 1;
|
||||
break;
|
||||
case ITEMS.SURFRAS:
|
||||
item.quality = 0;
|
||||
break;
|
||||
default:
|
||||
if (!item.quality) return;
|
||||
item.quality -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
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, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const item of this.items) {
|
||||
if (!item.quality) break;
|
||||
if (item.name != ITEMS.SURFRAS) {
|
||||
item.sellIn -= 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 {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1
|
||||
}
|
||||
}
|
||||
this.handleIfSellInIs0(item);
|
||||
|
||||
if (item.name != ITEMS.BRIE && item.name != ITEMS.PASSES) {
|
||||
if (item.name === ITEMS.SURFRAS) break;
|
||||
item.quality -= 1;
|
||||
}
|
||||
|
||||
if (item.quality >= 50) break;
|
||||
item.quality += 1;
|
||||
|
||||
this.handlePassesQuality(item);
|
||||
}
|
||||
|
||||
return this.items;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Item, GildedRose } from '../app/gilded-rose';
|
||||
import { Item, GildedRose } from "../app/gilded-rose";
|
||||
|
||||
const items = [
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
@ -10,22 +10,21 @@ const items = [
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)];
|
||||
|
||||
// new Item("Conjured Mana Cake", 3, 6)
|
||||
];
|
||||
|
||||
const gildedRose = new GildedRose(items);
|
||||
|
||||
let days: number = 2;
|
||||
if (process.argv.length > 2) {
|
||||
days = +process.argv[2];
|
||||
}
|
||||
days = +process.argv[2];
|
||||
}
|
||||
|
||||
for (let i = 0; i < days; i++) {
|
||||
console.log("-------- day " + i + " --------");
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(element => {
|
||||
console.log(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
||||
|
||||
items.forEach((element) => {
|
||||
console.log(element.name + " " + element.sellIn + " " + element.quality);
|
||||
});
|
||||
console.log();
|
||||
gildedRose.updateQuality();
|
||||
|
||||
@ -77,6 +77,4 @@ describe("Backstage passes 테스트", () => {
|
||||
expect(items[0].sellIn).toBe(4);
|
||||
expect(items[0].quality).toBe(6);
|
||||
});
|
||||
|
||||
// TODO: 콘서트 종료 후 quality 0으로 변경 테스트
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user