aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-18 16:54:00 +0200
committerEgor Tensin <egor@tensin.name>2026-06-18 16:54:00 +0200
commitc663acc4ed8e7d2a9e4389a3e8f790d60a070a0c (patch)
treed37fca42651fad8b0c55984a8796881ce8243777 /algorithms
parentadd .git-blame-ignore-revs (diff)
downloadsorting-algorithms-c663acc4ed8e7d2a9e4389a3e8f790d60a070a0c.tar.gz
sorting-algorithms-c663acc4ed8e7d2a9e4389a3e8f790d60a070a0c.zip
use format strings
Diffstat (limited to 'algorithms')
-rw-r--r--algorithms/algorithm.py1
-rw-r--r--algorithms/input_kind.py2
-rw-r--r--algorithms/params.py6
-rwxr-xr-xalgorithms/scripts/plot.py8
-rwxr-xr-xalgorithms/scripts/test.py6
5 files changed, 11 insertions, 12 deletions
diff --git a/algorithms/algorithm.py b/algorithms/algorithm.py
index 55d4929..ebbd559 100644
--- a/algorithms/algorithm.py
+++ b/algorithms/algorithm.py
@@ -14,7 +14,6 @@ class Algorithm:
@staticmethod
def gen_input(n, case=input_kind.InputKind.AVERAGE):
- # raise NotImplementedError('input generation is not defined for a generic algorithm')
return input_kind.gen_input_for_sorting(n, case)
diff --git a/algorithms/input_kind.py b/algorithms/input_kind.py
index b91d298..68a93d8 100644
--- a/algorithms/input_kind.py
+++ b/algorithms/input_kind.py
@@ -30,4 +30,4 @@ def gen_input_for_sorting(n, case=InputKind.AVERAGE):
return _gen_input_from(sample(range(n), n))
if case is InputKind.WORST:
return _gen_input_from(range(n - 1, -1, -1))
- raise NotImplementedError("invalid input kind: " + str(case))
+ raise NotImplementedError(f"invalid input kind: {case}")
diff --git a/algorithms/params.py b/algorithms/params.py
index 818ca47..fb5af6f 100644
--- a/algorithms/params.py
+++ b/algorithms/params.py
@@ -24,7 +24,7 @@ class TimeUnits(Enum):
return 1000.0
if self is TimeUnits.MICROSECONDS:
return 1000000.0
- raise NotImplementedError("invalid time units: " + str(self))
+ raise NotImplementedError(f"invalid time units: {self}")
def __str__(self):
return self.value
@@ -109,10 +109,10 @@ class AlgorithmParameters:
@staticmethod
def _format_plot_ylabel(units):
- return "Running time ({})".format(units)
+ return f"Running time ({units})"
def _format_plot_title(self):
- return "{}, {} case".format(self.algorithm.display_name, self.input_kind)
+ return f"{self.algorithm.display_name}, {self.input_kind} case"
def _format_plot_suptitle(self):
return self.algorithm.display_name
diff --git a/algorithms/scripts/plot.py b/algorithms/scripts/plot.py
index 25a87f7..61eeab1 100755
--- a/algorithms/scripts/plot.py
+++ b/algorithms/scripts/plot.py
@@ -40,7 +40,7 @@ def _parse_non_negative_integer(s):
try:
n = int(s)
except ValueError:
- raise argparse.ArgumentTypeError("must be a non-negative integer: " + str(s))
+ raise argparse.ArgumentTypeError(f"must be a non-negative integer: {s}")
if n < 0:
raise argparse.ArgumentTypeError("must be a non-negative integer")
return n
@@ -50,7 +50,7 @@ def _parse_positive_integer(s):
try:
n = int(s)
except ValueError:
- raise argparse.ArgumentTypeError("must be a positive integer: " + str(s))
+ raise argparse.ArgumentTypeError(f"must be a positive integer: {s}")
if n < 1:
raise argparse.ArgumentTypeError("must be a positive integer")
return n
@@ -60,11 +60,11 @@ def _parse_input_kind(s):
try:
return InputKind(s)
except ValueError:
- raise argparse.ArgumentTypeError("invalid input kind: " + str(s))
+ raise argparse.ArgumentTypeError(f"invalid input kind: {s}")
def _format_algorithm(codename):
- return "* {}: {}".format(codename, registry.get(codename).display_name)
+ return "* {codename}: {registry.get(codename).display_name}"
def _format_available_algorithms():
diff --git a/algorithms/scripts/test.py b/algorithms/scripts/test.py
index 52acc34..7fd7c68 100755
--- a/algorithms/scripts/test.py
+++ b/algorithms/scripts/test.py
@@ -30,7 +30,7 @@ def _parse_non_negative_integer(s):
try:
n = int(s)
except ValueError:
- raise argparse.ArgumentTypeError("must be a non-negative integer: " + str(s))
+ raise argparse.ArgumentTypeError(f"must be a non-negative integer: {s}")
if n < 0:
raise argparse.ArgumentTypeError("must be a non-negative integer")
return n
@@ -40,11 +40,11 @@ def _parse_input_kind(s):
try:
return InputKind(s)
except ValueError:
- raise argparse.ArgumentTypeError("invalid input kind: " + str(s))
+ raise argparse.ArgumentTypeError(f"invalid input kind: {s}")
def _format_algorithm(codename):
- return "* {}: {}".format(codename, registry.get(codename).display_name)
+ return "* {codename}: {registry.get(codename).display_name}"
def _format_available_algorithms():