Skip to content

Commit 92a4fd3

Browse files
committed
Setup Algorithm.algorithm() as an abstract class
1 parent 170bf88 commit 92a4fd3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Sorting Visualizer/algorithms.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import time
22
import random
3+
from abc import ABCMeta, abstractmethod
34

4-
class Algorithm:
5+
class Algorithm(metaclass=ABCMeta):
56
def __init__(self, name):
67
self.array = random.sample(range(512), 512) # Random array of size 512
78
self.name = name # Get name of the variable
@@ -15,6 +16,10 @@ def run(self): # Start the timer and run the algorithm
1516
self.algorithm()
1617
time_elapsed = time.time() - self.start_time
1718
return self.array, time_elapsed
19+
20+
@abstractmethod
21+
def algorithm(self):
22+
raise TypeError(f"Algorithm.algorithm() has not been overwritten.")
1823

1924

2025
class SelectionSort(Algorithm):

0 commit comments

Comments
 (0)