|
|
@@ -0,0 +1,137 @@
|
|
|
+
|
|
|
+/* README
|
|
|
+
|
|
|
+# Gilded Rose
|
|
|
+
|
|
|
+This is the Gilded Rose kata in TypeScript.
|
|
|
+
|
|
|
+## Getting started
|
|
|
+
|
|
|
+Install dependencies
|
|
|
+
|
|
|
+```sh
|
|
|
+npm install
|
|
|
+```
|
|
|
+
|
|
|
+## Run the unit tests from the Command-Line
|
|
|
+
|
|
|
+There are two unit test frameworks to choose from, Jest and Mocha.
|
|
|
+
|
|
|
+```sh
|
|
|
+npm run test:jest
|
|
|
+```
|
|
|
+
|
|
|
+To run all tests in watch mode
|
|
|
+
|
|
|
+```sh
|
|
|
+npm run test:jest:watch
|
|
|
+```
|
|
|
+
|
|
|
+Mocha
|
|
|
+
|
|
|
+```sh
|
|
|
+npm run test:mocha
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+## Run the TextTest fixture from the Command-Line
|
|
|
+
|
|
|
+_You may need to install `ts-node`_
|
|
|
+
|
|
|
+```sh
|
|
|
+npx ts-node test/golden-master-text-test.ts
|
|
|
+```
|
|
|
+
|
|
|
+Or with number of days as args:
|
|
|
+```sh
|
|
|
+npx ts-node test/golden-master-text-test.ts 10
|
|
|
+```
|
|
|
+
|
|
|
+You should make sure the command shown above works when you execute it in a terminal before trying to use TextTest (see below).
|
|
|
+
|
|
|
+
|
|
|
+## Run the TextTest approval test that comes with this project
|
|
|
+
|
|
|
+There are instructions in the [TextTest Readme](../texttests/README.md) for setting up TextTest. You will need to specify the Python executable and interpreter in [config.gr](../texttests/config.gr). Uncomment these lines:
|
|
|
+
|
|
|
+ executable:${TEXTTEST_HOME}/python/texttest_fixture.py
|
|
|
+ interpreter:python
|
|
|
+
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
+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
|
|
|
+ }
|
|
|
+ }) {
|
|
|
+ this.items[i].quality = this.items[i].quality + 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.items
|
|
|
+ }
|
|
|
+}
|