1+ const radixSort = require ( './radix-sort' ) ;
2+
3+ describe ( 'Testing Radix Sort Algorithm' , ( ) => {
4+ it ( 'should sort with multiple digit elements #1' , ( ) => {
5+ expect ( radixSort ( [ 5 , 3 , 88 , 235 , 65 , 23 , 4632 , 234 ] ) ) . toEqual ( [ 3 , 5 , 23 , 65 , 88 , 234 , 235 , 4632 ] ) ;
6+ } ) ;
7+
8+ it ( 'should sort with multiple digit elements #2' , ( ) => {
9+ expect ( radixSort ( [ 802 , 630 , 20 , 745 , 52 , 300 , 612 , 932 , 78 , 187 ] ) ) . toEqual ( [ 20 , 52 , 78 , 187 , 300 , 612 , 630 , 802 , 932 ] ) ;
10+ } ) ;
11+
12+ it ( 'should sort with duplicated values' , ( ) => {
13+ expect ( radixSort ( [ 45 , 2 , 56 , 2 , 5 , 6 , 34 , 1 , 56 , 89 , 33 ] ) ) . toEqual ( [ 1 , 2 , 2 , 5 , 6 , 33 , 34 , 45 , 56 , 56 , 89 ] ) ;
14+ } ) ;
15+
16+ it ( 'should work with zero numbers' , ( ) => {
17+ expect ( radixSort ( [ ] ) ) . toEqual ( [ ] ) ;
18+ } ) ;
19+
20+ it ( 'should work with one number' , ( ) => {
21+ expect ( radixSort ( [ 3 ] ) ) . toEqual ( [ 3 ] ) ;
22+ } ) ;
23+
24+ it ( 'should sort numbers' , ( ) => {
25+ expect ( radixSort ( [ 3 , 5 , 0 ] ) ) . toEqual ( [ 0 , 3 , 5 ] ) ;
26+ } ) ;
27+
28+ it ( 'should sort with inverse array' , ( ) => {
29+ expect ( radixSort ( [ 3 , 2 , 1 ] ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
30+ } ) ;
31+
32+ it ( 'should sort with already sorted array' , ( ) => {
33+ expect ( radixSort ( [ 1 , 2 , 3 ] ) ) . toEqual ( [ 1 , 2 , 3 ] ) ;
34+ } ) ;
35+ } ) ;
0 commit comments