|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | # -*- coding: utf-8 -*-
|
3 | 3 |
|
4 |
| -'''测试函数 ''' |
| 4 | +"""测试函数 """ |
5 | 5 | import random
|
6 | 6 | import time
|
7 | 7 |
|
8 |
| -from Sort.BubbleSort import bubble_sort, bubble_sort_flag |
9 |
| -from Sort.CountSort import count_sort |
10 |
| -from Sort.HeapSort import heap_sort |
11 |
| -from Sort.InsertSort import insert_sort |
12 |
| -from Sort.MargeSort import merge_sort |
13 |
| -from Sort.QuickSort import quick_sort, qsort |
14 |
| -from Sort.SelectionSort import selection_sort |
15 |
| -from Sort.ShellSort import shell_sort |
| 8 | +from Sort.bubble_sort import bubble_sort, bubble_sort_flag |
| 9 | +from Sort.count_sort import count_sort |
| 10 | +from Sort.heap_sort import heap_sort |
| 11 | +from Sort.insert_sort import insert_sort |
| 12 | +from Sort.marge_sort import merge_sort |
| 13 | +from Sort.quick_sort import quick_sort, qsort |
| 14 | +from Sort.selection_sort import selection_sort |
| 15 | +from Sort.shell_sort import shell_sort |
16 | 16 | import sys
|
17 | 17 |
|
18 | 18 | # 开挂 防止栈溢出
|
19 | 19 | sys.setrecursionlimit(99999)
|
20 | 20 |
|
21 |
| -#整数数列 |
| 21 | +# 整数数列 |
22 | 22 | # L = [int(random.uniform(0, 5000)) for x in range(1000)]
|
23 | 23 | # 浮点数列
|
24 | 24 | L = [random.uniform(0, 5000) for x in range(1000)]
|
25 |
| - |
26 | 25 | current = list(L)
|
27 | 26 | current.sort()
|
28 | 27 |
|
29 |
| -def compile(fun): |
| 28 | + |
| 29 | +def sort_test(fun): |
30 | 30 | l = list(L)
|
31 |
| - start=time.time() |
| 31 | + start = time.time() |
32 | 32 | res = fun(l)
|
33 | 33 | over = time.time()
|
34 |
| - print('time:'+str(over-start),current == res, fun.__name__) |
35 |
| - |
36 |
| - |
37 |
| -compile(selection_sort) |
38 |
| -compile(bubble_sort) |
39 |
| -compile(bubble_sort_flag) |
40 |
| -compile(insert_sort) |
41 |
| -compile(merge_sort) |
42 |
| -compile(shell_sort) |
43 |
| -compile(quick_sort) |
44 |
| -compile(qsort) |
45 |
| -compile(heap_sort) |
46 |
| -if isinstance(L[0],int): |
47 |
| - compile(count_sort) |
| 34 | + print('time:' + str(over - start), current == res, fun.__name__) |
| 35 | + |
| 36 | + |
| 37 | +sort_test(selection_sort) |
| 38 | +sort_test(bubble_sort) |
| 39 | +sort_test(bubble_sort_flag) |
| 40 | +sort_test(insert_sort) |
| 41 | +sort_test(merge_sort) |
| 42 | +sort_test(shell_sort) |
| 43 | +sort_test(quick_sort) |
| 44 | +sort_test(qsort) |
| 45 | +sort_test(heap_sort) |
| 46 | +if isinstance(L[0], int): |
| 47 | + sort_test(count_sort) |
0 commit comments