@@ -76,6 +76,16 @@ contract IntArrayLibTester {
7676 return y;
7777 }
7878
79+ function fill (int256 [] memory x , int256 v ) external pure returns (int256 [] memory ) {
80+ IntArrayLib.fill (x, v);
81+ return x;
82+ }
83+
84+ function sortByIndexes (int256 [] memory x , uint256 [] memory indexes ) external pure returns (int256 [] memory ) {
85+ int256 [] memory y = IntArrayLib.sortByIndexes (x, indexes);
86+ return y;
87+ }
88+
7989 function concat (int256 [] memory a , int256 [] memory b ) external pure returns (int256 [] memory ) {
8090 int256 [] memory y = IntArrayLib.concat (a, b);
8191 return y;
@@ -160,6 +170,16 @@ contract IntArrayLibCoverage is Test {
160170 assertEq (tester.min (arr), - 3 );
161171 }
162172
173+ function testMin2 () public {
174+ int256 [] memory arr = new int256 [](5 );
175+ arr[0 ] = 100 ;
176+ arr[1 ] = 200 ;
177+ arr[2 ] = type (int256 ).min;
178+ arr[3 ] = 300 ;
179+ arr[4 ] = type (int256 ).min;
180+ assertEq (tester.min (arr), type (int256 ).min);
181+ }
182+
163183 function testMinWithIndex () public {
164184 int256 [] memory arr = _getDefaultArray ();
165185 (int256 min_ , uint256 idx ) = tester.minWithIndex (arr);
@@ -175,9 +195,15 @@ contract IntArrayLibCoverage is Test {
175195
176196 function testRemove () public {
177197 int256 [] memory arr = _getDefaultArray ();
178- int256 [] memory removed = tester.remove (arr, 0 );
179- assertEq (removed[0 ], 5 );
198+ int256 [] memory removed = tester.remove (arr, 1 );
199+ assertEq (removed[0 ], 1 );
200+ assertEq (removed[1 ], - 2 );
180201 assertEq (removed.length , 4 );
202+
203+ // remove index 5: unchange
204+ int256 [] memory removed2 = tester.remove (arr, 5 );
205+ assertEq (removed2[4 ], - 3 );
206+ assertEq (removed2.length , 5 );
181207 }
182208
183209 function testIndexOf () public {
@@ -209,6 +235,25 @@ contract IntArrayLibCoverage is Test {
209235 assertEq (indexes[4 ], 1 );
210236 }
211237
238+ function testSortByIndex () public {
239+ // default [1, 5, -2, 4, -3]
240+ int256 [] memory arr = _getDefaultArray ();
241+
242+ uint256 [] memory idxs = new uint256 [](5 );
243+ idxs[0 ] = 1 ; // first element is arr[1] = 5
244+ idxs[1 ] = 3 ; // second element is arr[3] = 4
245+ idxs[2 ] = 0 ;
246+ idxs[3 ] = 2 ;
247+ idxs[4 ] = 4 ;
248+
249+ int256 [] memory sorted = tester.sortByIndexes (arr, idxs);
250+ assertEq (sorted[0 ], 5 );
251+ assertEq (sorted[1 ], 4 );
252+ assertEq (sorted[2 ], 1 );
253+ assertEq (sorted[3 ], - 2 );
254+ assertEq (sorted[4 ], - 3 );
255+ }
256+
212257 function testSort () public {
213258 int256 [] memory arr = _getDefaultArray ();
214259 arr = tester.sort (arr);
@@ -297,6 +342,14 @@ contract IntArrayLibCoverage is Test {
297342 assertEq (newArr[4 ], newArr[9 ]);
298343 }
299344
345+ function testFill () public {
346+ int256 [] memory empty = new int256 [](5 );
347+
348+ int256 [] memory newArr = tester.fill (empty, 77 );
349+ assertEq (newArr[0 ], 77 );
350+ assertEq (newArr[4 ], 77 );
351+ }
352+
300353 function testPopulate () public {
301354 int256 [] memory empty = new int256 [](5 );
302355 int256 [] memory arr = _getDefaultArray ();
0 commit comments