From 10346b66c81eda2879a9893ef02fbb4ecbf4a6c6 Mon Sep 17 00:00:00 2001 From: Paulo Clavijo Esteban Date: Fri, 30 Jun 2017 17:21:55 +0100 Subject: [PATCH] Added GildedRose for TypeScript --- TypeScript/.gitignore | 10 ++++ TypeScript/app/gilded-rose.ts | 69 ++++++++++++++++++++++++++++ TypeScript/package.json | 44 ++++++++++++++++++ TypeScript/test/guilded-rose.spec.ts | 12 +++++ TypeScript/test/mocha.opts | 4 ++ TypeScript/tsconfig.json | 11 +++++ 6 files changed, 150 insertions(+) create mode 100644 TypeScript/.gitignore create mode 100644 TypeScript/app/gilded-rose.ts create mode 100644 TypeScript/package.json create mode 100644 TypeScript/test/guilded-rose.spec.ts create mode 100644 TypeScript/test/mocha.opts create mode 100644 TypeScript/tsconfig.json diff --git a/TypeScript/.gitignore b/TypeScript/.gitignore new file mode 100644 index 00000000..7d7d75b0 --- /dev/null +++ b/TypeScript/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +.idea +node_modules +typings +app/**/*.js +app/**/*.js.map +test/**/*.js +test/**/*.js.map +coverage +.nyc_output diff --git a/TypeScript/app/gilded-rose.ts b/TypeScript/app/gilded-rose.ts new file mode 100644 index 00000000..c7d58c65 --- /dev/null +++ b/TypeScript/app/gilded-rose.ts @@ -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; + + constructor(items = []) { + 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; + } +} diff --git a/TypeScript/package.json b/TypeScript/package.json new file mode 100644 index 00000000..28b6bb3f --- /dev/null +++ b/TypeScript/package.json @@ -0,0 +1,44 @@ +{ + "name": "typescript-mocha-kata-seed", + "version": "1.4.0", + "description": "Seed project for TDD code katas on TypeScript and mocha", + "main": "index.js", + "scripts": { + "precompile": "rimraf app/**/*.js test/**/*.js", + "compile": "tsc", + "pretest": "rimraf app/**/*.js test/**/*.js", + "test": "nyc mocha" + }, + "author": "paucls", + "homepage": "https://github.com/paucls/typescript-mocha-kata-seed", + "license": "ISC", + "private": true, + "devDependencies": { + "@types/chai": "~3.5.2", + "@types/mocha": "~2.2.41", + "@types/node": "~7.0.18", + "chai": "~3.5.0", + "mocha": "~3.2.0", + "nyc": "~11.0.3", + "rimraf": "~2.5.2", + "ts-node": "~3.1.0", + "typescript": "~2.2.0" + }, + "nyc": { + "extension": [ + ".ts" + ], + "exclude": [ + "**/*.d.ts", + "test/**" + ], + "require": [ + "ts-node/register" + ], + "reporter": [ + "html", + "text" + ] + } +} + diff --git a/TypeScript/test/guilded-rose.spec.ts b/TypeScript/test/guilded-rose.spec.ts new file mode 100644 index 00000000..02b4f154 --- /dev/null +++ b/TypeScript/test/guilded-rose.spec.ts @@ -0,0 +1,12 @@ +import { expect } from 'chai'; +import { Item, GildedRose } from '../app/gilded-rose'; + +describe('Gilded Rose', function () { + + it('should foo', function() { + const gilgedRose = new GildedRose([ new Item('foo', 0, 0) ]); + const items = gilgedRose.updateQuality(); + expect(items[0].name).to.equal('fixme'); + }); + +}); \ No newline at end of file diff --git a/TypeScript/test/mocha.opts b/TypeScript/test/mocha.opts new file mode 100644 index 00000000..bf3868c8 --- /dev/null +++ b/TypeScript/test/mocha.opts @@ -0,0 +1,4 @@ +--compilers ts-node/register +--require source-map-support/register +--recursive +test/**/*.ts diff --git a/TypeScript/tsconfig.json b/TypeScript/tsconfig.json new file mode 100644 index 00000000..4f713921 --- /dev/null +++ b/TypeScript/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es5", + "noImplicitAny": false, + "sourceMap": false + }, + "exclude": [ + "node_modules" + ] +}