|
@@ -1,14 +1,69 @@
|
1
|
|
-from email import utils
|
|
1
|
+import sorting
|
|
2
|
+from random import randint
|
2
|
3
|
|
|
4
|
+DEBUG_OUTPUT = True
|
3
|
5
|
|
4
|
|
-from utils import qsortUtils
|
5
|
|
-from random import randint
|
|
6
|
+def test_mergeSort(pruebas):
|
|
7
|
+ FAIL = False
|
|
8
|
+
|
|
9
|
+ print("\nProbando MergeSort")
|
|
10
|
+
|
|
11
|
+ for nombre, lista in pruebas.items():
|
|
12
|
+ if sorting.mergeSort(lista) == sorted(lista):
|
|
13
|
+ print(f"{nombre}: " + "Pass")
|
|
14
|
+ else:
|
|
15
|
+ print(f"{nombre}: " + "Fail")
|
|
16
|
+ FAIL = True
|
|
17
|
+
|
|
18
|
+ if FAIL == True and DEBUG_OUTPUT == True:
|
|
19
|
+ print("\n Test FAIL OUTPUT for MergeSort")
|
|
20
|
+ for nombre, lista in pruebas.items():
|
|
21
|
+ print(f"{nombre}: Obtained -> {sorting.mergeSort(lista)} | Expected -> {sorted(lista)}")
|
|
22
|
+
|
|
23
|
+def test_quickSort(pruebas):
|
|
24
|
+ FAIL = False
|
|
25
|
+
|
|
26
|
+ print("\nProbando QuickSort")
|
|
27
|
+
|
|
28
|
+ for nombre, lista in pruebas.items():
|
|
29
|
+ if sorting.quickSort(lista) == sorted(lista):
|
|
30
|
+ print(f"{nombre}: " + "Pass")
|
|
31
|
+ else:
|
|
32
|
+ print(f"{nombre}: " + "Fail")
|
|
33
|
+ FAIL = True
|
|
34
|
+
|
|
35
|
+ if FAIL == True and DEBUG_OUTPUT == True:
|
|
36
|
+ print("\n Test FAIL OUTPUT for QuickSort")
|
|
37
|
+ for nombre, lista in pruebas.items():
|
|
38
|
+ print(f"{nombre}: Obtained -> {sorting.quickSort(lista)} | Expected -> {sorted(lista)}")
|
|
39
|
+
|
|
40
|
+def test_shellSort(pruebas):
|
|
41
|
+ FAIL = False
|
|
42
|
+
|
|
43
|
+ print("\nProbando ShellSort")
|
|
44
|
+
|
|
45
|
+ for nombre, lista in pruebas.items():
|
|
46
|
+ if sorting.shellSort(lista) == sorted(lista):
|
|
47
|
+ print(f"{nombre}: " + "Pass")
|
|
48
|
+ else:
|
|
49
|
+ print(f"{nombre}: " + "Fail")
|
|
50
|
+ FAIL = True
|
6
|
51
|
|
7
|
|
-enteros = [0,7,3,1,4,5,2]
|
8
|
|
-negativos = [8,-1,3,2,-4,9]
|
9
|
|
-aleatoria =[randint(-49,50) for r in range(10)]
|
|
52
|
+ if FAIL == True and DEBUG_OUTPUT == True:
|
|
53
|
+ print("\n Test FAIL OUTPUT for ShellSort")
|
|
54
|
+ for nombre, lista in pruebas.items():
|
|
55
|
+ print(f"{nombre}: Obtained -> {sorting.shellSort(lista)} | Expected -> {sorted(lista)}")
|
10
|
56
|
|
11
|
|
-print(qsortUtils.qSort(enteros,0,len(enteros)-1) == enteros.sort())
|
12
|
|
-print(qsortUtils.qSort(negativos,0,len(negativos)-1) == negativos.sort())
|
13
|
|
-print(qsortUtils.qSort(aleatoria,0,len(aleatoria)-1) == aleatoria.sort())
|
|
57
|
+def main():
|
|
58
|
+ PRUEBAS = {"Enteros":[0,7,3,1,4,5,2],
|
|
59
|
+ "Negativos":[8,-1,3,2,-4,9],
|
|
60
|
+ "Aleatorios":[randint(-49,50) for r in range(10)],
|
|
61
|
+ "Vacia":[],
|
|
62
|
+ "Ordenada":[1,2,3,4,5,6,7]}
|
|
63
|
+
|
|
64
|
+ test_mergeSort(PRUEBAS)
|
|
65
|
+ test_quickSort(PRUEBAS)
|
|
66
|
+ test_shellSort(PRUEBAS)
|
14
|
67
|
|
|
68
|
+if __name__ == "__main__":
|
|
69
|
+ main()
|