説明なし

test_sortAlgo.py 2.7KB

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