@@ -48,13 +48,13 @@ describe('defaultComparator', () =>
48
48
testComparison ( defaultComparator , sorted , values , [ [ dateA , dateA2 ] , [ 0 , - 0 ] , [ [ 1 ] , [ '1' ] ] ] ) ;
49
49
} ) ;
50
50
51
- describe ( 'compareFiniteNumbers ' , ( ) =>
51
+ describe ( 'simpleComparator with non-NaN numbers and null ' , ( ) =>
52
52
{
53
- const sorted = [ - Infinity , - 10 , - 1 , - 0 , 0 , 1 , 2 , 10 , Infinity ] ;
54
- testComparison ( simpleComparator , sorted , sorted , [ [ - 0 , 0 ] ] ) ;
53
+ const sorted = [ - Infinity , - 10 , - 1 , - 0 , 0 , null , 1 , 2 , 10 , Infinity ] ;
54
+ testComparison < number | null > ( simpleComparator , sorted , sorted , [ [ - 0 , 0 ] , [ - 0 , null ] , [ 0 , null ] ] ) ;
55
55
} ) ;
56
56
57
- describe ( 'compareStrings ' , ( ) =>
57
+ describe ( 'simpleComparator with strings ' , ( ) =>
58
58
{
59
59
const values = [
60
60
'24x' ,
@@ -68,15 +68,40 @@ describe('compareStrings', () =>
68
68
'10' ,
69
69
"NaN" ,
70
70
] ; ;
71
- testComparison ( simpleComparator , [ ] , values , [ ] ) ;
71
+ testComparison < string > ( simpleComparator , [ ] , values , [ ] ) ;
72
+ } ) ;
73
+
74
+ describe ( 'simpleComparator with Date' , ( ) =>
75
+ {
76
+ const dateA = new Date ( Date . UTC ( 96 , 1 , 2 , 3 , 4 , 5 ) ) ;
77
+ const dateA2 = new Date ( Date . UTC ( 96 , 1 , 2 , 3 , 4 , 5 ) ) ;
78
+ const dateB = new Date ( Date . UTC ( 96 , 1 , 2 , 3 , 4 , 6 ) ) ;
79
+ const values = [
80
+ dateA ,
81
+ dateA2 ,
82
+ dateB ,
83
+ null ,
84
+ ] ;
85
+ testComparison < Date > ( simpleComparator , [ ] , values , [ [ dateA , dateA2 ] ] ) ;
86
+ } ) ;
87
+
88
+ describe ( 'simpleComparator arrays' , ( ) =>
89
+ {
90
+ const values = [
91
+ [ ] ,
92
+ [ 1 ] ,
93
+ [ '1' ] ,
94
+ [ 2 ] ,
95
+ ] ;
96
+ testComparison < ( number | string ) [ ] > ( simpleComparator , [ ] , values , [ [ [ 1 ] , [ '1' ] ] ] ) ;
72
97
} ) ;
73
98
74
99
/**
75
100
* Tests a comparison function, ensuring it produces a strict partial order over the provided values.
76
101
* Additionally confirms that the comparison function has the correct definition of equality via expectedDuplicates.
77
102
*/
78
- function testComparison ( comparison : ( a : any , b : any ) => number , inOrder : any [ ] , values : any [ ] , expectedDuplicates : [ any , any ] [ ] = [ ] ) {
79
- function compare ( a : any , b : any ) : number {
103
+ function testComparison < T > ( comparison : ( a : T , b : T ) => number , inOrder : T [ ] , values : T [ ] , expectedDuplicates : [ T , T ] [ ] = [ ] ) {
104
+ function compare ( a : T , b : T ) : number {
80
105
const v = comparison ( a , b ) ;
81
106
expect ( typeof v ) . toEqual ( 'number' ) ;
82
107
if ( v !== v )
0 commit comments