@@ -16,51 +16,43 @@ describe('BubbleSort', () => {
1616 SortTester . testSortWithCustomComparator ( BubbleSort ) ;
1717 } ) ;
1818
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+ ) ;
2927 } ) ;
3028
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 ;
3831
39- expect ( arrayAfterSorting ) . toEqual ( sortedArr ) ;
40- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
32+ SortTester . testAlgorithmTimeComplexity (
33+ BubbleSort ,
34+ sortedArr ,
35+ expectedNumberOfVisits ,
36+ ) ;
4137 } ) ;
4238
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 ;
4541
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+ ) ;
5347 } ) ;
5448
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 ;
6251
63- expect ( arrayAfterSorting ) . toEqual ( sortedArr ) ;
64- expect ( visitingCallback ) . toHaveBeenCalledTimes ( 19 ) ;
52+ SortTester . testAlgorithmTimeComplexity (
53+ BubbleSort ,
54+ reverseArr ,
55+ expectedNumberOfVisits ,
56+ ) ;
6557 } ) ;
6658} ) ;
0 commit comments