Skip to content

Commit

Permalink
Co-authored-by: 賴鴻德 <[email protected]>
Browse files Browse the repository at this point in the history
Co-authored-by: Pikacnu  <[email protected]>
Co-authored-by: Tuhacrt <[email protected]>
  • Loading branch information
Dlutermade committed Nov 12, 2023
1 parent 433451f commit f21033b
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Creature, Status } from 'card';
import { createIdToPlayer, createPlayer } from 'player';
import { pipe } from 'fp-ts/function';
import O from 'fp-ts/Option';

import { checkPlayerHasUnrevealedCardOfHands } from './checkPlayerHasUnrevealedCardOfHands';

describe('checkPlayerHasUnrevealedCardOfHands', () => {
it(`
given a player
hands [
{ id: 1, status: 'UNREVEALED', creature: 'BAT' }
]
when check player has unrevealed card
then
player has unrevealedCard
`, () => {
const hasUnrevealedCard = pipe(
{ uid: '1', name: 'player1' },
createPlayer,
createIdToPlayer,
O.map((player) => {
player.hands = [
{ id: 1, status: Status.Unrevealed, creature: Creature.Bat },
];
return player;
}),
O.map(checkPlayerHasUnrevealedCardOfHands),
);

expect(hasUnrevealedCard).toStrictEqual(O.some(true));
});

it(`
given a player
hands [
]
when check player has unrevealed card
then
player not has unrevealedCard
`, () => {
const hasUnrevealedCard = pipe(
{ uid: '1', name: 'player1' },
createPlayer,
createIdToPlayer,
O.map(checkPlayerHasUnrevealedCardOfHands),
);

expect(hasUnrevealedCard).toStrictEqual(O.some(false));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Player } from 'player';
import { pipe } from 'fp-ts/function';
import { prop } from 'remeda';

export interface CheckPlayerHasUnrevealedCardOfHands {
(player: Player): boolean;
}

export const checkPlayerHasUnrevealedCardOfHands: CheckPlayerHasUnrevealedCardOfHands =
(player: Player) =>
pipe(
//
player,
prop('hands'),
prop('length'),
(length) => length > 0,
);
Loading

0 comments on commit f21033b

Please sign in to comment.