mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
adding conjured rules with test
This commit is contained in:
parent
9d878b7641
commit
d6293cff29
@ -1,3 +1,16 @@
|
||||
export const RULES = [
|
||||
{
|
||||
name: "Aged Brie",
|
||||
qualityPerDay: 1,
|
||||
staticQuality: undefined,
|
||||
},
|
||||
{
|
||||
name: "Backstage passes to a TAFKAL80ETC concert",
|
||||
qualityPerDay: 1,
|
||||
staticQuality: undefined,
|
||||
}
|
||||
]
|
||||
|
||||
export class Item {
|
||||
name: string;
|
||||
sellIn: number;
|
||||
@ -19,49 +32,42 @@ export class GildedRose {
|
||||
|
||||
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
|
||||
switch (this.items[i].name) {
|
||||
case 'Aged Brie':
|
||||
if (this.items[i].quality < 50) {
|
||||
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
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Backstage passes to a TAFKAL80ETC concert':
|
||||
if (this.items[i].sellIn < 0) {
|
||||
this.items[i].quality = 0
|
||||
} else if (this.items[i].sellIn < 6) {
|
||||
this.items[i].quality += 3
|
||||
} else if (this.items[i].sellIn < 11) {
|
||||
this.items[i].quality += 2
|
||||
} else {
|
||||
this.items[i].quality += 1
|
||||
}
|
||||
if (this.items[i].quality > 50) {
|
||||
this.items[i].quality = 50
|
||||
}
|
||||
break;
|
||||
case 'Sulfuras, Hand of Ragnaros':
|
||||
this.items[i].quality = 80
|
||||
break;
|
||||
case 'Conjured Mana Cake':
|
||||
if (this.items[i].quality > 0) {
|
||||
this.items[i].quality -= 2
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (this.items[i].quality > 0) {
|
||||
this.items[i].quality -= 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.items;
|
||||
|
||||
@ -1,9 +1,39 @@
|
||||
import { Item, GildedRose } from '@/gilded-rose';
|
||||
|
||||
describe('Gilded Rose', () => {
|
||||
it('should foo', () => {
|
||||
const gildedRose = new GildedRose([new Item('foo', 0, 0)]);
|
||||
it('test: Aged Brie', () => {
|
||||
const gildedRose = new GildedRose([new Item('Aged Brie', 5, 5)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('fixme');
|
||||
expect(items[0].name).toBe('Aged Brie');
|
||||
expect(items[0].sellIn).toBe(4);
|
||||
expect(items[0].quality).toBe(6);
|
||||
});
|
||||
it('test: Backstage passes to a TAFKAL80ETC concert', () => {
|
||||
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 5, 5)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('Backstage passes to a TAFKAL80ETC concert');
|
||||
expect(items[0].sellIn).toBe(4);
|
||||
expect(items[0].quality).toBe(8);
|
||||
});
|
||||
it('test: Sulfuras, Hand of Ragnaros', () => {
|
||||
const gildedRose = new GildedRose([new Item('Sulfuras, Hand of Ragnaros', 5, 80)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('Sulfuras, Hand of Ragnaros');
|
||||
expect(items[0].sellIn).toBe(5);
|
||||
expect(items[0].quality).toBe(80);
|
||||
});
|
||||
it('test: Conjured Mana Cake', () => {
|
||||
const gildedRose = new GildedRose([new Item('Conjured Mana Cake', 5, 5)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('Conjured Mana Cake');
|
||||
expect(items[0].sellIn).toBe(4);
|
||||
expect(items[0].quality).toBe(3);
|
||||
});
|
||||
it('test: Elixir of the Mongoose', () => {
|
||||
const gildedRose = new GildedRose([new Item('Elixir of the Mongoose', 5, 5)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe('Elixir of the Mongoose');
|
||||
expect(items[0].sellIn).toBe(4);
|
||||
expect(items[0].quality).toBe(4);
|
||||
});
|
||||
});
|
||||
|
||||
3283
TypeScript/yarn.lock
Normal file
3283
TypeScript/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user