Skip to content

Progress pentru workshop final. #42

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 1 commit 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
69 changes: 69 additions & 0 deletions app/gilded-rose-og.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export class Item {
name: string;
sellIn: number;
quality: number;

constructor(name, sellIn, quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
}

export class GildedRose {
items: Array<Item>;

constructor(items = [] as Array<Item>) {
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
}
}
} 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.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;
}
}
107 changes: 57 additions & 50 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,66 @@ export class Item {
}

export class GildedRose {
items: Array<Item>;
constructor(public items: Item[] = []) {}

constructor(items = [] as Array<Item>) {
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
}
}
} 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.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
}
}
}
updateQuality(): Item[] {
for (const item of this.items) {
this.updateItem(item);
}

return this.items;
}

private updateItem(item: Item): void {
switch (item.name) {
case 'Aged Brie':
this.updateAgedBrie(item);
break;

case 'Backstage passes to a TAFKAL80ETC concert':
this.updatePass(item);
break;

case 'Sulfuras, Hand of Ragnaros':
break;

default:
this.updateNormalItem(item);
}
if (item.name !== 'Sulfuras, Hand of Ragnaros') {
item.sellIn--;
}
if (item.sellIn < 0) {
this.handleExpired(item);
}
}
private updateAgedBrie(item: Item): void {
if (item.quality < 50) {
item.quality++;
}
}
private updatePass(item: Item): void {
if (item.quality < 50) item.quality++;
if (item.sellIn < 11 && item.quality < 50) item.quality++;
if (item.sellIn < 6 && item.quality < 50) item.quality++;
}
private updateNormalItem(item: Item): void {
if (item.quality > 0) {
item.quality--;
}
}
private handleExpired(item: Item): void {
switch (item.name) {
case 'Aged Brie':
if (item.quality < 50) item.quality++;
break;
case 'Backstage passes to a TAFKAL80ETC concert':
item.quality = 0;
break;
case 'Sulfuras, Hand of Ragnaros':
break;
default:
if (item.quality > 0) item.quality--;
}
}
}
51 changes: 49 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,53 @@ describe('Gilded Rose', () => {
const items = gildedRose.updateQuality();

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

it('should shaorma', () => {
// Arrange
const gildedRose = new GildedRose([new Item('shaorma', 4, 30),new Item('shaorma2', -1, 30)]);

// Act
const items = gildedRose.updateQuality();

// Assert
expect(items[0].quality).toBeGreaterThan(10);
expect(items[1].quality).toBeGreaterThan(10);
expect(items[0].name).toBe('shaorma');
expect(items[1].name).toBe('shaorma2');
})
it('aaged brie', () => {
// Arrange
const gildedRose = new GildedRose([new Item('Aged Brie', 0, 20)]);

// Act
const items = gildedRose.updateQuality();

// Assert
expect(items[0].quality).toBeGreaterThan(10);
expect(items[0].name).toBe('Aged Brie');
})
it('backstage passes', () => {
// Arrange
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', 0, 20)]);

// Act
const items = gildedRose.updateQuality();

// Assert
expect(items[0].quality).toBe(0);
expect(items[0].name).toBe('Backstage passes to a TAFKAL80ETC concert');
})
it('backstage passes 2', () => {
// Arrange
const gildedRose = new GildedRose([new Item('Backstage passes to a TAFKAL80ETC concert', -1, 20)]);

// Act
const items = gildedRose.updateQuality();

// Assert
expect(items[0].quality).toBe(0);
expect(items[0].name).toBe('Backstage passes to a TAFKAL80ETC concert');
})
});