1- // @dart=2.9
21import 'package:test/test.dart' ;
32
43import 'package:algorithms/sorts/distribution.dart' ;
54
65void main () {
7- List <int > randomList;
8- List <int > positiveRandomList;
9- List <int > sortedRandomListAscending;
10- List <int > sortedRandomListDescending;
11- List <int > sortedPositiveRandomListAscending;
12- List <int > sortedPositiveRandomListDescending;
13- List <int > allNegatives;
14- List <int > someNegatives;
15- List <int > sortedAllNegatives;
16- List <int > sortedSomeNegatives;
17- List <num > randomDistribution;
18- List <num > randomDistributionSorted;
19-
20- List <int > emptyList;
21-
6+ List <int >? randomList, positiveRandomList, sortedRandomListAscending,
7+ sortedRandomListDescending, sortedPositiveRandomListAscending,
8+ sortedPositiveRandomListDescending, allNegatives, someNegatives,
9+ sortedAllNegatives, sortedSomeNegatives, emptyList;
10+ List <double >? randomDistribution, randomDistributionSorted;
2211 setUp (() {
2312 emptyList = [];
2413 randomList = [2 , 4 , 2 , 1 , - 1 , 0 , 20 ];
@@ -39,67 +28,67 @@ void main() {
3928 });
4029
4130 test ('Pigeonhole Sort' , () {
42- expect (pigeonholeSort (randomList), equals (sortedRandomListAscending));
43- expect (pigeonholeSort (randomList, desc: false ),
31+ expect (pigeonholeSort (randomList! ), equals (sortedRandomListAscending));
32+ expect (pigeonholeSort (randomList! , desc: false ),
4433 equals (sortedRandomListAscending));
45- expect (pigeonholeSort (randomList, desc: true ),
34+ expect (pigeonholeSort (randomList! , desc: true ),
4635 equals (sortedRandomListDescending));
4736
48- expect (pigeonholeSort (emptyList), equals (emptyList));
49- expect (pigeonholeSort (emptyList, desc: false ), equals (emptyList));
50- expect (pigeonholeSort (emptyList, desc: true ), equals (emptyList));
37+ expect (pigeonholeSort (emptyList! ), equals (emptyList));
38+ expect (pigeonholeSort (emptyList! , desc: false ), equals (emptyList));
39+ expect (pigeonholeSort (emptyList! , desc: true ), equals (emptyList));
5140 });
5241
5342 test ('Counting Sort' , () {
54- expect (countingSort (positiveRandomList),
43+ expect (countingSort (positiveRandomList! ),
5544 equals (sortedPositiveRandomListAscending));
56- expect (countingSort (positiveRandomList, desc: false ),
45+ expect (countingSort (positiveRandomList! , desc: false ),
5746 equals (sortedPositiveRandomListAscending));
58- expect (countingSort (positiveRandomList, desc: true ),
47+ expect (countingSort (positiveRandomList! , desc: true ),
5948 equals (sortedPositiveRandomListDescending));
6049
61- expect (countingSort (emptyList), equals (emptyList));
62- expect (countingSort (emptyList, desc: false ), equals (emptyList));
63- expect (countingSort (emptyList, desc: true ), equals (emptyList));
50+ expect (countingSort (emptyList! ), equals (emptyList));
51+ expect (countingSort (emptyList! , desc: false ), equals (emptyList));
52+ expect (countingSort (emptyList! , desc: true ), equals (emptyList));
6453
65- expect (countingSort (allNegatives), equals (sortedAllNegatives));
66- expect (countingSort (someNegatives), equals (sortedSomeNegatives));
54+ expect (countingSort (allNegatives! ), equals (sortedAllNegatives));
55+ expect (countingSort (someNegatives! ), equals (sortedSomeNegatives));
6756 });
6857
6958 test ('Radix Sort for positive numbers' , () {
70- expect (radixSort (positiveRandomList),
59+ expect (radixSort (positiveRandomList! ),
7160 equals (sortedPositiveRandomListAscending));
72- expect (radixSort (positiveRandomList, desc: false ),
61+ expect (radixSort (positiveRandomList! , desc: false ),
7362 equals (sortedPositiveRandomListAscending));
74- expect (radixSort (positiveRandomList, desc: true ),
63+ expect (radixSort (positiveRandomList! , desc: true ),
7564 equals (sortedPositiveRandomListDescending));
7665
77- expect (radixSort (emptyList), equals (emptyList));
78- expect (radixSort (emptyList, desc: false ), equals (emptyList));
79- expect (radixSort (emptyList, desc: true ), equals (emptyList));
66+ expect (radixSort (emptyList! ), equals (emptyList));
67+ expect (radixSort (emptyList! , desc: false ), equals (emptyList));
68+ expect (radixSort (emptyList! , desc: true ), equals (emptyList));
8069
81- expect (radixSort (allNegatives), equals (sortedAllNegatives));
82- expect (radixSort (someNegatives), equals (sortedSomeNegatives));
70+ expect (radixSort (allNegatives! ), equals (sortedAllNegatives));
71+ expect (radixSort (someNegatives! ), equals (sortedSomeNegatives));
8372 });
8473
8574 test ('Bucket sort for positive numbers' , () {
86- expect (bucketSort (positiveRandomList),
75+ expect (bucketSort (positiveRandomList! ),
8776 equals (sortedPositiveRandomListAscending));
88- expect (bucketSort (positiveRandomList, desc: false ),
77+ expect (bucketSort (positiveRandomList! , desc: false ),
8978 equals (sortedPositiveRandomListAscending));
90- expect (bucketSort (positiveRandomList, desc: true ),
79+ expect (bucketSort (positiveRandomList! , desc: true ),
9180 equals (sortedPositiveRandomListDescending));
92- expect (bucketSort (randomDistribution), equals (randomDistributionSorted));
93- expect (bucketSort (randomDistribution, desc: true ),
94- equals (randomDistributionSorted.reversed));
81+ expect (bucketSort (randomDistribution! ), equals (randomDistributionSorted));
82+ expect (bucketSort (randomDistribution! , desc: true ),
83+ equals (randomDistributionSorted! .reversed));
9584
96- expect (bucketSort (emptyList), equals (emptyList));
97- expect (bucketSort (emptyList, desc: false ), equals (emptyList));
98- expect (bucketSort (emptyList, desc: true ), equals (emptyList));
85+ expect (bucketSort (emptyList! ), equals (emptyList));
86+ expect (bucketSort (emptyList! , desc: false ), equals (emptyList));
87+ expect (bucketSort (emptyList! , desc: true ), equals (emptyList));
9988 });
10089
10190 test ('Bucket sort for negative numbers' , () {
102- expect (() => bucketSort (allNegatives), throwsA (isA <FormatException >()));
103- expect (() => bucketSort (someNegatives), throwsA (isA <FormatException >()));
91+ expect (() => bucketSort (allNegatives! ), throwsA (isA <FormatException >()));
92+ expect (() => bucketSort (someNegatives! ), throwsA (isA <FormatException >()));
10493 });
10594}
0 commit comments