40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { expect, test } from 'bun:test'
|
|
import ruleHighcard from './highcard'
|
|
import Pile from '../pile'
|
|
import Card, { Index, Suit } from '../card'
|
|
|
|
test('Ten beats One', () => {
|
|
const cardTen = new Card(Index.Ten, Suit.Club)
|
|
const cardOne = new Card(Index.One, Suit.Club)
|
|
|
|
const pile = new Pile([cardTen, cardOne])
|
|
expect(ruleHighcard(pile)).toBe(cardTen)
|
|
|
|
// Ensure it isn't just lucky ordering
|
|
const pileFlipped = new Pile([cardOne, cardTen])
|
|
expect(ruleHighcard(pileFlipped)).toBe(cardTen)
|
|
})
|
|
|
|
test('Ace beats King', () => {
|
|
const cardAce = new Card(Index.Ace, Suit.Club)
|
|
const cardKing = new Card(Index.King, Suit.Club)
|
|
|
|
const pile = new Pile([cardAce, cardKing])
|
|
expect(ruleHighcard(pile)).toBe(cardAce)
|
|
|
|
// Ensure it isn't just lucky ordering
|
|
const pileFlipped = new Pile([cardKing, cardAce])
|
|
expect(ruleHighcard(pileFlipped)).toBe(cardAce)
|
|
})
|
|
|
|
test('two hands compared for a winner', () => {
|
|
const cardAce = new Card(Index.Ace, Suit.Club)
|
|
const cardKing = new Card(Index.King, Suit.Club)
|
|
const cardTwo = new Card(Index.Two, Suit.Club)
|
|
const cardOne = new Card(Index.One, Suit.Club)
|
|
const hand1 = new Pile([cardAce, cardKing])
|
|
const hand2 = new Pile([cardOne, cardTwo])
|
|
|
|
expect(ruleHighcard(hand1)).toBe(cardAce)
|
|
expect(ruleHighcard(hand2)).toBe(cardTwo)
|
|
})
|