37 lines
956 B
TypeScript
37 lines
956 B
TypeScript
|
import {CamelCard, CamelCards} from "./day_seven";
|
||
|
|
||
|
describe('Day Seven', () => {
|
||
|
const input = `32T3K 765
|
||
|
T55J5 684
|
||
|
KK677 28
|
||
|
KTJJT 220
|
||
|
QQQJA 483`;
|
||
|
|
||
|
it.each([
|
||
|
['AAAAA', 7], // Five of a kind
|
||
|
['AA8AA', 6], // Four of a kind
|
||
|
['AABBB', 5], // Full house
|
||
|
['T55C5', 4], // Three of a kind
|
||
|
['KK677', 3], // Two pairs
|
||
|
['32T3K', 2], // One pair
|
||
|
['12345', 1], // High card
|
||
|
|
||
|
['T55J5', 6], // Four of a kind with Joker
|
||
|
['KTJJT', 6],
|
||
|
['QQQJA', 6]
|
||
|
])('should should correctly score %s as %s', (card, score) => {
|
||
|
const camelCard = new CamelCard(card);
|
||
|
expect(camelCard.score).toEqual(score);
|
||
|
});
|
||
|
|
||
|
it('should correctly compare two clashing cards', () => {
|
||
|
const a = new CamelCard('AA2CC');
|
||
|
const b = new CamelCard('AATCC');
|
||
|
expect(a.compare(b)).toBeLessThan(0);
|
||
|
});
|
||
|
|
||
|
it('should parse the input and calculate the total winnings', () => {
|
||
|
const camelCards = new CamelCards(input);
|
||
|
expect(camelCards.winnings).toEqual(5905);
|
||
|
})
|
||
|
});
|