update tests and mancala version
This commit is contained in:
parent
9e20f153b4
commit
0312b0e98c
10859
package-lock.json
generated
10859
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -20,7 +20,7 @@
|
|||||||
"@types/ws": "^7.4.5",
|
"@types/ws": "^7.4.5",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mancala.js": "^0.0.2-beta.0",
|
"mancala.js": "^0.0.2-beta.1",
|
||||||
"morgan": "^1.10.0",
|
"morgan": "^1.10.0",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
"ws": "^7.5.0"
|
"ws": "^7.5.0"
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
"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 +0,0 @@
|
|||||||
{"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"}
|
|
||||||
@ -1,16 +0,0 @@
|
|||||||
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))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
"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", "playing");
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
it('game end test 1', function () {
|
|
||||||
var board = new mancala_1.Board([new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(4), new mancala_1.Hole(4)], [new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(0), new mancala_1.Hole(1)], new mancala_1.Store(0), new mancala_1.Store(0));
|
|
||||||
var game = new mancala_1.Game(player1, player2, board, "player2", "playing");
|
|
||||||
game.moveByIndex(5, "player2");
|
|
||||||
expect(game.turn).toBe("player2");
|
|
||||||
expect(game.board.player2Store.ballCount).toBe(9);
|
|
||||||
expect(game.board.player1Holes[game.board.player1Holes.length / 2].ballCount).toBe(0);
|
|
||||||
expect(game.state).toBe("ended");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=mancala.test.js.map
|
|
||||||
@ -1 +0,0 @@
|
|||||||
{"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,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MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACrF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
||||||
@ -1,61 +1,14 @@
|
|||||||
import { Board, createGame, Game, Hole, Store } from "../src/mancala"
|
import { CommonMancalaGame, MancalaGame } from "mancala.js";
|
||||||
|
|
||||||
describe('mancala', function () {
|
function createGame(player1Id: string, player2Id: string): MancalaGame {
|
||||||
const player1 = "0"
|
return new CommonMancalaGame("0", player1Id, player2Id);
|
||||||
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", "playing")
|
|
||||||
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)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('game end test 1', function () {
|
describe("mancala", function () {
|
||||||
const board = new Board(
|
const player1 = "0";
|
||||||
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(4), new Hole(4)],
|
const player2 = "0";
|
||||||
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(1)],
|
it("turn test", function () {
|
||||||
new Store(0), new Store(0))
|
const game = createGame(player1, player2);
|
||||||
const game = new Game(player1, player2, board, "player2", "playing")
|
expect(game.id).toBe("0");
|
||||||
game.moveByIndex(5, "player2")
|
});
|
||||||
expect(game.turn).toBe("player2")
|
});
|
||||||
expect(game.board.player2Store.ballCount).toBe(9)
|
|
||||||
expect(game.board.player1Holes[game.board.player1Holes.length / 2].ballCount).toBe(0)
|
|
||||||
expect(game.state).toBe("ended")
|
|
||||||
})
|
|
||||||
|
|
||||||
it('game end won user 1', function () {
|
|
||||||
const board = new Board(
|
|
||||||
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(4), new Hole(4)],
|
|
||||||
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(1)],
|
|
||||||
new Store(0), new Store(0))
|
|
||||||
const game = new Game(player1, player2, board, "player2", "playing")
|
|
||||||
game.moveByIndex(5, "player2")
|
|
||||||
expect(game.turn).toBe("player2")
|
|
||||||
expect(game.board.player2Store.ballCount).toBe(9)
|
|
||||||
expect(game.board.player1Holes[game.board.player1Holes.length / 2].ballCount).toBe(0)
|
|
||||||
expect(game.state).toBe("ended")
|
|
||||||
expect(game.getWonPlayer()).toBe("player2")
|
|
||||||
})
|
|
||||||
|
|
||||||
it('too many ball test', function () {
|
|
||||||
const board = new Board(
|
|
||||||
[new Hole(1), new Hole(1), new Hole(1), new Hole(1), new Hole(1), new Hole(1)],
|
|
||||||
[new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(0), new Hole(12)],
|
|
||||||
new Store(0), new Store(0))
|
|
||||||
const game = new Game(player1, player2, board, "player2", "playing")
|
|
||||||
game.moveByIndex(5, "player2")
|
|
||||||
expect(game.turn).toBe("player1")
|
|
||||||
expect(game.state).toBe("playing")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user