@@ -416,74 +416,4 @@ def test_jump_search():
416416 _test_common_search (jump_search , backend = Backend .CPP )
417417
418418def test_radix_sort ():
419- random .seed (1000 )
420-
421- # Test with DynamicOneDimensionalArray
422- n = random .randint (10 , 20 )
423- arr = DynamicOneDimensionalArray (int , 0 )
424- generated_ints = []
425- for _ in range (n ):
426- integer = random .randint (1 , 1000 )
427- generated_ints .append (integer )
428- arr .append (integer )
429- for _ in range (n // 3 ):
430- integer = random .randint (0 , n // 2 )
431- generated_ints .append (integer )
432- arr .delete (integer )
433- expected_arr_1 = [686 , 779 , 102 , 134 , 362 , 448 ,
434- 480 , 548 , None , None , None ,
435- 228 , 688 , 247 , 373 , 696 , None ,
436- None , None , None , None , None ,
437- None , None , None , None , None ,
438- None , None , None , None ]
439- radix_sort (arr , start = 2 , end = 10 )
440- assert arr ._data == expected_arr_1
441- radix_sort (arr )
442- expected_arr_2 = [102 , 134 , 228 , 247 , 362 , 373 , 448 ,
443- 480 , 548 , 686 , 688 , 696 , 779 ,
444- None , None , None , None , None , None ,
445- None , None , None , None , None ,
446- None , None , None , None , None , None , None ]
447- assert arr ._data == expected_arr_2
448- assert (arr ._last_pos_filled , arr ._num , arr ._size ) == (12 , 13 , 31 )
449-
450- # Test with DynamicOneDimensionalArray (CPP backend)
451- arr = DynamicOneDimensionalArray (int , 0 , backend = Backend .CPP )
452- int_idx = 0
453- for _ in range (n ):
454- arr .append (generated_ints [int_idx ])
455- int_idx += 1
456- for _ in range (n // 3 ):
457- arr .delete (generated_ints [int_idx ])
458- int_idx += 1
459- radix_sort (arr , start = 2 , end = 10 )
460- for i in range (len (expected_arr_1 )):
461- assert arr [i ] == expected_arr_1 [i ]
462- radix_sort (arr )
463- for i in range (len (expected_arr_2 )):
464- assert arr [i ] == expected_arr_2 [i ]
465- assert (arr ._last_pos_filled , arr ._num , arr .size ) == (12 , 13 , 31 )
466-
467- # Test with OneDimensionalArray
468- n = random .randint (10 , 20 )
469- arr = OneDimensionalArray (int , n )
470- generated_ints .clear ()
471- for i in range (n ):
472- integer = random .randint (1 , 1000 )
473- arr [i ] = integer
474- generated_ints .append (integer )
475- expected_arr_3 = [42 , 695 , 147 , 500 , 768 ,
476- 998 , 473 , 732 , 728 , 426 ,
477- 709 , 910 ]
478- radix_sort (arr , start = 2 , end = 5 )
479- assert arr ._data == expected_arr_3
480-
481- # Test with OneDimensionalArray (CPP backend)
482- arr = OneDimensionalArray (int , n , backend = Backend .CPP )
483- int_idx = 0
484- for i in range (n ):
485- arr [i ] = generated_ints [int_idx ]
486- int_idx += 1
487- radix_sort (arr , start = 2 , end = 5 )
488- for i in range (len (expected_arr_3 )):
489- assert arr [i ] == expected_arr_3
419+ _test_common_sort (radix_sort )
0 commit comments