anvilsign in

collin/mahjong

1import { describe, expect, it } from 'vitest';
2import { reconcileOrder } from './handOrder';
3
4describe('reconcileOrder', () => {
5 it('keeps an arrangement while the tiles are all still there', () => {
6 expect(reconcileOrder([5, 2, 9, 2], [2, 2, 5, 9])).toEqual([5, 2, 9, 2]);
7 });
8
9 it('appends a new draw at the end, whatever the engine sorted it next to', () => {
10 expect(reconcileOrder([5, 2, 9], [2, 3, 5, 9])).toEqual([5, 2, 9, 3]);
11 });
12
13 it('drops a discard and keeps everything else where it was', () => {
14 expect(reconcileOrder([5, 2, 9, 3], [2, 5, 9])).toEqual([5, 2, 9]);
15 });
16
17 it('handles duplicates by count, not identity', () => {
18 // Two of the 2s went (a pung claim), one 7 arrived.
19 expect(reconcileOrder([2, 8, 2, 2], [2, 7, 8])).toEqual([2, 8, 7]);
20 });
21
22 it('builds an order from nothing', () => {
23 expect(reconcileOrder([], [3, 1, 2])).toEqual([3, 1, 2]);
24 });
25
26 it('survives a whole new hand', () => {
27 expect(reconcileOrder([1, 2, 3], [10, 11, 12])).toEqual([10, 11, 12]);
28 });
29});