Skip to content

Add tests #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 53 additions & 39 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,67 @@ export class GildedRose {
this.items = items;
}

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
modifyQualityIfSellInNegative(name: string, quality: number) {
if (name != 'Aged Brie') {
if (name != 'Backstage passes to a TAFKAL80ETC concert') {
if (quality > 0) {
if (name != 'Sulfuras, Hand of Ragnaros') {
quality--
}
}
} 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
}
}
}
}
quality = 0
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;
} else {
if (quality < 50) {
quality++
}
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 quality;
}

modifyQuality(name: string, sellIn: number ,quality: number) {
quality = quality + 1
if (name == 'Backstage passes to a TAFKAL80ETC concert') {
if (sellIn < 11) {
if (quality < 50) {
quality++
}
}
if (sellIn < 6) {
if (quality < 50) {
quality++
}
}
}
return quality;
}

updateQuality() {
for (let i = 0; i < this.items.length; i++) {
var name: string = this.items[i].name;
var sellIn: number = this.items[i].sellIn;
var quality: number = this.items[i].quality;

if (name != 'Aged Brie' && name != 'Backstage passes to a TAFKAL80ETC concert') {
if (quality > 0) {
if (name != 'Sulfuras, Hand of Ragnaros') {
quality--
}
}
} else if (quality < 50) {
quality = this.modifyQuality(name, sellIn, quality)
}
}

if (name != 'Sulfuras, Hand of Ragnaros') {
sellIn--;
}
if (sellIn < 0) {
quality = this.modifyQualityIfSellInNegative(name, quality)
}
this.items[i].sellIn = sellIn;
this.items[i].quality = quality;
}
return this.items;
}
}
}
68 changes: 66 additions & 2 deletions test/jest/gilded-rose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Gilded Rose', () => {
const items = gildedRose.updateQuality();

// Assert
expect(items[0].name).toBe('bar');
expect(items[0].name).toBe('foo');
});

it('sword quality drops by 1', () => {
Expand All @@ -20,6 +20,70 @@ describe('Gilded Rose', () => {
const items = gildedRose.updateQuality();

// Assert
expect(items[0].quality).toBe(1);
expect(items[0].quality).toBe(0);
})

it('the quality should increase with 2', () => {
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 7, 0)]);

const items = gildedRose.updateQuality();

expect(items[0].quality).toBe(2);
})

it('the quality should increase with 1', () => {
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 13, 0)]);

const items = gildedRose.updateQuality();

expect(items[0].quality).toBe(1);
})


it('the quality should be the same', () => {
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 3, 51)]);

const items = gildedRose.updateQuality();

expect(items[0].quality).toBe(51);
})


it('the sellIn should be negative an the quality drops with 1', () => {
const gildedRose = new GildedRose([new Item('Hello', 0, 1)]);

const items = gildedRose.updateQuality();

expect(items[0].quality).toBe(0);
expect(items[0].sellIn).toBe(-1);

})

it('the sellIn should drop with 1 and the quality will be equal with 0', () => {
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 0, 39)]);

const items = gildedRose.updateQuality();

expect(items[0].sellIn).toBe(-1);
expect(items[0].quality).toBe(0);
})

it('the sellIn should drop with 1 and the quality will be increased with 2', () => {
const gildedRose = new GildedRose([new Item('Aged Brie', 0, 39)]);

const items = gildedRose.updateQuality();

expect(items[0].sellIn).toBe(-1);
expect(items[0].quality).toBe(41);
})

it('the sellIn should drop with 1 and the quality will be decreased with 2', () => {
const gildedRose = new GildedRose([new Item('Hello', 0, 243)]);

const items = gildedRose.updateQuality();

expect(items[0].sellIn).toBe(-1);
expect(items[0].quality).toBe(241);
})

});