@@ -16,51 +16,43 @@ describe('BubbleSort', () => {
16
16
SortTester . testSortWithCustomComparator ( BubbleSort ) ;
17
17
} ) ;
18
18
19
- it ( 'should visit sorted array element specified number of times' , ( ) => {
20
- const visitingCallback = jest . fn ( ) ;
21
-
22
- const callbacks = { visitingCallback } ;
23
- const sorter = new BubbleSort ( callbacks ) ;
24
-
25
- const arrayAfterSorting = sorter . sort ( sortedArr ) ;
26
-
27
- expect ( arrayAfterSorting ) . toEqual ( sortedArr ) ;
28
- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
19
+ it ( 'should visit EQUAL array element specified number of times' , ( ) => {
20
+ const expectedNumberOfVisits = 19 ;
21
+
22
+ SortTester . testAlgorithmTimeComplexity (
23
+ BubbleSort ,
24
+ equalArr ,
25
+ expectedNumberOfVisits ,
26
+ ) ;
29
27
} ) ;
30
28
31
- it ( 'should visit not-sorted array element specified number of times' , ( ) => {
32
- const visitingCallback = jest . fn ( ) ;
33
-
34
- const callbacks = { visitingCallback } ;
35
- const sorter = new BubbleSort ( callbacks ) ;
36
-
37
- const arrayAfterSorting = sorter . sort ( notSortedArr ) ;
29
+ it ( 'should visit SORTED array element specified number of times' , ( ) => {
30
+ const expectedNumberOfVisits = 19 ;
38
31
39
- expect ( arrayAfterSorting ) . toEqual ( sortedArr ) ;
40
- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
32
+ SortTester . testAlgorithmTimeComplexity (
33
+ BubbleSort ,
34
+ sortedArr ,
35
+ expectedNumberOfVisits ,
36
+ ) ;
41
37
} ) ;
42
38
43
- it ( 'should visit equal array element specified number of times' , ( ) => {
44
- const visitingCallback = jest . fn ( ) ;
39
+ it ( 'should visit NOT SORTED array element specified number of times' , ( ) => {
40
+ const expectedNumberOfVisits = 266 ;
45
41
46
- const callbacks = { visitingCallback } ;
47
- const sorter = new BubbleSort ( callbacks ) ;
48
-
49
- const arrayAfterSorting = sorter . sort ( equalArr ) ;
50
-
51
- expect ( arrayAfterSorting ) . toEqual ( equalArr ) ;
52
- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
42
+ SortTester . testAlgorithmTimeComplexity (
43
+ BubbleSort ,
44
+ notSortedArr ,
45
+ expectedNumberOfVisits ,
46
+ ) ;
53
47
} ) ;
54
48
55
- it ( 'should visit reverse sorted array element specified number of times' , ( ) => {
56
- const visitingCallback = jest . fn ( ) ;
57
-
58
- const callbacks = { visitingCallback } ;
59
- const sorter = new BubbleSort ( callbacks ) ;
60
-
61
- const arrayAfterSorting = sorter . sort ( reverseArr ) ;
49
+ it ( 'should visit REVERSE SORTED array element specified number of times' , ( ) => {
50
+ const expectedNumberOfVisits = 380 ;
62
51
63
- expect ( arrayAfterSorting ) . toEqual ( sortedArr ) ;
64
- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
52
+ SortTester . testAlgorithmTimeComplexity (
53
+ BubbleSort ,
54
+ reverseArr ,
55
+ expectedNumberOfVisits ,
56
+ ) ;
65
57
} ) ;
66
58
} ) ;
0 commit comments