import { expect } from "chai"; import "mocha"; import { Deck } from "../../src/objects/Deck"; describe("The Deck object", () => { var drawSuccess = false; it("should construct properly with strings", () => { let d = new Deck(["1", "2", "3", "4", "5"]); expect(d.size).to.equal(5); }); it("should construct properly with objects", () => { let d = new Deck([ {}, {}, {}, {}, {} ]); expect(d.size).to.equal(5); }); it("should draw a single card from the deck properly", () => { let d = new Deck(["1", "2", "3", "4", "5"]); let c = d.draw(1); expect(d.size).to.equal(4); expect(c).to.have.length(1); expect(c[0]).to.be.a("string"); expect(c[0]).to.be.oneOf(["1", "2", "3", "4", "5"]); drawSuccess = true; }); it("should draw multiple cards from the deck properly", () => { let d = new Deck(["1", "2", "3", "4", "5"]); let draws = 2; let c = d.draw(draws); expect(d.size).to.equal(3); expect(c).to.have.length(draws); for (var i = 0; i < draws; i++) { expect(c[i]).to.be.a("string"); expect(c[i]).to.be.oneOf(["1", "2", "3", "4", "5"]); }; }); it("should draw all of the cards from the deck properly", () => { let d = new Deck(["1", "2", "3", "4", "5"]); let draws = 5; let c = d.draw(draws); expect(d.size).to.equal(0); expect(c).to.have.length(draws); for (var i = 0; i < draws; i++) { expect(c[i]).to.be.a("string"); expect(c[i]).to.be.oneOf(["1", "2", "3", "4", "5"]); }; }); it("should throw an error when -1 cards are drawn", () => { let d = new Deck(["1", "2", "3", "4", "5"]); try { d.draw(-1); throw "draw() didn't error with -1 given"; } catch (e) {}; }); it("should throw an error when -5 cards are drawn", () => { let d = new Deck(["1", "2", "3", "4", "5"]); try { d.draw(-5); throw "draw() didn't error with -5 given"; } catch (e) {}; }); it("should throw an error when n+1 cards were requested", () => { let d = new Deck(["1", "2", "3", "4", "5"]); try { d.draw(6); throw "Draw didn't error with 6 given"; } catch (e) {}; }); it("should throw an error when n+5 cards were requested", () => { let d = new Deck(["1", "2", "3", "4", "5"]); try { d.draw(10); throw "Draw didn't error with 10 given"; } catch (e) {}; }); it("should error when discarding something that isn't a card in the deck", function (this: Mocha.Context) { if (!drawSuccess) { this.skip() }; let d = new Deck(["1", "2", "3", "4", "5"]); d.draw(1); try { d.discard("potato"); throw "Didn't error when discarding an invalid card" } catch (_) {}; }); it("shouldn't error when discarding a valid card", function (this: Mocha.Context) { if (!drawSuccess) { this.skip() }; const d = new Deck(["1", "2", "3", "4", "5"]); const c = d.draw(1)[0]; d.discard(c); }); it("should reset count when card is in unknown domain", function (this: Mocha.Context) { if (!drawSuccess) { this.skip() }; const d = new Deck(["1", "2", "3", "4", "5"]); d.draw(1); d.reset(); expect(d.size).to.equal(5); }); it("should reset count when card is in discard", function (this: Mocha.Context) { if (!drawSuccess) { this.skip() }; const d = new Deck(["1", "2", "3", "4", "5"]); const c = d.draw(1)[0]; d.discard(c); d.reset(); expect(d.size).to.equal(5); }); });