modaq
Version:
Quiz Bowl Reader using TypeScript, React, and MobX
191 lines • 12.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const TeamState_1 = require("src/state/TeamState");
const GameState_1 = require("src/state/GameState");
const PacketState_1 = require("src/state/PacketState");
require("src/state/Cycle");
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("first q", "first a"),
new PacketState_1.Tossup("second q", "second a"),
new PacketState_1.Tossup("third q", "third a"),
new PacketState_1.Tossup("fourth q", "fourth 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 }]),
new PacketState_1.Bonus("third leadin", [{ question: "third q", answer: "third a", value: 10 }]),
new PacketState_1.Bonus("fourth leadin", [{ question: "fourth q", answer: "fourth a", value: 10 }]),
]);
describe("GameStateTests", () => {
describe("protestsMatter", () => {
it("Tie game, no protests", () => {
const game = createDefaultGame();
chai_1.expect(game.protestsMatter).to.be.false;
});
it("Tie game, tossup protests", () => {
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);
game.cycles[0].addTossupProtest(firstTeamPlayer.teamName, 0, 2, "My answer", "My reason");
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Tie game, bonus protests", () => {
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: 1, isLastWord: false }, 0, game.gameFormat, 1, 1);
game.cycles[1].addBonusProtest(1, 0, "My answer", "My reason", secondTeamPlayer.teamName);
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, protests don't matter", () => {
const game = createDefaultGame();
// 20-0
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);
// 60-0
game.cycles[1].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 1, isLastWord: false }, 0, game.gameFormat, 1, 1);
game.cycles[1].setBonusPartAnswer(0, firstTeamPlayer.teamName, 10);
game.cycles[1].setBonusPartAnswer(1, firstTeamPlayer.teamName, 10);
game.cycles[1].setBonusPartAnswer(2, firstTeamPlayer.teamName, 10);
// 60-0, so 10 + 30 points here and 10 points shouldn't make up for 60-0
game.cycles[2].addWrongBuzz({ player: secondTeamPlayer, points: -5, position: 1, isLastWord: false }, 2, game.gameFormat);
game.cycles[2].addTossupProtest(secondTeamPlayer.teamName, 2, 1, "My answer", "My reason");
game.cycles[3].addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 0, isLastWord: false }, 3, game.gameFormat, 2, 1);
game.cycles[3].addBonusProtest(1, 0, "My answer2", "My reason2", secondTeamPlayer.teamName);
chai_1.expect(game.protestsMatter).to.be.false;
});
it("Uneven game, tossup and bonus protests matter", () => {
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);
game.cycles[1].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 1, isLastWord: false }, 0, game.gameFormat, 1, 1);
// 30-0, so 15 points here and 10 points shouldn matter
game.cycles[2].addWrongBuzz({ player: secondTeamPlayer, points: -5, position: 1, isLastWord: false }, 2, game.gameFormat);
game.cycles[2].addTossupProtest(secondTeamPlayer.teamName, 2, 1, "My answer", "My reason");
game.cycles[3].addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 0, isLastWord: false }, 3, game.gameFormat, 2, 1);
game.cycles[3].addBonusProtest(1, 0, "My answer2", "My reason2", secondTeamPlayer.teamName);
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, tossup protest matters", () => {
const game = createDefaultGame();
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 0, 1);
// 30-0, so 15 points here and 10 points shouldn matter
game.cycles[3].addWrongBuzz({ player: secondTeamPlayer, points: -5, position: 1, isLastWord: false }, 2, game.gameFormat);
game.cycles[3].addTossupProtest(secondTeamPlayer.teamName, 2, 1, "My answer", "My reason");
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, bonus protest matters (for)", () => {
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);
game.cycles[1].addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 1, isLastWord: false }, 0, game.gameFormat, 1, 1);
game.cycles[1].addBonusProtest(1, 0, "My answer", "My reason", secondTeamPlayer.teamName);
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, bonus protest matters (against)", () => {
const game = createDefaultGame();
// 20-0, one protest
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);
game.cycles[0].addBonusProtest(0, 0, "My answer", "My reason", secondTeamPlayer.teamName);
// 20-10, one bonus protest (should tie since protest against correctness)
game.cycles[1].addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 1, isLastWord: false }, 0, game.gameFormat, 1, 1);
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, protests matter, both teams have protests", () => {
const game = createDefaultGame();
game.cycles[0].addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 0, 1);
game.cycles[0].addBonusProtest(0, 0, "My answer", "My reason", firstTeamPlayer.teamName);
// 30-0, so 15 points here and 10 points shouldn matter
game.cycles[3].addWrongBuzz({ player: secondTeamPlayer, points: -5, position: 1, isLastWord: false }, 2, game.gameFormat);
game.cycles[3].addTossupProtest(secondTeamPlayer.teamName, 2, 1, "My answer", "My reason");
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Uneven game, tossup with bonus for other team would swing it", () => {
const packet = new PacketState_1.PacketState();
packet.setTossups([
new PacketState_1.Tossup("first q", "first a"),
new PacketState_1.Tossup("second q", "second a"),
new PacketState_1.Tossup("third q", "third a"),
new PacketState_1.Tossup("fourth q", "fourth a"),
]);
packet.setBonuses([
new PacketState_1.Bonus("first leadin", [
{ question: "first q", answer: "first a", value: 10 },
{ question: "first q2", answer: "first a2", value: 10 },
{ question: "first q3", answer: "first a3", value: 10 },
]),
new PacketState_1.Bonus("second leadin", [
{ question: "second q", answer: "second a", value: 10 },
{ question: "second q2", answer: "second a2", value: 10 },
{ question: "second q3", answer: "second a3", value: 10 },
]),
new PacketState_1.Bonus("third leadin", [
{ question: "third q", answer: "third a", value: 10 },
{ question: "third q2", answer: "third a2", value: 10 },
{ question: "third q3", answer: "third a3", value: 10 },
]),
]);
const game = new GameState_1.GameState();
game.addNewPlayers(players);
game.loadPacket(defaultPacket);
// 30-0
const firstCycle = game.cycles[0];
firstCycle.addCorrectBuzz({ player: firstTeamPlayer, points: 10, position: 2, isLastWord: false }, 0, game.gameFormat, 0, 3);
firstCycle.setBonusPartAnswer(0, firstTeamPlayer.teamName, 10);
firstCycle.setBonusPartAnswer(1, firstTeamPlayer.teamName, 10);
chai_1.expect(game.protestsMatter).to.be.false;
// 25-40, but protest neg
const secondCycle = game.cycles[1];
secondCycle.addWrongBuzz({ player: firstTeamPlayer, points: -5, position: 1, isLastWord: false }, 1, game.gameFormat);
secondCycle.addTossupProtest(firstTeamPlayer.teamName, 2, 1, "My answer", "My reason");
secondCycle.addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 2, isLastWord: false }, 1, game.gameFormat, 1, 3);
secondCycle.setBonusPartAnswer(0, secondTeamPlayer.teamName, 10);
secondCycle.setBonusPartAnswer(1, secondTeamPlayer.teamName, 10);
chai_1.expect(game.protestsMatter).to.be.true;
// 25-50... protestMatter should still be true, since the protest in the second question should flip it
const thirdCycle = game.cycles[2];
thirdCycle.addCorrectBuzz({ player: secondTeamPlayer, points: 10, position: 2, isLastWord: false }, 2, game.gameFormat, 2, 3);
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Tossup-only game, protest matters", () => {
const game = new GameState_1.GameState();
game.addNewPlayers(players);
const packet = new PacketState_1.PacketState();
packet.setTossups(defaultPacket.tossups);
game.loadPacket(packet);
game.setGameFormat(Object.assign(Object.assign({}, game.gameFormat), { negValue: -5 }));
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 2, isLastWord: false }, 0, game.gameFormat);
game.cycles[0].addTossupProtest(firstTeamPlayer.teamName, 0, 2, "My answer", "My reason");
chai_1.expect(game.protestsMatter).to.be.true;
});
it("Tossup-only game, protest doesn't matter", () => {
const game = new GameState_1.GameState();
game.addNewPlayers(players);
const packet = new PacketState_1.PacketState();
packet.setTossups(defaultPacket.tossups);
game.loadPacket(packet);
game.setGameFormat(Object.assign(Object.assign({}, game.gameFormat), { negValue: -5 }));
game.cycles[0].addWrongBuzz({ player: firstTeamPlayer, points: 0, position: 2, isLastWord: false }, 0, game.gameFormat);
game.cycles[0].addTossupProtest(firstTeamPlayer.teamName, 0, 2, "My answer", "My reason");
game.cycles[1].addCorrectBuzz({
player: firstTeamPlayer,
points: 10,
position: 1,
isLastWord: false,
}, 1, game.gameFormat, 0, 0);
chai_1.expect(game.protestsMatter).to.be.false;
});
});
});
function createDefaultGame() {
const game = new GameState_1.GameState();
game.addNewPlayers(players);
game.loadPacket(defaultPacket);
return game;
}
//# sourceMappingURL=ProtestsMatterTests.js.map