mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
refactored some tests
This commit is contained in:
parent
4dd71da770
commit
57f1bb484a
@ -22,6 +22,7 @@ export class GildedRose {
|
|||||||
updateQuality() {
|
updateQuality() {
|
||||||
var maxQuality = 50;
|
var maxQuality = 50;
|
||||||
var minQuality = 0;
|
var minQuality = 0;
|
||||||
|
var conjured = 'Conjured';
|
||||||
for (let i = 0; i < this.items.length; i++) {
|
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].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
&& this.items[i].name != 'Sulfuras, Hand of Ragnaros' && this.items[i].quality >minQuality) {
|
&& this.items[i].name != 'Sulfuras, Hand of Ragnaros' && this.items[i].quality >minQuality) {
|
||||||
@ -59,13 +60,12 @@ export class GildedRose {
|
|||||||
this.items[i].quality -= 1;
|
this.items[i].quality -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// set quality to 0 after sellIn date passes
|
// set quality to 0 after sellIn date passes
|
||||||
} else {
|
} else {
|
||||||
this.items[i].quality = 0;
|
this.items[i].quality = 0;
|
||||||
}
|
}
|
||||||
// aged brie increases in quality here
|
// aged brie increases in quality here
|
||||||
} else {
|
} else if (this.items[i].name == 'Aged Brie') {
|
||||||
if (this.items[i].quality < maxQuality) {
|
if (this.items[i].quality < maxQuality) {
|
||||||
this.items[i].quality += 1;
|
this.items[i].quality += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,80 +3,96 @@ import { Item, GildedRose } from '../app/gilded-rose';
|
|||||||
|
|
||||||
|
|
||||||
// General Tests to ensure it works for newly created item
|
// General Tests to ensure it works for newly created item
|
||||||
describe('Gilded Rose', function () {
|
describe('Gilded Rose', () => {
|
||||||
|
|
||||||
it('should foo', function() {
|
describe('General tests', () => {
|
||||||
const gildedRose = new GildedRose([ new Item('foo', 0, 0) ]);
|
var gildedRose: GildedRose;
|
||||||
const items = gildedRose.updateQuality();
|
|
||||||
expect(items[0].name).to.equal('foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
beforeEach(() => {
|
||||||
|
gildedRose = new GildedRose([new Item('foo', 5, 5)]);
|
||||||
|
});
|
||||||
|
|
||||||
describe('Gilded Rose', function () {
|
it('Foo should be added to item array', () => {
|
||||||
it('Should give back updated SellIn', function () {
|
const items = gildedRose.updateQuality()[0];
|
||||||
const gildedRose = new GildedRose([ new Item('foo', 5, 5)]);
|
expect(items.name).to.equal('foo');
|
||||||
const items = gildedRose.updateQuality();
|
});
|
||||||
expect(items[0].sellIn).to.equal(4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Gilded Rose', function () {
|
it('should give back updated sellIn ', () => {
|
||||||
it('Should give back updated Quality', function () {
|
const items = gildedRose.updateQuality()[0];
|
||||||
const gildedRose = new GildedRose([ new Item('foo', 5, 5)]);
|
expect(items.sellIn).to.equal(4);
|
||||||
const items = gildedRose.updateQuality();
|
});
|
||||||
expect(items[0].quality).to.equal(4);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Gilded Rose', function () {
|
it('should give back updated quality', () => {
|
||||||
it('Quality should go down twice as much after sellIn date passes', function () {
|
const items = gildedRose.updateQuality()[0];
|
||||||
const gildedRose = new GildedRose([ new Item('foo', -1, 5)]);
|
expect(items.quality).to.equal(4);
|
||||||
const items = gildedRose.updateQuality();
|
});
|
||||||
expect(items[0].quality).to.equal(3);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Gilded Rose', function () {
|
|
||||||
it('Quality should not go negative', function () {
|
it('Quality decreases twice as fast after sellIn date', () => {
|
||||||
const gildedRose = new GildedRose([ new Item('foo', -1, 0)]);
|
gildedRose.items[0].sellIn = -1;
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality()[0];
|
||||||
expect(items[0].quality).to.equal(0);
|
expect(items.quality).to.equal(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Quality should not go negative', () => {
|
||||||
|
gildedRose.items[0].quality = 0;
|
||||||
|
gildedRose.items[0].sellIn = -1;
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// tests for backstage passes
|
// tests for backstage passes
|
||||||
describe('Backstage Pass', function () {
|
describe('Gilded Rose', () => {
|
||||||
it('Backstage pass should increase in quality by 2 with only 10 days left', function () {
|
|
||||||
const gildedRose = new GildedRose ([ new Item('Backstage passes to a TAFKAL80ETC concert', 10, 5)]);
|
|
||||||
const items = gildedRose.updateQuality();
|
|
||||||
expect(items[0].quality).to.equal(7);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Backstage Pass', function () {
|
describe('Backstage passes to a TAFKAL80ETC concert Tests', () => {
|
||||||
it('Backstage pass should increase in quality by 3 with 5 days left', function () {
|
var gildedRose: GildedRose;
|
||||||
const gildedRose = new GildedRose ([ new Item('Backstage passes to a TAFKAL80ETC concert', 5, 5)]);
|
|
||||||
const items = gildedRose.updateQuality();
|
|
||||||
expect(items[0].quality).to.equal(8);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Backstage Pass', function () {
|
beforeEach(() => {
|
||||||
it('Backstage pass should increase in quality by 3, but quality is at 49', function () {
|
gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 10, 5)]);
|
||||||
const gildedRose = new GildedRose ([ new Item('Backstage passes to a TAFKAL80ETC concert', 4, 49)]);
|
});
|
||||||
const items = gildedRose.updateQuality();
|
|
||||||
expect(items[0].quality).to.equal(50);
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Backstage Pass', function () {
|
it('Backstage passes to a TAFKAL80ETC concert should be added to item array', () => {
|
||||||
it('Backstage pass quality should drop to 0 after concert', function () {
|
const items = gildedRose.updateQuality()[0];
|
||||||
const gildedRose = new GildedRose ([ new Item('Backstage passes to a TAFKAL80ETC concert', 0, 50)]);
|
expect(items.name).to.equal('Backstage passes to a TAFKAL80ETC concert');
|
||||||
const items = gildedRose.updateQuality();
|
});
|
||||||
expect(items[0].quality).to.equal(0);
|
|
||||||
})
|
it('should give back updated sellIn ', () => {
|
||||||
})
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.sellIn).to.equal(9);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should give back updated quality, Backstage passes increase in quality as days go on', () => {
|
||||||
|
gildedRose.items[0].sellIn = 12;
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(6);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Backstage pass quality should increase by 2 with 10 or less days', () => {
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(7);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Backstage pass quality should increase by 3 with 5 or less days', () => {
|
||||||
|
gildedRose.items[0].sellIn = 2;
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(8);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Backstage Pass quality drops to 0 after concert', () => {
|
||||||
|
gildedRose.items[0].sellIn = -1;
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Backstage Pass quality caps at 50', () => {
|
||||||
|
gildedRose.items[0].quality = 50;
|
||||||
|
const items = gildedRose.updateQuality()[0];
|
||||||
|
expect(items.quality).to.equal(50);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// tests for aged brie
|
// tests for aged brie
|
||||||
describe('Gilded Rose', () => {
|
describe('Gilded Rose', () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user