Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
674482e
t get test to pass
Apr 2, 2022
dd3e8c5
r introduce variables
Apr 2, 2022
e685651
t use toMatchSnapshot
Apr 2, 2022
ff89aef
r extract method
Apr 2, 2022
5ba4057
r inline variable
Apr 2, 2022
8ba6dcb
r introduce parameter
Apr 2, 2022
792a0f3
t use JSON.stringify object instead of just name
Apr 2, 2022
2ca80d1
r inline variable
Apr 2, 2022
6e4b1fb
t add more names
Apr 2, 2022
2754d97
t add qualities to the combinations
Apr 2, 2022
c8f8e19
t add sellIns to the combinaions
Apr 2, 2022
2b2f91b
r extract method
Apr 2, 2022
8ca2d2a
r inline variable
Apr 2, 2022
1dfe7b4
r extract method
Apr 2, 2022
94db0f1
R add empty if else to prepare for flip condition
Apr 2, 2022
e02a62a
R move the doStuff into the if condition before inline
Apr 2, 2022
e089021
r inline method doStuff
Apr 2, 2022
dd58ccf
R move the agebrie condition up
Apr 2, 2022
877082c
R simpliy conditions for AgeBrie
Apr 2, 2022
cbff8a5
r extract method for agebrie and everything else
Apr 2, 2022
f5adda1
r extract method doStuff1
Apr 2, 2022
9b94954
R add if else statement to prepare to flip backstage passes condition
Apr 2, 2022
eccf96c
R add doStuff1 to both if and else condition
Apr 2, 2022
fdcefd3
R simplify if condition
Apr 2, 2022
bfe29e8
r extract method updateQualityBackstagePass
Apr 2, 2022
8b67d9a
r extract method updateQualtyForEverythingElse
Apr 2, 2022
69600db
r unwrap else
Apr 2, 2022
2dd0bd9
r unwrap else
Apr 2, 2022
2efb3f0
R flip condition for sulfurus
Apr 2, 2022
267b3bc
r extrace method
tonytvo Apr 2, 2022
aa0e203
r extract method
tonytvo Apr 2, 2022
6ae5894
r reuse method increase/decrease to avoid duplication
tonytvo Apr 2, 2022
905e1b3
r extract method
tonytvo Apr 2, 2022
c8da8ce
r move updateSingleItem to QualityUpdater
tonytvo Apr 2, 2022
379ff92
r rename class to everythingqualityupdater
tonytvo Apr 2, 2022
98a111b
r extract interface quality updater
tonytvo Apr 2, 2022
33dfa26
R add AgedBrieQualityUpdater
tonytvo Apr 2, 2022
52ac0a8
r extract createQualityUpdater
tonytvo Apr 2, 2022
7097b93
R add agedbriequalityupdater
tonytvo Apr 2, 2022
aa2679b
R add backstagepassesupdater
tonytvo Apr 2, 2022
ebf6ae2
R add sulfurus item updater
tonytvo Apr 2, 2022
8fa1538
r remove unused method
tonytvo Apr 2, 2022
c8c5129
r rename class to defaultItemQualityUpdater
tonytvo Apr 2, 2022
751a3f6
r move inner class to its own module
tonytvo Apr 2, 2022
1531d06
R add NonNegativeWithCeilingQuality
tonytvo Apr 2, 2022
4af7c22
R use toString instead of JSON.stringify
tonytvo Apr 2, 2022
5ba202f
R add qualityTempField
tonytvo Apr 2, 2022
e127701
r move increaseQuality to item
tonytvo Apr 2, 2022
5f975d4
R reuse item.increaseQuantity
tonytvo Apr 3, 2022
3f61b3d
R reuse item.increaseQuanlity
tonytvo Apr 3, 2022
9b6416d
r move decreaseQuality to Item
tonytvo Apr 3, 2022
70a7a18
R add qualityTemp in parallel with quantity so we can avoid command s…
tonytvo Apr 3, 2022
6c50a84
r replace for index loop with for each
tonytvo Apr 3, 2022
0e616cb
r update method signature to return item
tonytvo Apr 3, 2022
8ee89cb
R use pure functions instead of command functions
tonytvo Apr 3, 2022
6e2d591
R remove command effects in agebrie and backstage
tonytvo Apr 3, 2022
0e9d70b
R remove command effects in default-item-quality-updater and sulfuras
tonytvo Apr 3, 2022
dc22e4b
R remove more command effects
tonytvo Apr 3, 2022
470a778
r remove unused quality field
tonytvo Apr 3, 2022
340262e
r rename qualityTemp to quality
tonytvo Apr 3, 2022
f2fdcfc
r add getter
tonytvo Apr 3, 2022
9bb4e3d
r move inner class up 1 level
tonytvo Apr 3, 2022
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
17 changes: 17 additions & 0 deletions refactoring/gildedrose/js/app/aged-brie-quality-updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {QualityUpdater} from "@/quality-updater";
import {Item} from "@/item";

export class AgedBrieQualityUpdater implements QualityUpdater {
update(item: Item): Item {
return this.updateQualityForAgeBrie(item);
}

private updateQualityForAgeBrie(item: Item) {
let updatedQuality = item.increaseQuality();
let updatedSellIn = item.sellIn - 1;
if (updatedSellIn < 0) {
updatedQuality = updatedQuality.increaseQuality();
}
return new Item(item.name, updatedSellIn, updatedQuality.quality);
}
}
24 changes: 24 additions & 0 deletions refactoring/gildedrose/js/app/backstage-pass-quality-updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {QualityUpdater} from "@/quality-updater";
import {Item} from "@/item";
import {NonNegativeWithCeilingQuality} from "@/non-negative-with-ceiling-quality";

export class BackstagePassQualityUpdater implements QualityUpdater {
update(item: Item): Item {
return this.updateQualityBackstagePasses(item);
}

private updateQualityBackstagePasses(item: Item) {
let updateQuality = item.increaseQuality();
if (item.sellIn < 11) {
updateQuality = updateQuality.increaseQuality();
}
if (item.sellIn < 6) {
updateQuality = updateQuality.increaseQuality();
}
let updatedSellIn = item.sellIn - 1;
if (updatedSellIn < 0) {
updateQuality = NonNegativeWithCeilingQuality.zero();
}
return new Item(item.name, updatedSellIn, updateQuality.quality);
}
}
17 changes: 17 additions & 0 deletions refactoring/gildedrose/js/app/default-item-quality-updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {QualityUpdater} from "@/quality-updater";
import {Item} from "@/item";

export class DefaultItemQualityUpdater implements QualityUpdater {
update(item: Item): Item {
return this.updateQualityForDefaultItem(item);
}

private updateQualityForDefaultItem(item: Item) {
let updatedQuality = item.decreaseQuality();
let updatedSellIn = item.sellIn - 1;
if (updatedSellIn < 0) {
updatedQuality = updatedQuality.decreaseQuality();
}
return new Item(item.name, updatedSellIn, updatedQuality.quality);
}
}
86 changes: 26 additions & 60 deletions refactoring/gildedrose/js/app/gilded-rose.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,35 @@
export class Item {
name: string;
sellIn: number;
quality: number;

constructor(name, sellIn, quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
}
import {QualityUpdater} from "@/quality-updater";
import {BackstagePassQualityUpdater} from "@/backstage-pass-quality-updater";
import {AgedBrieQualityUpdater} from "@/aged-brie-quality-updater";
import {SulfurasQualityUpdater} from "@/sulfuras-quality-updater";
import {DefaultItemQualityUpdater} from "@/default-item-quality-updater";
import {Item} from "@/item";

export class GildedRose {
items: Array<Item>;
items: Array<Item>;

constructor(items = [] as Array<Item>) {
this.items = items;
}
constructor(items = [] as Array<Item>) {
this.items = items;
}

updateQuality() {
this.items = this.items.map(item => this.createQualityUpdater(item.name).update(item));
return this.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
}
private createQualityUpdater(name: string) : QualityUpdater{
if (name == 'Aged Brie') {
return new AgedBrieQualityUpdater();
}
} 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 (name == 'Backstage passes to a TAFKAL80ETC concert') {
return new BackstagePassQualityUpdater();
}
}
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
}

if (name == 'Sulfuras, Hand of Ragnaros') {
return new SulfurasQualityUpdater();
}
}
}

return this.items;
}
return new DefaultItemQualityUpdater();
}
}
29 changes: 29 additions & 0 deletions refactoring/gildedrose/js/app/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {NonNegativeWithCeilingQuality} from "@/non-negative-with-ceiling-quality";

export class Item {
name: string;
sellIn: number;
quality: NonNegativeWithCeilingQuality;

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

public increaseQuality() {
return this.quality.increaseQuality();
}

public toString() {
return `{"name":"${this.name}","sellIn":${this.sellIn},"quality":${this.quality.quality}}`;
}

public decreaseQuality() {
return this.quality.decreaseQuality();
}

public qualityAmount() {
return this.quality.quality;
}
}
25 changes: 25 additions & 0 deletions refactoring/gildedrose/js/app/non-negative-with-ceiling-quality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export class NonNegativeWithCeilingQuality {
quality: number;

constructor(quality) {
this.quality = quality;
}

public increaseQuality() {
if (this.quality < 50) {
return new NonNegativeWithCeilingQuality(this.quality + 1);
}
return new NonNegativeWithCeilingQuality(this.quality);
}

static zero() {
return new NonNegativeWithCeilingQuality(0);
}

public decreaseQuality() {
if (this.quality > 0) {
return new NonNegativeWithCeilingQuality(this.quality - 1);
}
return new NonNegativeWithCeilingQuality(this.quality);
}
}
5 changes: 5 additions & 0 deletions refactoring/gildedrose/js/app/quality-updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Item} from "@/item";

export interface QualityUpdater {
update(item: Item): Item;
}
8 changes: 8 additions & 0 deletions refactoring/gildedrose/js/app/sulfuras-quality-updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {QualityUpdater} from "@/quality-updater";
import {Item} from "@/item";

export class SulfurasQualityUpdater implements QualityUpdater {
update(item: Item): Item {
return new Item(item.name, item.sellIn, item.qualityAmount());
}
}
3 changes: 2 additions & 1 deletion refactoring/gildedrose/js/test/golden-master-text-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Item, GildedRose } from '../app/gilded-rose';
import { GildedRose } from '../app/gilded-rose';
import {Item} from "@/item";

const items = [
new Item("+5 Dexterity Vest", 10, 20), //
Expand Down
Loading