modaq
Version:
Quiz Bowl Reader using TypeScript, React, and MobX
134 lines • 8.07 kB
JavaScript
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const GameFormats = __importStar(require("src/state/GameFormats"));
const TeamState_1 = require("src/state/TeamState");
const GameState_1 = require("src/state/GameState");
const PacketState_1 = require("src/state/PacketState");
const firstTeamPlayer = new TeamState_1.Player("Alice", "A", /* isStarter */ true);
const secondTeamPlayer = new TeamState_1.Player("Bob", "B", /* isStarter */ true);
const players = [firstTeamPlayer, secondTeamPlayer];
const defaultPacket = new PacketState_1.PacketState();
defaultPacket.setTossups([
new PacketState_1.Tossup("power before (*) first q", "first a"),
new PacketState_1.Tossup("power before (*) second q", "second a"),
]);
defaultPacket.setBonuses([
new PacketState_1.Bonus("first leadin", [{ question: "first q", answer: "first a", value: 10 }]),
new PacketState_1.Bonus("second leadin", [{ question: "second q", answer: "second a", value: 10 }]),
]);
describe("GameStateTests", () => {
describe("score", () => {
it("Initial game", () => {
const game = createDefaultGame();
chai_1.expect(game.scores[0]).to.deep.equal([0, 0]);
});
it("Game with more than two teams", () => {
const game = new GameState_1.GameState();
const thirdPlayer = new TeamState_1.Player("Charlie", "C", /* isStarter */ true);
game.addNewPlayers(players.concat(thirdPlayer));
game.loadPacket(defaultPacket);
game.setGameFormat(GameFormats.StandardPowersMACFGameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, 0, 0]);
game.cycles[0].addWrongBuzz({ player: thirdPlayer, points: -5, position: 2, isLastWord: false }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, 0, -5]);
});
it("Neg with zero-point neg format", () => {
const game = createDefaultGame();
game.setGameFormat(Object.assign(Object.assign({}, game.gameFormat), { negValue: 0 }));
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 2, isLastWord: false }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, 0]);
});
it("Two correct buzzes", () => {
const game = createDefaultGame();
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 0, 1);
game.cycles[1].addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 1, 1);
chai_1.expect(game.scores[0]).to.deep.equal([10, 0]);
chai_1.expect(game.scores[1]).to.deep.equal([10, 10]);
});
it("Correct buzz with bonus", () => {
const game = createDefaultGame();
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 0, 1);
game.cycles[0].setBonusPartAnswer(0, firstTeamPlayer.teamName, 10);
chai_1.expect(game.scores[0]).to.deep.equal([20, 0]);
game.cycles[1].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 3, isLastWord: false }, 0, game.gameFormat, 1, 1);
chai_1.expect(game.scores[1]).to.deep.equal([30, 0]);
});
it("Power", () => {
const game = createDefaultGame();
// Say 10 points, but it should be calculated from the game format, which says it's 15
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 0, isLastWord: false }, 0, game.gameFormat, 0, 1);
chai_1.expect(game.scores[0]).to.deep.equal([15, 0]);
// Should revert to 10 points after a game format change
game.setGameFormat(GameFormats.ACFGameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([10, 0]);
// And back to a power after resetting the format
game.setGameFormat(GameFormats.StandardPowersMACFGameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([15, 0]);
});
it("Neg", () => {
const game = createDefaultGame();
// Say 10 points, but it should be calculated from the game format, which says it's 15
game.cycles[0].addWrongBuzz({ player: secondTeamPlayer, points: 0, position: 1, isLastWord: false }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, -5]);
// Should revert to 0 points after a game format change
game.setGameFormat(GameFormats.PACEGameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, 0]);
// And back to a neg after resetting the format
game.setGameFormat(GameFormats.StandardPowersMACFGameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, -5]);
});
it("No penalty", () => {
const game = createDefaultGame();
game.cycles[0].addWrongBuzz({ player: secondTeamPlayer, points: 0, position: 4, isLastWord: true }, 0, game.gameFormat);
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 4, isLastWord: false }, 0, game.gameFormat, 0, 1);
chai_1.expect(game.scores[0]).to.deep.equal([10, 0]);
});
it("No penalties", () => {
const game = createDefaultGame();
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 4, isLastWord: true }, 0, game.gameFormat);
game.cycles[0].addWrongBuzz({ player: secondTeamPlayer, points: 0, position: 4, isLastWord: true }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([0, 0]);
});
it("Neg followed by no penalty", () => {
const game = createDefaultGame();
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 3, isLastWord: false }, 0, game.gameFormat);
game.cycles[0].addWrongBuzz({ player: secondTeamPlayer, points: 0, position: 4, isLastWord: true }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([-5, 0]);
});
it("Neg and no penalty on the same word", () => {
const game = createDefaultGame();
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 3, isLastWord: false }, 0, game.gameFormat);
game.cycles[0].addWrongBuzz({ player: secondTeamPlayer, points: 0, position: 3, isLastWord: true }, 0, game.gameFormat);
chai_1.expect(game.scores[0]).to.deep.equal([-5, 0]);
});
// Verify neg, no penalty on all Sheets tests and QBJ
});
});
function createDefaultGame() {
const game = new GameState_1.GameState();
game.addNewPlayers(players);
game.loadPacket(defaultPacket);
game.setGameFormat(GameFormats.StandardPowersMACFGameFormat);
return game;
}
//# sourceMappingURL=ScoreTests.js.map