added tests
This commit is contained in:
parent
4bef322d90
commit
30953e3464
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"program": "${workspaceFolder}/src/index.ts",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json",
|
||||
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
|
||||
},
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jest Current File",
|
||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
||||
"args": ["${relativeFile}"],
|
||||
"console": "integratedTerminal",
|
||||
"internalConsoleOptions": "neverOpen",
|
||||
"windows": {
|
||||
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
6
jest.config.js
Normal file
6
jest.config.js
Normal file
@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
transform: {'^.+\\.ts?$': 'ts-jest'},
|
||||
testEnvironment: 'node',
|
||||
testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$',
|
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
|
||||
};
|
||||
3631
package-lock.json
generated
3631
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,7 +6,9 @@
|
||||
"scripts": {
|
||||
"start": "node dist/index.js",
|
||||
"dev": "nodemon src/index.ts",
|
||||
"build": "tsc"
|
||||
"build": "tsc",
|
||||
"test": "jest",
|
||||
"coverage": "jest --coverage"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
@ -22,8 +24,11 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/express": "^4.17.12",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/node": "^15.12.4",
|
||||
"jest": "^27.0.5",
|
||||
"nodemon": "^2.0.7",
|
||||
"ts-jest": "^27.0.3",
|
||||
"ts-node": "^10.0.0",
|
||||
"typescript": "^4.3.4"
|
||||
}
|
||||
|
||||
17
tests/encode_decode.test.js
Normal file
17
tests/encode_decode.test.js
Normal file
@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var byte_util_1 = require("../src/rtmt/byte_util");
|
||||
var encode_decode_message_1 = require("../src/rtmt/encode_decode_message");
|
||||
describe('encode decode message', function () {
|
||||
it('basic encode decode message test', function () {
|
||||
var message = {
|
||||
channel: "channel",
|
||||
data: byte_util_1.encodeText("{text}")
|
||||
};
|
||||
var data = encode_decode_message_1.encode(message);
|
||||
var messageAfter = encode_decode_message_1.decode(Buffer.from(data));
|
||||
expect(messageAfter.channel).toBe(messageAfter.channel);
|
||||
expect(byte_util_1.decodeText(messageAfter.data)).toBe(byte_util_1.decodeText(messageAfter.data));
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=encode_decode.test.js.map
|
||||
1
tests/encode_decode.test.js.map
Normal file
1
tests/encode_decode.test.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"encode_decode.test.js","sourceRoot":"","sources":["encode_decode.test.ts"],"names":[],"mappings":";;AAAA,mDAA8D;AAC9D,2EAAkE;AAElE,QAAQ,CAAC,uBAAuB,EAAE;IAChC,EAAE,CAAC,kCAAkC,EAAE;QACrC,IAAM,OAAO,GAAG;YACd,OAAO,EAAE,SAAS;YAClB,IAAI,EAAE,sBAAU,CAAC,QAAQ,CAAC;SAC3B,CAAA;QACD,IAAM,IAAI,GAAG,8BAAM,CAAC,OAAO,CAAC,CAAA;QAC5B,IAAM,YAAY,GAAG,8BAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAE/C,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QACvD,MAAM,CAAC,sBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAA;IAC3E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
||||
16
tests/encode_decode.test.ts
Normal file
16
tests/encode_decode.test.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { decodeText, encodeText } from "../src/rtmt/byte_util"
|
||||
import { encode, decode } from "../src/rtmt/encode_decode_message"
|
||||
|
||||
describe('encode decode message', function () {
|
||||
it('basic encode decode message test', function () {
|
||||
const message = {
|
||||
channel: "channel",
|
||||
data: encodeText("{text}")
|
||||
}
|
||||
const data = encode(message)
|
||||
const messageAfter = decode(Buffer.from(data));
|
||||
|
||||
expect(messageAfter.channel).toBe(messageAfter.channel)
|
||||
expect(decodeText(messageAfter.data)).toBe(decodeText(messageAfter.data))
|
||||
})
|
||||
})
|
||||
22
tests/mancala.test.js
Normal file
22
tests/mancala.test.js
Normal file
@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var mancala_1 = require("../src/mancala");
|
||||
describe('mancala', function () {
|
||||
var player1 = "0";
|
||||
var player2 = "0";
|
||||
it('turn test', function () {
|
||||
var game = mancala_1.createGame(player1, player2);
|
||||
game.turn = "player1";
|
||||
game.moveByIndex(3, "player1");
|
||||
expect(game.turn).toBe("player1");
|
||||
});
|
||||
it('zero hole test 1', function () {
|
||||
var board = new mancala_1.Board([new mancala_1.Hole(0), new mancala_1.Hole(1), new mancala_1.Hole(2), new mancala_1.Hole(3), new mancala_1.Hole(4), new mancala_1.Hole(5)], [new mancala_1.Hole(1), new mancala_1.Hole(0), new mancala_1.Hole(4), new mancala_1.Hole(4), new mancala_1.Hole(4), new mancala_1.Hole(4)], new mancala_1.Store(0), new mancala_1.Store(0));
|
||||
var game = new mancala_1.Game(player1, player2, board, "player2");
|
||||
game.moveByIndex(0, "player2");
|
||||
expect(game.turn).toBe("player1");
|
||||
expect(game.board.player2Store.ballCount).toBe(5);
|
||||
expect(game.board.player1Holes[game.board.player1Holes.length - 1 - 1].ballCount).toBe(0);
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=mancala.test.js.map
|
||||
1
tests/mancala.test.js.map
Normal file
1
tests/mancala.test.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"mancala.test.js","sourceRoot":"","sources":["mancala.test.ts"],"names":[],"mappings":";;AAAA,0CAAqE;AAErE,QAAQ,CAAC,SAAS,EAAE;IAClB,IAAM,OAAO,GAAG,GAAG,CAAA;IACnB,IAAM,OAAO,GAAG,GAAG,CAAA;IACnB,EAAE,CAAC,WAAW,EAAE;QACd,IAAM,IAAI,GAAG,oBAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;QACrB,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;IACF,EAAE,CAAC,kBAAkB,EAAE;QACrB,IAAM,KAAK,GAAG,IAAI,eAAK,CACrB,CAAC,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,CAAC,EAC9E,CAAC,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,EAAE,IAAI,cAAI,CAAC,CAAC,CAAC,CAAC,EAC9E,IAAI,eAAK,CAAC,CAAC,CAAC,EAAE,IAAI,eAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7B,IAAM,IAAI,GAAG,IAAI,cAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAA;QACzD,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACjC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC3F,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
||||
23
tests/mancala.test.ts
Normal file
23
tests/mancala.test.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Board, createGame, Game, Hole, Store } from "../src/mancala"
|
||||
|
||||
describe('mancala', function () {
|
||||
const player1 = "0"
|
||||
const player2 = "0"
|
||||
it('turn test', function () {
|
||||
const game = createGame(player1, player2)
|
||||
game.turn = "player1"
|
||||
game.moveByIndex(3, "player1")
|
||||
expect(game.turn).toBe("player1")
|
||||
})
|
||||
it('zero hole test 1', function () {
|
||||
const board = new Board(
|
||||
[new Hole(0), new Hole(1), new Hole(2), new Hole(3), new Hole(4), new Hole(5)],
|
||||
[new Hole(1), new Hole(0), new Hole(4), new Hole(4), new Hole(4), new Hole(4)],
|
||||
new Store(0), new Store(0))
|
||||
const game = new Game(player1, player2, board, "player2")
|
||||
game.moveByIndex(0, "player2")
|
||||
expect(game.turn).toBe("player1")
|
||||
expect(game.board.player2Store.ballCount).toBe(5)
|
||||
expect(game.board.player1Holes[game.board.player1Holes.length - 1 - 1].ballCount).toBe(0)
|
||||
})
|
||||
})
|
||||
@ -7,6 +7,7 @@
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"sourceMap": true
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user