File tree Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Expand file tree Collapse file tree 4 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 4
4
#include <CUnit/CUnit.h>
5
5
#include <stdlib.h>
6
6
7
- static void test_insertion_sort () {
7
+ static void test_heap_sort () {
8
8
int len = 100 ;
9
9
int nums [len ];
10
10
for (int i = 0 ; i < len ; i ++ ) {
@@ -19,7 +19,7 @@ static void test_insertion_sort() {
19
19
CU_ErrorCode add_test_heap_sort () {
20
20
CU_pSuite pSuite = CU_add_suite ("heap_sort" , NULL , NULL );
21
21
CHECK_CU_GLOBAL ();
22
- CU_ADD_TEST (pSuite , test_insertion_sort );
22
+ CU_ADD_TEST (pSuite , test_heap_sort );
23
23
CHECK_CU_GLOBAL ();
24
24
return CUE_SUCCESS ;
25
25
}
Original file line number Diff line number Diff line change
1
+ #include "quick_sort.h"
2
+ #include "test_quick_sort.h"
3
+ #include "../utils.h"
4
+ #include <CUnit/CUnit.h>
5
+ #include <stdlib.h>
6
+
7
+ static void test_quick_sort () {
8
+ int len = 100 ;
9
+ int nums [len ];
10
+ for (int i = 0 ; i < len ; i ++ ) {
11
+ nums [i ] = rand ();
12
+ }
13
+ quick_sort (nums , 0 , len );
14
+ for (int i = 1 ; i < len ; i ++ ) {
15
+ CU_ASSERT (nums [i - 1 ] <= nums [i ]);
16
+ }
17
+ }
18
+
19
+ CU_ErrorCode add_test_quick_sort () {
20
+ CU_pSuite pSuite = CU_add_suite ("quick_sort" , NULL , NULL );
21
+ CHECK_CU_GLOBAL ();
22
+ CU_ADD_TEST (pSuite , test_quick_sort );
23
+ CHECK_CU_GLOBAL ();
24
+ return CUE_SUCCESS ;
25
+ }
Original file line number Diff line number Diff line change
1
+ #ifndef TEST_QUICK_SORT_H
2
+ #define TEST_QUICK_SORT_H
3
+
4
+ #include <CUnit/CUnit.h>
5
+
6
+ CU_ErrorCode add_test_quick_sort ();
7
+
8
+ #endif
Original file line number Diff line number Diff line change 2
2
#include "chap02/test_merge_sort.h"
3
3
#include "chap04/test_maximum_subarray.h"
4
4
#include "chap06/test_heap_sort.h"
5
+ #include "chap07/test_quick_sort.h"
5
6
#include "chap15/test_optimal_binary_search_tree.h"
6
7
#include "utils.h"
7
8
#include <stdio.h>
@@ -27,6 +28,7 @@ int main() {
27
28
CHECK_CU_RETURN (add_test_merge_sort ());
28
29
CHECK_CU_RETURN (add_test_maximum_subarray ());
29
30
CHECK_CU_RETURN (add_test_heap_sort ());
31
+ CHECK_CU_RETURN (add_test_quick_sort ());
30
32
CHECK_CU_RETURN (add_test_obst ());
31
33
32
34
//使用console控制交互界面的函数入口
You can’t perform that action at this time.
0 commit comments