Testing Fisher-Yates Shuffle Algorithm Implementation in javascript-algorithms
This test suite validates the Fisher-Yates shuffle algorithm implementation in JavaScript. It ensures the algorithm correctly randomizes array elements while maintaining array integrity and original element preservation.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/sets/fisher-yates/__test__/fisherYates.test.js
import fisherYates from '../fisherYates';
import { sortedArr } from '../../../sorting/SortTester';
import QuickSort from '../../../sorting/quick-sort/QuickSort';
describe('fisherYates', () => {
it('should shuffle small arrays', () => {
expect(fisherYates([])).toEqual([]);
expect(fisherYates([1])).toEqual([1]);
});
it('should shuffle array randomly', () => {
const shuffledArray = fisherYates(sortedArr);
const sorter = new QuickSort();
expect(shuffledArray.length).toBe(sortedArr.length);
expect(shuffledArray).not.toEqual(sortedArr);
expect(sorter.sort(shuffledArray)).toEqual(sortedArr);
});
});