From 92eccfaef4bb5d8a92120923642c8bd4d843738f Mon Sep 17 00:00:00 2001 From: rickithadi Date: Sat, 3 Oct 2020 13:22:38 +0800 Subject: [PATCH 1/4] added target in .tsconfig, build was failing on manjaro 'Accessors are only available when targeting ECMAScript 5 and higher' --- .tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.tsconfig.json b/.tsconfig.json index a640a8a..0e2fda8 100644 --- a/.tsconfig.json +++ b/.tsconfig.json @@ -1,6 +1,7 @@ { "compilerOptions": { "module": "commonjs", + "target": "es5", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, @@ -11,4 +12,4 @@ }, "include": ["src/*"], "exclude": ["node_modules", "**/*.spec.ts"] - } +} From 849ca2f358e62bbf5b172780590044034cf8862c Mon Sep 17 00:00:00 2001 From: rickithadi Date: Sat, 3 Oct 2020 13:34:09 +0800 Subject: [PATCH 2/4] added tests for movement cases, speed units not implemented, maybe file issue? --- dist/cli.js | 16 +++++++++++++-- dist/cli.js.map | 2 +- dist/spacecraft.js | 33 ++++++++++++++++++++++++++++--- dist/spacecraft.js.map | 2 +- src/spacecraft.ts | 42 ++++++++++++++++++++++++++-------------- tests/spacecraft.spec.ts | 15 +++++++++++++- 6 files changed, 87 insertions(+), 23 deletions(-) diff --git a/dist/cli.js b/dist/cli.js index ce56281..d57097f 100644 --- a/dist/cli.js +++ b/dist/cli.js @@ -1,8 +1,20 @@ "use strict"; -exports.__esModule = true; +Object.defineProperty(exports, "__esModule", { value: true }); +var readline = require("readline"); var spacecraft_1 = require("./spacecraft"); -var spacecraft = new spacecraft_1["default"](); +var spacecraft = new spacecraft_1.default(0, 0); var message; message = spacecraft.createMessage(); +var running = false; +var rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, +}); +var loop = function () { + while (running) { + console.log("X: " + spacecraft.X + " Y: " + spacecraft.Y); + } +}; +spacecraft.forward(spacecraft.y); console.log(message); //# sourceMappingURL=cli.js.map \ No newline at end of file diff --git a/dist/cli.js.map b/dist/cli.js.map index 0243659..9a03f44 100644 --- a/dist/cli.js.map +++ b/dist/cli.js.map @@ -1 +1 @@ -{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAAA,2CAAsC;AAEtC,IAAM,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;AAEpC,IAAI,OAAe,CAAC;AAEpB,OAAO,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;AAErC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC"} \ No newline at end of file +{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;AAAA,mCAAqC;AAErC,2CAAsC;AAEtC,IAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAExC,IAAI,OAAe,CAAC;AAEpB,OAAO,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;AAErC,IAAI,OAAO,GAAG,KAAK,CAAC;AACpB,IAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;IAChC,KAAK,EAAE,OAAO,CAAC,KAAK;IACpB,MAAM,EAAE,OAAO,CAAC,MAAM;CACzB,CAAC,CAAA;AACF,IAAM,IAAI,GAAG;IACT,OAAO,OAAO,EAAE;QACZ,OAAO,CAAC,GAAG,CAAC,QAAM,UAAU,CAAC,CAAC,YAAO,UAAU,CAAC,CAAG,CAAC,CAAC;KACxD;AACL,CAAC,CAAA;AACD,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;AAGhC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC"} \ No newline at end of file diff --git a/dist/spacecraft.js b/dist/spacecraft.js index 56d81ad..2fb917c 100644 --- a/dist/spacecraft.js +++ b/dist/spacecraft.js @@ -1,12 +1,39 @@ "use strict"; -exports.__esModule = true; +Object.defineProperty(exports, "__esModule", { value: true }); var Spacecraft = (function () { - function Spacecraft() { + function Spacecraft(x, y) { + this.x = 0; + this.y = 0; + this.x = x; + this.y = y; } + Object.defineProperty(Spacecraft.prototype, "X", { + get: function () { + return this.x; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Spacecraft.prototype, "Y", { + get: function () { + return this.y; + }, + enumerable: false, + configurable: true + }); Spacecraft.prototype.createMessage = function () { return 'Starter point Spacecraft CLI'; }; + Spacecraft.prototype.forward = function (y) { + return y + 1; + }; + Spacecraft.prototype.left = function (x) { + return x - 1; + }; + Spacecraft.prototype.right = function (x) { + return x + 1; + }; return Spacecraft; }()); -exports["default"] = Spacecraft; +exports.default = Spacecraft; //# sourceMappingURL=spacecraft.js.map \ No newline at end of file diff --git a/dist/spacecraft.js.map b/dist/spacecraft.js.map index 00a2a99..40a4096 100644 --- a/dist/spacecraft.js.map +++ b/dist/spacecraft.js.map @@ -1 +1 @@ -{"version":3,"file":"spacecraft.js","sourceRoot":"","sources":["../src/spacecraft.ts"],"names":[],"mappings":";;AAAA;IAAA;IAIA,CAAC;IAHC,kCAAa,GAAb;QACE,OAAO,8BAA8B,CAAC;IACxC,CAAC;IACH,iBAAC;AAAD,CAAC,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"spacecraft.js","sourceRoot":"","sources":["../src/spacecraft.ts"],"names":[],"mappings":";;AAAA;IAIE,oBAAmB,CAAS,EAAE,CAAS;QAHhC,MAAC,GAAW,CAAC,CAAC;QACd,MAAC,GAAW,CAAC,CAAC;QAGnB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,sBAAW,yBAAC;aAAZ;YACE,OAAO,IAAI,CAAC,CAAC,CAAC;QAChB,CAAC;;;OAAA;IAED,sBAAW,yBAAC;aAAZ;YACE,OAAO,IAAI,CAAC,CAAC,CAAC;QAChB,CAAC;;;OAAA;IAED,kCAAa,GAAb;QACE,OAAO,8BAA8B,CAAC;IACxC,CAAC;IACD,4BAAO,GAAP,UAAQ,CAAS;QACf,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,yBAAI,GAAJ,UAAK,CAAS;QACZ,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACD,0BAAK,GAAL,UAAM,CAAS;QACb,OAAO,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IACH,iBAAC;AAAD,CAAC,AA7BD,IA6BC"} \ No newline at end of file diff --git a/src/spacecraft.ts b/src/spacecraft.ts index ba4d64d..a2213fe 100644 --- a/src/spacecraft.ts +++ b/src/spacecraft.ts @@ -1,22 +1,34 @@ export default class Spacecraft { + public x: number = 0; + public y: number = 0; - public x: number = 0; - public y: number = 0; + public constructor(x: number, y: number) { + this.x = x; + this.y = y; + } - public constructor(x: number, y: number) { - this.x = x; - this.y = y; - } + public get X() { + return this.x; + } - public get X() { - return this.x; - } + public get Y() { + return this.y; + } - public get Y() { - return this.y; - } + createMessage(): string { + return 'Starter point Spacecraft CLI'; + } + forward(y: number): number { + return y + 1; + } + vack(y: number): number { + return y - 1; + } - createMessage(): string { - return 'Starter point Spacecraft CLI'; - } + left(x: number): number { + return x - 1; + } + right(x: number): number { + return x + 1; + } } diff --git a/tests/spacecraft.spec.ts b/tests/spacecraft.spec.ts index 107877f..dd0ceca 100644 --- a/tests/spacecraft.spec.ts +++ b/tests/spacecraft.spec.ts @@ -1,9 +1,22 @@ import SpaceCraft from '../src/spacecraft'; describe('Spacecraft', () => { - const spaceCraft = new SpaceCraft(); + const spaceCraft = new SpaceCraft(0, 0); it('displays starter point message', () => { expect(spaceCraft.createMessage()).toEqual('Starter point Spacecraft CLI'); }); + it('moves forward', () => { + expect(spaceCraft.forward(spaceCraft.y)).toEqual(1); + }); + it('moves left', () => { + expect(spaceCraft.left(spaceCraft.x)).toEqual(-1); + }); + it('moves right', () => { + expect(spaceCraft.right(spaceCraft.x)).toEqual(1); + }); +it('moves bacl', () => { + expect(spaceCraft.back(spaceCraft.y)).toEqual(-1); + }); + }); From cda590f60d73634c0aee08041c43f208ec84595a Mon Sep 17 00:00:00 2001 From: rickithadi Date: Sat, 3 Oct 2020 13:39:27 +0800 Subject: [PATCH 3/4] typo --- src/spacecraft.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spacecraft.ts b/src/spacecraft.ts index a2213fe..606c5c6 100644 --- a/src/spacecraft.ts +++ b/src/spacecraft.ts @@ -21,7 +21,7 @@ export default class Spacecraft { forward(y: number): number { return y + 1; } - vack(y: number): number { + back(y: number): number { return y - 1; } From 8cfc123b70aa12c807ea4c600131a058d43d16ee Mon Sep 17 00:00:00 2001 From: rickithadi Date: Sat, 3 Oct 2020 21:27:25 +0800 Subject: [PATCH 4/4] fixed typo in test case --- tests/spacecraft.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/spacecraft.spec.ts b/tests/spacecraft.spec.ts index dd0ceca..4c53292 100644 --- a/tests/spacecraft.spec.ts +++ b/tests/spacecraft.spec.ts @@ -15,8 +15,7 @@ describe('Spacecraft', () => { it('moves right', () => { expect(spaceCraft.right(spaceCraft.x)).toEqual(1); }); -it('moves bacl', () => { + it('moves back', () => { expect(spaceCraft.back(spaceCraft.y)).toEqual(-1); }); - });