UNPKG

deck-of-cards-ts

Version:

Deck of cards package with TypeScript types.

68 lines 3.26 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const constants_1 = require("./constants"); const deck_1 = __importDefault(require("./deck")); describe('Deck tests', () => { it('Instantiates with the correct number of cards', () => { (0, vitest_1.expect)(new deck_1.default().getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 1); (0, vitest_1.expect)(new deck_1.default(1).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 1); (0, vitest_1.expect)(new deck_1.default(2).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 2); (0, vitest_1.expect)(new deck_1.default(10).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 10); }); it('Instantiating a full deck does not repeat cards', () => { const deck = new deck_1.default(); const cards = deck.getCards(); const uniqueCards = new Set(cards); (0, vitest_1.expect)(uniqueCards.size).toBe(constants_1.FULL_DECK_CARD_COUNT); }); it('Drawing a card removes it from the deck', () => { const deck = new deck_1.default(); const card = deck.draw(); (0, vitest_1.expect)(card).not.toBe(null); (0, vitest_1.expect)(deck.getCards().some((c) => { if (deck.isThisYourCard(c, card)) { console.log(c); console.log(card); } return deck.isThisYourCard(c, card); })).toBe(false); }); it('Drawing after the last card returns null', () => { const deck = new deck_1.default(0); const card = deck.draw(); (0, vitest_1.expect)(card).toBe(null); }); it('Shuffling changes the order of the cards', () => { const deck = new deck_1.default(); const cards = deck.getCards(); deck.shuffle(); const cardsCopy = deck.getCards(); (0, vitest_1.expect)(cards).not.toEqual(cardsCopy); }); it('isThisYourCard returns true when the cards are the same', () => { const deck = new deck_1.default(); const cards = deck.getCards(); (0, vitest_1.expect)(deck.isThisYourCard(cards[0], cards[0])).toBe(true); }); it('isThisYourCard returns false when the cards are different', () => { const deck = new deck_1.default(); const cards = deck.getCards(); (0, vitest_1.expect)(deck.isThisYourCard(cards[0], cards[1])).toBe(false); }); it('Calling toString on a card returns the string implementation of the card', () => { const deck = new deck_1.default(); const cards = deck.getCards(); (0, vitest_1.expect)(cards[0].toString()).toBe(`${cards[0].rank} of ${cards[0].suit}`); }); it('Empties the deck before resetting it', () => { const deck = new deck_1.default(2); (0, vitest_1.expect)(deck.getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 2); deck.resetDeck(); (0, vitest_1.expect)(deck.getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 2); }); }); //# sourceMappingURL=deck.test.js.map