mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
Added GildedRose for TypeScript
This commit is contained in:
parent
e046dba763
commit
10346b66c8
10
TypeScript/.gitignore
vendored
Normal file
10
TypeScript/.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
.DS_Store
|
||||||
|
.idea
|
||||||
|
node_modules
|
||||||
|
typings
|
||||||
|
app/**/*.js
|
||||||
|
app/**/*.js.map
|
||||||
|
test/**/*.js
|
||||||
|
test/**/*.js.map
|
||||||
|
coverage
|
||||||
|
.nyc_output
|
||||||
69
TypeScript/app/gilded-rose.ts
Normal file
69
TypeScript/app/gilded-rose.ts
Normal file
@ -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 = []) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
44
TypeScript/package.json
Normal file
44
TypeScript/package.json
Normal file
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
12
TypeScript/test/guilded-rose.spec.ts
Normal file
12
TypeScript/test/guilded-rose.spec.ts
Normal file
@ -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');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
4
TypeScript/test/mocha.opts
Normal file
4
TypeScript/test/mocha.opts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
--compilers ts-node/register
|
||||||
|
--require source-map-support/register
|
||||||
|
--recursive
|
||||||
|
test/**/*.ts
|
||||||
11
TypeScript/tsconfig.json
Normal file
11
TypeScript/tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "commonjs",
|
||||||
|
"target": "es5",
|
||||||
|
"noImplicitAny": false,
|
||||||
|
"sourceMap": false
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user