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
|
coverage
|
||||||
.nyc_output
|
.nyc_output
|
||||||
.yarn
|
.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 {
|
export class Item {
|
||||||
name: string;
|
name: string;
|
||||||
sellIn: number;
|
sellIn: number;
|
||||||
@ -17,51 +19,52 @@ export class GildedRose {
|
|||||||
this.items = items;
|
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() {
|
updateQuality() {
|
||||||
for (let i = 0; i < this.items.length; i++) {
|
for (const item of this.items) {
|
||||||
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
if (!item.quality) break;
|
||||||
if (this.items[i].quality > 0) {
|
if (item.name != ITEMS.SURFRAS) {
|
||||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
item.sellIn -= 1;
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
this.handleIfSellInIs0(item);
|
||||||
this.items[i].sellIn = this.items[i].sellIn - 1;
|
|
||||||
}
|
if (item.name != ITEMS.BRIE && item.name != ITEMS.PASSES) {
|
||||||
if (this.items[i].sellIn < 0) {
|
if (item.name === ITEMS.SURFRAS) break;
|
||||||
if (this.items[i].name != 'Aged Brie') {
|
item.quality -= 1;
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.quality >= 50) break;
|
||||||
|
item.quality += 1;
|
||||||
|
|
||||||
|
this.handlePassesQuality(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.items;
|
return this.items;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Item, GildedRose } from '../app/gilded-rose';
|
import { Item, GildedRose } from "../app/gilded-rose";
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
new Item("+5 Dexterity Vest", 10, 20), //
|
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", 10, 49),
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
// this conjured item does not work properly yet
|
// 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);
|
const gildedRose = new GildedRose(items);
|
||||||
|
|
||||||
let days: number = 2;
|
let days: number = 2;
|
||||||
if (process.argv.length > 2) {
|
if (process.argv.length > 2) {
|
||||||
days = +process.argv[2];
|
days = +process.argv[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < days; i++) {
|
for (let i = 0; i < days; i++) {
|
||||||
console.log("-------- day " + i + " --------");
|
console.log("-------- day " + i + " --------");
|
||||||
console.log("name, sellIn, quality");
|
console.log("name, sellIn, quality");
|
||||||
items.forEach(element => {
|
items.forEach((element) => {
|
||||||
console.log(element.name + ' ' + element.sellIn + ' ' + element.quality);
|
console.log(element.name + " " + element.sellIn + " " + element.quality);
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log();
|
console.log();
|
||||||
gildedRose.updateQuality();
|
gildedRose.updateQuality();
|
||||||
|
|||||||
@ -77,6 +77,4 @@ describe("Backstage passes 테스트", () => {
|
|||||||
expect(items[0].sellIn).toBe(4);
|
expect(items[0].sellIn).toBe(4);
|
||||||
expect(items[0].quality).toBe(6);
|
expect(items[0].quality).toBe(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: 콘서트 종료 후 quality 0으로 변경 테스트
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user