-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deck: Implemented Fisher-Yates shuffling algorithm to shuffle the deck
Fixes: #2
- Loading branch information
1 parent
f05595c
commit ef2dc47
Showing
2 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,28 @@ | ||
import { makeCard } from '../uno-game-engine/deck'; | ||
import { shuffle, makeCard } from '../uno-game-engine/deck'; | ||
describe('testing deck.ts', () => { | ||
test('makeCard', () => { | ||
const card = makeCard('number', 'blue', '3'); | ||
expect(card.color).toBe('blue'); | ||
}); | ||
}); | ||
describe('shuffle function', () => { | ||
test('should change order of elements', () => { | ||
// Create a mock deck | ||
const deck = [ | ||
makeCard('number', 'red', '1'), | ||
makeCard('number', 'blue', '2'), | ||
makeCard('number', 'red', '1'), | ||
makeCard('number', 'yellow', '1'), | ||
]; | ||
|
||
// Create a copy of the deck for comparison | ||
const originalDeck = [...deck]; | ||
shuffle(deck); | ||
|
||
// Check that the order of elements has changed | ||
const orderChanged = deck.some( | ||
(card, index) => card !== originalDeck[index] | ||
); | ||
expect(orderChanged).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters