Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Hand from '../Hand';
- const TEST_IMG_URL = 'https://deckofcardsapi.com/static/img/back.png';
- const aceCard: Card = {
- value: 'ACE',
- suit: 'HEARTS',
- imageURL: TEST_IMG_URL
- };
- const queenCard: Card = {
- value: 'QUEEN',
- suit: 'HEARTS',
- imageURL: TEST_IMG_URL
- };
- const kingCard: Card = {
- value: 'KING',
- suit: 'HEARTS',
- imageURL: TEST_IMG_URL
- };
- const jackCard: Card = {
- value: 'JACK',
- suit: 'SPADES',
- imageURL: TEST_IMG_URL
- };
- const threeCard: Card = {
- value: '3',
- suit: 'CLUBS',
- imageURL: TEST_IMG_URL
- };
- const twoCard: Card = {
- value: '2',
- suit: 'DIAMONDS',
- imageURL: TEST_IMG_URL
- };
- const fiveCard: Card = {
- value: '5',
- suit: 'HEARTS',
- imageURL: TEST_IMG_URL
- };
- const tenCard: Card = {
- value: '10',
- suit: 'CLUBS',
- imageURL: TEST_IMG_URL
- }
- describe('isBusted', () => {
- it('busts after drawing 1 king, 1 queen, and 1 jack as total > 21', () => {
- const hand = new Hand();
- hand.addCard(kingCard);
- hand.addCard(queenCard);
- hand.addCard(jackCard);
- expect(hand.totalPoints).toEqual(30);
- expect(hand.isBusted()).toEqual(true);
- });
- it('does not bust after drawing 1 king and 1 queen as total <= 21', () => {
- const hand = new Hand();
- hand.addCard(kingCard);
- hand.addCard(queenCard);
- expect(hand.totalPoints).toEqual(20);
- expect(hand.isBusted()).toEqual(false);
- });
- });
- describe('addCard', () => {
- it('results in a count of cards and total points matching the cards added', () => {
- const hand = new Hand();
- hand.addCard(threeCard);
- hand.addCard(jackCard);
- expect(hand.cards.length).toEqual(2);
- });
- });
- describe('addCards', () => {
- it('results in a count of cards and total points matching the cards added', () => {
- const hand = new Hand();
- hand.addCards([threeCard, jackCard]);
- expect(hand.cards.length).toEqual(2);
- });
- });
- /* These are the same examples given in the README.md */
- describe('ace value', () => {
- it('is worth 1 point to add up to 21 if the player has a Jack and a Queen, and then draws an Ace', () => {
- const hand = new Hand();
- hand.addCard(queenCard);
- hand.addCard(jackCard);
- expect(hand.totalPoints).toEqual(20);
- hand.addCard(aceCard);
- expect(hand.totalPoints).toEqual(21);
- });
- it('If the player has a Queen and an Ace, the Ace will be worth 11 points to add up to 21', () => {
- const hand = new Hand();
- hand.addCard(queenCard);
- hand.addCard(aceCard);
- expect(hand.totalPoints).toEqual(21);
- });
- it('If the player has a 2 and an Ace, the Ace will be worth 11 points to get closer to 21', () => {
- const hand = new Hand();
- hand.addCard(twoCard);
- hand.addCard(aceCard);
- expect(hand.totalPoints).toEqual(13); // 2 + 11 = 13
- });
- it('If the player has a 2 and a 5, and then draws an Ace, the Ace will be worth 11 points to get closer to 21. If the player then draws a 10, the Ace will now be worth 1 point', () => {
- const hand = new Hand();
- hand.addCard(twoCard);
- hand.addCard(fiveCard);
- expect(hand.totalPoints).toEqual(7); // 2 + 5 = 7
- hand.addCard(aceCard);
- expect(hand.totalPoints).toEqual(18); // 2 + 5 + 11 = 18
- hand.addCard(tenCard);
- expect(hand.totalPoints).toEqual(18); // 2 + 5 + 1 + 10 = 18 (Ace adjusted to 1)
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement