deck-of-cards-ts
Version:
Deck of cards package with TypeScript types.
58 lines • 2.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var constants_1 = require("./constants");
var deck_1 = require("./deck");
describe('Deck tests', function () {
test('Instantiates with the correct number of cards', function () {
expect(new deck_1.default().getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 1);
expect(new deck_1.default(1).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 1);
expect(new deck_1.default(2).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 2);
expect(new deck_1.default(10).getCards().length).toBe(constants_1.FULL_DECK_CARD_COUNT * 10);
});
test('Instantiating a full deck does not repeat cards', function () {
var deck = new deck_1.default();
var cards = deck.getCards();
var uniqueCards = new Set(cards);
expect(uniqueCards.size).toBe(constants_1.FULL_DECK_CARD_COUNT);
});
test('Drawing a card removes it from the deck', function () {
var deck = new deck_1.default();
var card = deck.draw();
expect(card).not.toBe(null);
expect(deck.getCards().some(function (c) {
if (deck.isThisYourCard(c, card)) {
console.log(c);
console.log(card);
}
return deck.isThisYourCard(c, card);
})).toBe(false);
});
test('Drawing after the last card returns null', function () {
var deck = new deck_1.default(0);
var card = deck.draw();
expect(card).toBe(null);
});
test('Shuffling changes the order of the cards', function () {
var deck = new deck_1.default();
var cards = deck.getCards();
deck.shuffle();
var cardsCopy = deck.getCards();
expect(cards).not.toEqual(cardsCopy);
});
test('isThisYourCard returns true when the cards are the same', function () {
var deck = new deck_1.default();
var cards = deck.getCards();
expect(deck.isThisYourCard(cards[0], cards[0])).toBe(true);
});
test('isThisYourCard returns false when the cards are different', function () {
var deck = new deck_1.default();
var cards = deck.getCards();
expect(deck.isThisYourCard(cards[0], cards[1])).toBe(false);
});
test('Calling toString on a card returns the string implementation of the card', function () {
var deck = new deck_1.default();
var cards = deck.getCards();
expect(cards[0].toString()).toBe("".concat(cards[0].rank, " of ").concat(cards[0].suit));
});
});
//# sourceMappingURL=deck.test.js.map