Skip to content

Commit feb0e29

Browse files
committed
feat(hand): inherit from ICardPile
1 parent 3272e9c commit feb0e29

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ICard } from '../card/card.interface'
2-
import { ICardCollection } from './cardCollection.interface'
2+
import { ICardPile } from './cardPile.interface'
33
import { IRankSet } from '../card/rankSet.interface'
44

5-
export interface IHand extends ICardCollection {
5+
export interface IHand extends ICardPile {
66
sortCards (cardRank: IRankSet): IHand
77
playCard (card: ICard): void
88
}

src/models/cardCollection/hand.model.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Suit } from '../card/suit.model'
2-
import { CardCollection } from './cardCollection.model'
2+
import { CardPile } from './cardPile.model'
33
import { MapExtensions } from '../../common/mapExtensions.model'
44
import { IHand } from './hand.interface'
55
import { ICard } from '../card/card.interface'
@@ -8,14 +8,12 @@ import { IRankSet } from '../card/rankSet.interface'
88
/**
99
* Represents a group of cards assigned to an IPlayer
1010
*/
11-
export class Hand extends CardCollection implements IHand {
12-
11+
export class Hand extends CardPile implements IHand {
12+
public name = 'Hand'
1313
public suitOrder: Suit[] = [Suit.Clubs, Suit.Spades, Suit.Diamonds, Suit.Hearts]
1414

1515
constructor (cards: ICard[] = []) {
16-
super(cards) // CardCollection.constructor
17-
18-
this.friendlyName = 'Hand' // default name
16+
super(cards) // CardPile.constructor
1917
}
2018

2119
/**

src/models/cardCollection/hand.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ test('is empty with no cards', async t => {
1212
t.true(hand.isEmpty(), 'isEmpty() should have been true')
1313
})
1414

15+
test('has default name', async t => {
16+
const hand = new Hand()
17+
t.deepEqual(hand.name, 'Hand')
18+
})
19+
20+
test('can assign name', async t => {
21+
const hand = new Hand()
22+
hand.name = 'Player 1 Hand'
23+
t.deepEqual(hand.name, 'Player 1 Hand')
24+
})
25+
1526
test('has cards when initialized with them', async t => {
1627
const cards: ICard[] = [
1728
new PlayingCard(CardName.Eight, Suit.Diamonds),

0 commit comments

Comments
 (0)