mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
Made Rule class to hold the rules for each item
This commit is contained in:
parent
1d0671a186
commit
2454d1d0e8
@ -1,16 +1,35 @@
|
||||
class Item {
|
||||
constructor(name, sellIn, quality){
|
||||
constructor(name, sellIn, quality) {
|
||||
this.name = name;
|
||||
this.sellIn = sellIn;
|
||||
this.quality = quality;
|
||||
}
|
||||
}
|
||||
|
||||
class Rules {
|
||||
constructor(dailyQualityChangeValue, maxQuality, minQuality, tenDayChange, fiveDayChange,
|
||||
isZeroDayQualityDrop, zeroDayQualityValue) {
|
||||
this.dailyQualityChangeValue = dailyQualityChangeValue;
|
||||
this.maxQuality = maxQuality;
|
||||
this.minQuality = minQuality;
|
||||
this.tenDayChange = tenDayChange;
|
||||
this.fiveDayChange = fiveDayChange;
|
||||
this.isZeroDayQualityDrop = isZeroDayQualityDrop;
|
||||
this.zeroDayQualityValue = zeroDayQualityValue;
|
||||
}
|
||||
}
|
||||
|
||||
class Shop {
|
||||
constructor(items=[]){
|
||||
constructor(items = []) {
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
|
||||
updateQuality() {
|
||||
const rules = {
|
||||
'Aged Brie': new Rules(1, 50, 0, 1, 1),
|
||||
'Backstage passes to a TAFKAL80ETC concert': new Rules(1, 50, 0)
|
||||
}
|
||||
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) {
|
||||
|
||||
@ -1,9 +1,23 @@
|
||||
const {Shop, Item} = require("../src/gilded_rose");
|
||||
const { Shop, Item } = require("../src/gilded_rose");
|
||||
|
||||
describe("Gilded Rose", function() {
|
||||
it("should foo", function() {
|
||||
describe("Gilded Rose", function () {
|
||||
it("should foo", function () {
|
||||
const gildedRose = new Shop([new Item("foo", 0, 0)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe("fixme");
|
||||
expect(items[0].name).toBe("foo");
|
||||
});
|
||||
|
||||
it("Aged Brie test", function () {
|
||||
const items = [
|
||||
new Item("Aged Brie", 2, 0),
|
||||
];
|
||||
const gildedRose = new Shop(items);
|
||||
for (let day = 0; day < 4; day++) {
|
||||
console.log(`\n-------- day ${day} --------`);
|
||||
console.log("name, sellIn, quality");
|
||||
items.forEach(item => console.log(`${item.name}, ${item.sellIn}, ${item.quality}`));
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
expect(items[0].name).toBe("Aged Brie");
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user