Skip to content

Commit 2f70414

Browse files
committed
improve test_runer.py add requirements.txt
1 parent b3bb6ae commit 2f70414

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[Sorting Algorithms](#sorting-algorithms)
22

3+
# pre requirements
4+
``` bash
5+
pip install -r requirements.txt
6+
```
37

48
# Sorting Algorithms
59
- [Bubble sort](#bubble-sort)

Sorting_Algorithms/src/7__Linked_List_Merge_Sort.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ void Forward_list::print()
4848
std::cout << std::endl;
4949
}
5050

51-
void Forward_list::MergeSort()
52-
{
53-
MergeSorthelper(m_head);
54-
}
5551

5652
Forward_list::Node* Forward_list::SortedMerge(Node* first, Node* second)
5753
{
@@ -114,4 +110,9 @@ void Forward_list::MergeSorthelper(Node*& head)
114110
MergeSorthelper(secondHalf);
115111

116112
head = SortedMerge(firstHalf, secondHalf);
113+
}
114+
115+
void Forward_list::MergeSort()
116+
{
117+
MergeSorthelper(m_head);
117118
}

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rich==10.12.0
2+
pyfiglet==0.8.post1
3+

test_runer.py

+27-18
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import os
55
import signal
66
from types import FrameType
7-
from typing import List, Union, Callable
7+
from typing import List, Union
88
from rich.console import Console
9+
from pyfiglet import figlet_format
910

1011
console: Console = Console()
1112

@@ -84,59 +85,67 @@ def exit_gracefully(signal: signal.Signals, frame: Union[FrameType, None]) -> No
8485

8586

8687
def main() -> None:
87-
options: dict[str, Union[str, Callable[[], None]]] = {
88+
options: dict[str, str] = {
8889
'1': 'bubble_sort',
8990
'2': 'insertion_sort',
9091
'3': 'selection_sort',
92+
'4': 'quick_sort',
93+
'5': 'merge_sort',
94+
'6': 'counting_sort',
95+
'7': 'Linked_List_Merge_Sort',
96+
'8': 'Finish testing',
97+
}
98+
99+
quick_sort_options: dict[str, str] = {
91100
'A': 'first',
92101
'B': 'last',
93102
'C': 'medianOfThree',
94103
'D': 'Random',
95-
'5': 'merge_sort',
96-
'6': 'counting_sort',
97-
'7': 'Linked_List_Merge_Sort',
98-
'8': lambda: console.print("Ending the loop.", style="bold green")
99104
}
100105

101106
signal.signal(signal.SIGINT, exit_gracefully)
102107

108+
text: str = "Sorting Algorithms"
109+
ascii_art = figlet_format(text, font="slant")
110+
console.print(ascii_art, style="bold cyan")
111+
103112
while True:
104-
console.print("Enter the number corresponding to the sorting algorithm you want to test:")
105-
113+
console.print("Enter the number corresponding to the sorting algorithm you want to test:\n", style="bold #00AAA6 u")
106114
for key, value in options.items():
107-
if key.isdigit() and int(key) >= 1 and int(key) <= 7:
115+
if key == '8':
116+
console.print(f"[green bold]{key}.[/green bold] {value}", style="b red")
117+
else:
108118
console.print(f"[green bold]{key}.[/green bold] {value}")
119+
109120

110-
console.print("[green bold]8.[/green bold] Finish testing", style="red")
111-
console.print(" Choose from [green bold](1 - 6)[green bold]")
121+
console.print(f" Choose from [green bold](1 - {len(options)})[green bold]")
112122
console.print("\n" + "-" * 40 + "\n", style="bold cyan")
113123

114124
choice: str = input()
115125

116126
if choice == '4':
117127
while True:
118128
console.print("Choose the version of Quick Sort:")
119-
console.print("[green bold]A.[/green bold] First Element Pivot")
120-
console.print("[green bold]B.[/green bold] Last Element Pivot")
121-
console.print("[green bold]C.[/green bold] Median of Three Pivot")
122-
console.print("[green bold]D.[/green bold] Random Pivot")
129+
130+
for key, value in quick_sort_options.items():
131+
console.print(f"[green bold]{key}.[/green bold] {value}", style="")
132+
123133
console.print("[green bold]E.[/green bold] end Quick Sort chise\n", style="red")
124-
125134
quick_sort_choice: str = input("Enter your choice (a/A/ b/B c/C d/D e/E): ").upper()
126135

127136
if quick_sort_choice in ['A', 'B', 'C', 'D', 'E']:
128137
if(quick_sort_choice == 'E'):
129138
break
130139
else:
131-
pivot_name: str = options[quick_sort_choice]
140+
pivot_name: str = quick_sort_options[quick_sort_choice]
132141
test_Quick_Sort(quick_sort_choice, pivot_name)
133142

134143
else:
135144
console.print("Invalid choice. Please enter A, B, C, or D.", style="bold red")
136145
else:
137146
if choice in options:
138147
if choice == '8':
139-
options[choice]()
148+
console.print("Ending the loop.", style="bold green")
140149
cleanup_test_files(TEST_FILES)
141150
break
142151
else:

0 commit comments

Comments
 (0)