Validating Selection Sort Algorithm Implementation in javascript-algorithms
This test suite validates the implementation of Selection Sort algorithm, focusing on array sorting functionality and algorithmic complexity verification. The tests cover basic sorting operations, custom comparator usage, and performance characteristics across different input scenarios.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
trekhleb/javascript-algorithms
src/algorithms/sorting/selection-sort/__test__/SelectionSort.test.js
import SelectionSort from '../SelectionSort';
import {
equalArr,
notSortedArr,
reverseArr,
sortedArr,
SortTester,
} from '../../SortTester';
// Complexity constants.
const SORTED_ARRAY_VISITING_COUNT = 209;
const NOT_SORTED_ARRAY_VISITING_COUNT = 209;
const REVERSE_SORTED_ARRAY_VISITING_COUNT = 209;
const EQUAL_ARRAY_VISITING_COUNT = 209;
describe('SelectionSort', () => {
it('should sort array', () => {
SortTester.testSort(SelectionSort);
});
it('should sort array with custom comparator', () => {
SortTester.testSortWithCustomComparator(SelectionSort);
});
it('should sort negative numbers', () => {
SortTester.testNegativeNumbersSort(SelectionSort);
});
it('should visit EQUAL array element specified number of times', () => {
SortTester.testAlgorithmTimeComplexity(
SelectionSort,
equalArr,
EQUAL_ARRAY_VISITING_COUNT,
);
});
it('should visit SORTED array element specified number of times', () => {
SortTester.testAlgorithmTimeComplexity(
SelectionSort,
sortedArr,
SORTED_ARRAY_VISITING_COUNT,
);
});
it('should visit NOT SORTED array element specified number of times', () => {
SortTester.testAlgorithmTimeComplexity(
SelectionSort,
notSortedArr,
NOT_SORTED_ARRAY_VISITING_COUNT,
);
});
it('should visit REVERSE SORTED array element specified number of times', () => {
SortTester.testAlgorithmTimeComplexity(
SelectionSort,
reverseArr,
REVERSE_SORTED_ARRAY_VISITING_COUNT,
);
});
});