diff --git a/arithmetic_analysis/bisection.py b/arithmetic_analysis/bisection.py index 640913a7a..e359cc170 100644 --- a/arithmetic_analysis/bisection.py +++ b/arithmetic_analysis/bisection.py @@ -8,7 +8,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float: 1.0000000149011612 >>> bisection(lambda x: x ** 3 - 1, 2, 1000) Traceback (most recent call last): - ... + ... ValueError: could not find root in given interval. >>> bisection(lambda x: x ** 2 - 4 * x + 3, 0, 2) 1.0 @@ -16,7 +16,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float: 3.0 >>> bisection(lambda x: x ** 2 - 4 * x + 3, 4, 1000) Traceback (most recent call last): - ... + ... ValueError: could not find root in given interval. """ start: float = a diff --git a/arithmetic_analysis/intersection.py b/arithmetic_analysis/intersection.py index 49213dd05..826c0ead0 100644 --- a/arithmetic_analysis/intersection.py +++ b/arithmetic_analysis/intersection.py @@ -10,7 +10,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl 0.9999999999954654 >>> intersection(lambda x: x ** 3 - 1, 5, 5) Traceback (most recent call last): - ... + ... ZeroDivisionError: float division by zero, could not find root >>> intersection(lambda x: x ** 3 - 1, 100, 200) 1.0000000000003888 @@ -24,7 +24,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl 0.0 >>> intersection(math.cos, -math.pi, math.pi) Traceback (most recent call last): - ... + ... ZeroDivisionError: float division by zero, could not find root """ x_n: float = x0 diff --git a/arithmetic_analysis/jacobi_iteration_method.py b/arithmetic_analysis/jacobi_iteration_method.py index 3087309e8..fe506a94a 100644 --- a/arithmetic_analysis/jacobi_iteration_method.py +++ b/arithmetic_analysis/jacobi_iteration_method.py @@ -42,7 +42,7 @@ def jacobi_iteration_method( >>> iterations = 3 >>> jacobi_iteration_method(coefficient, constant, init_val, iterations) Traceback (most recent call last): - ... + ... ValueError: Coefficient matrix dimensions must be nxn but received 2x3 >>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]]) @@ -51,7 +51,7 @@ def jacobi_iteration_method( >>> iterations = 3 >>> jacobi_iteration_method(coefficient, constant, init_val, iterations) Traceback (most recent call last): - ... + ... ValueError: Coefficient and constant matrices dimensions must be nxn and nx1 but received 3x3 and 2x1 @@ -61,7 +61,7 @@ def jacobi_iteration_method( >>> iterations = 3 >>> jacobi_iteration_method(coefficient, constant, init_val, iterations) Traceback (most recent call last): - ... + ... ValueError: Number of initial values must be equal to number of rows in coefficient matrix but received 2 and 3 @@ -71,7 +71,7 @@ def jacobi_iteration_method( >>> iterations = 0 >>> jacobi_iteration_method(coefficient, constant, init_val, iterations) Traceback (most recent call last): - ... + ... ValueError: Iterations must be at least 1 """ @@ -138,7 +138,7 @@ def strictly_diagonally_dominant(table: NDArray[float64]) -> bool: >>> table = np.array([[4, 1, 1, 2], [1, 5, 2, -6], [1, 2, 3, -4]]) >>> strictly_diagonally_dominant(table) Traceback (most recent call last): - ... + ... ValueError: Coefficient matrix is not strictly diagonally dominant """ diff --git a/arithmetic_analysis/lu_decomposition.py b/arithmetic_analysis/lu_decomposition.py index 1e98b9066..217719cf4 100644 --- a/arithmetic_analysis/lu_decomposition.py +++ b/arithmetic_analysis/lu_decomposition.py @@ -31,7 +31,7 @@ def lower_upper_decomposition( >>> matrix = np.array([[2, -2, 1], [0, 1, 2]]) >>> lower_upper_decomposition(matrix) Traceback (most recent call last): - ... + ... ValueError: 'table' has to be of square shaped array but got a 2x3 array: [[ 2 -2 1] [ 0 1 2]] diff --git a/arithmetic_analysis/newton_method.py b/arithmetic_analysis/newton_method.py index c4018a0f2..5127bfcaf 100644 --- a/arithmetic_analysis/newton_method.py +++ b/arithmetic_analysis/newton_method.py @@ -28,7 +28,7 @@ def newton( 1.5707963267948966 >>> newton(math.cos, lambda x: -math.sin(x), 0) Traceback (most recent call last): - ... + ... ZeroDivisionError: Could not find root """ prev_guess = float(starting_int) diff --git a/arithmetic_analysis/newton_raphson_new.py b/arithmetic_analysis/newton_raphson_new.py index 19ea4ce21..dd1d7e092 100644 --- a/arithmetic_analysis/newton_raphson_new.py +++ b/arithmetic_analysis/newton_raphson_new.py @@ -32,7 +32,7 @@ def newton_raphson( 1.2186556186174883e-10 >>> newton_raphson('cos(x)', 0) Traceback (most recent call last): - ... + ... ZeroDivisionError: Could not find root """ diff --git a/backtracking/knight_tour.py b/backtracking/knight_tour.py index 6e9b31bd1..bb650ece3 100644 --- a/backtracking/knight_tour.py +++ b/backtracking/knight_tour.py @@ -78,7 +78,7 @@ def open_knight_tour(n: int) -> list[list[int]]: >>> open_knight_tour(2) Traceback (most recent call last): - ... + ... ValueError: Open Kight Tour cannot be performed on a board of size 2 """ diff --git a/conversions/binary_to_decimal.py b/conversions/binary_to_decimal.py index a7625e475..914a9318c 100644 --- a/conversions/binary_to_decimal.py +++ b/conversions/binary_to_decimal.py @@ -12,15 +12,15 @@ def bin_to_decimal(bin_string: str) -> int: 0 >>> bin_to_decimal("a") Traceback (most recent call last): - ... + ... ValueError: Non-binary value was passed to the function >>> bin_to_decimal("") Traceback (most recent call last): - ... + ... ValueError: Empty string was passed to the function >>> bin_to_decimal("39") Traceback (most recent call last): - ... + ... ValueError: Non-binary value was passed to the function """ bin_string = str(bin_string).strip() diff --git a/conversions/binary_to_hexadecimal.py b/conversions/binary_to_hexadecimal.py index 89f7af696..a3855bb70 100644 --- a/conversions/binary_to_hexadecimal.py +++ b/conversions/binary_to_hexadecimal.py @@ -30,11 +30,11 @@ def bin_to_hexadecimal(binary_str: str) -> str: '-0x1d' >>> bin_to_hexadecimal('a') Traceback (most recent call last): - ... + ... ValueError: Non-binary value was passed to the function >>> bin_to_hexadecimal('') Traceback (most recent call last): - ... + ... ValueError: Empty string was passed to the function """ # Sanitising parameter diff --git a/conversions/binary_to_octal.py b/conversions/binary_to_octal.py index 35ede95b1..82f81e062 100644 --- a/conversions/binary_to_octal.py +++ b/conversions/binary_to_octal.py @@ -9,11 +9,11 @@ The function below will convert any binary string to the octal equivalent. >>> bin_to_octal("") Traceback (most recent call last): -... + ... ValueError: Empty string was passed to the function >>> bin_to_octal("a-1") Traceback (most recent call last): -... + ... ValueError: Non-binary value was passed to the function """ diff --git a/conversions/decimal_to_any.py b/conversions/decimal_to_any.py index 908c89e8f..11a2af294 100644 --- a/conversions/decimal_to_any.py +++ b/conversions/decimal_to_any.py @@ -29,32 +29,32 @@ def decimal_to_any(num: int, base: int) -> str: >>> # negatives will error >>> decimal_to_any(-45, 8) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... ValueError: parameter must be positive int >>> # floats will error >>> decimal_to_any(34.4, 6) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: int() can't convert non-string with explicit base >>> # a float base will error >>> decimal_to_any(5, 2.5) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: 'float' object cannot be interpreted as an integer >>> # a str base will error >>> decimal_to_any(10, '16') # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: 'str' object cannot be interpreted as an integer >>> # a base less than 2 will error >>> decimal_to_any(7, 0) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... ValueError: base must be >= 2 >>> # a base greater than 36 will error >>> decimal_to_any(34, 37) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... ValueError: base must be <= 36 """ if isinstance(num, float): diff --git a/conversions/decimal_to_binary.py b/conversions/decimal_to_binary.py index c21cdbcae..cfda57ca7 100644 --- a/conversions/decimal_to_binary.py +++ b/conversions/decimal_to_binary.py @@ -19,12 +19,12 @@ def decimal_to_binary(num: int) -> str: >>> # other floats will error >>> decimal_to_binary(16.16) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: 'float' object cannot be interpreted as an integer >>> # strings will error as well >>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: 'str' object cannot be interpreted as an integer """ diff --git a/conversions/decimal_to_binary_recursion.py b/conversions/decimal_to_binary_recursion.py index c149ea865..05833ca67 100644 --- a/conversions/decimal_to_binary_recursion.py +++ b/conversions/decimal_to_binary_recursion.py @@ -7,7 +7,7 @@ def binary_recursive(decimal: int) -> str: '1001000' >>> binary_recursive("number") Traceback (most recent call last): - ... + ... ValueError: invalid literal for int() with base 10: 'number' """ decimal = int(decimal) @@ -30,11 +30,11 @@ def main(number: str) -> str: '-0b101000' >>> main(40.8) Traceback (most recent call last): - ... + ... ValueError: Input value is not an integer >>> main("forty") Traceback (most recent call last): - ... + ... ValueError: Input value is not an integer """ number = str(number).strip() diff --git a/conversions/decimal_to_hexadecimal.py b/conversions/decimal_to_hexadecimal.py index 2389c6d1f..5ea48401f 100644 --- a/conversions/decimal_to_hexadecimal.py +++ b/conversions/decimal_to_hexadecimal.py @@ -46,12 +46,12 @@ def decimal_to_hexadecimal(decimal: float) -> str: >>> # other floats will error >>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... AssertionError >>> # strings will error as well >>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... AssertionError >>> # results are the same when compared to Python's default hex function >>> decimal_to_hexadecimal(-256) == hex(-256) diff --git a/conversions/hex_to_bin.py b/conversions/hex_to_bin.py index e358d810b..b872ab5cb 100644 --- a/conversions/hex_to_bin.py +++ b/conversions/hex_to_bin.py @@ -21,11 +21,11 @@ def hex_to_bin(hex_num: str) -> int: -1111111111111111 >>> hex_to_bin("F-f") Traceback (most recent call last): - ... + ... ValueError: Invalid value was passed to the function >>> hex_to_bin("") Traceback (most recent call last): - ... + ... ValueError: No value was passed to the function """ diff --git a/conversions/hexadecimal_to_decimal.py b/conversions/hexadecimal_to_decimal.py index beb1c2c3d..209e4aebb 100644 --- a/conversions/hexadecimal_to_decimal.py +++ b/conversions/hexadecimal_to_decimal.py @@ -18,15 +18,15 @@ def hex_to_decimal(hex_string: str) -> int: -255 >>> hex_to_decimal("F-f") Traceback (most recent call last): - ... + ... ValueError: Non-hexadecimal value was passed to the function >>> hex_to_decimal("") Traceback (most recent call last): - ... + ... ValueError: Empty string was passed to the function >>> hex_to_decimal("12m") Traceback (most recent call last): - ... + ... ValueError: Non-hexadecimal value was passed to the function """ hex_string = hex_string.strip().lower() diff --git a/conversions/octal_to_decimal.py b/conversions/octal_to_decimal.py index 551311e26..7f006f20e 100644 --- a/conversions/octal_to_decimal.py +++ b/conversions/octal_to_decimal.py @@ -4,27 +4,27 @@ def oct_to_decimal(oct_string: str) -> int: >>> oct_to_decimal("") Traceback (most recent call last): - ... + ... ValueError: Empty string was passed to the function >>> oct_to_decimal("-") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("e") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("8") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("-e") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("-8") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("1") 1 @@ -38,7 +38,7 @@ def oct_to_decimal(oct_string: str) -> int: -37 >>> oct_to_decimal("-") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("0") 0 @@ -46,15 +46,15 @@ def oct_to_decimal(oct_string: str) -> int: -2093 >>> oct_to_decimal("2-0Fm") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function >>> oct_to_decimal("") Traceback (most recent call last): - ... + ... ValueError: Empty string was passed to the function >>> oct_to_decimal("19") Traceback (most recent call last): - ... + ... ValueError: Non-octal value was passed to the function """ oct_string = str(oct_string).strip() diff --git a/conversions/temperature_conversions.py b/conversions/temperature_conversions.py index 167c9dc64..e5af46556 100644 --- a/conversions/temperature_conversions.py +++ b/conversions/temperature_conversions.py @@ -23,7 +23,7 @@ def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float: 104.0 >>> celsius_to_fahrenheit("celsius") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'celsius' """ return round((float(celsius) * 9 / 5) + 32, ndigits) @@ -47,7 +47,7 @@ def celsius_to_kelvin(celsius: float, ndigits: int = 2) -> float: 313.15 >>> celsius_to_kelvin("celsius") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'celsius' """ return round(float(celsius) + 273.15, ndigits) @@ -71,7 +71,7 @@ def celsius_to_rankine(celsius: float, ndigits: int = 2) -> float: 563.67 >>> celsius_to_rankine("celsius") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'celsius' """ return round((float(celsius) * 9 / 5) + 491.67, ndigits) @@ -101,7 +101,7 @@ def fahrenheit_to_celsius(fahrenheit: float, ndigits: int = 2) -> float: 37.78 >>> fahrenheit_to_celsius("fahrenheit") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'fahrenheit' """ return round((float(fahrenheit) - 32) * 5 / 9, ndigits) @@ -131,7 +131,7 @@ def fahrenheit_to_kelvin(fahrenheit: float, ndigits: int = 2) -> float: 310.93 >>> fahrenheit_to_kelvin("fahrenheit") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'fahrenheit' """ return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, ndigits) @@ -161,7 +161,7 @@ def fahrenheit_to_rankine(fahrenheit: float, ndigits: int = 2) -> float: 559.67 >>> fahrenheit_to_rankine("fahrenheit") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'fahrenheit' """ return round(float(fahrenheit) + 459.67, ndigits) @@ -185,7 +185,7 @@ def kelvin_to_celsius(kelvin: float, ndigits: int = 2) -> float: 42.35 >>> kelvin_to_celsius("kelvin") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'kelvin' """ return round(float(kelvin) - 273.15, ndigits) @@ -209,7 +209,7 @@ def kelvin_to_fahrenheit(kelvin: float, ndigits: int = 2) -> float: 108.23 >>> kelvin_to_fahrenheit("kelvin") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'kelvin' """ return round(((float(kelvin) - 273.15) * 9 / 5) + 32, ndigits) @@ -233,7 +233,7 @@ def kelvin_to_rankine(kelvin: float, ndigits: int = 2) -> float: 72.0 >>> kelvin_to_rankine("kelvin") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'kelvin' """ return round((float(kelvin) * 9 / 5), ndigits) @@ -257,7 +257,7 @@ def rankine_to_celsius(rankine: float, ndigits: int = 2) -> float: -97.87 >>> rankine_to_celsius("rankine") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'rankine' """ return round((float(rankine) - 491.67) * 5 / 9, ndigits) @@ -277,7 +277,7 @@ def rankine_to_fahrenheit(rankine: float, ndigits: int = 2) -> float: -144.17 >>> rankine_to_fahrenheit("rankine") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'rankine' """ return round(float(rankine) - 459.67, ndigits) @@ -297,7 +297,7 @@ def rankine_to_kelvin(rankine: float, ndigits: int = 2) -> float: 22.22 >>> rankine_to_kelvin("rankine") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'rankine' """ return round((float(rankine) * 5 / 9), ndigits) @@ -316,7 +316,7 @@ def reaumur_to_kelvin(reaumur: float, ndigits: int = 2) -> float: 323.15 >>> reaumur_to_kelvin("reaumur") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'reaumur' """ return round((float(reaumur) * 1.25 + 273.15), ndigits) @@ -335,7 +335,7 @@ def reaumur_to_fahrenheit(reaumur: float, ndigits: int = 2) -> float: 122.0 >>> reaumur_to_fahrenheit("reaumur") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'reaumur' """ return round((float(reaumur) * 2.25 + 32), ndigits) @@ -354,7 +354,7 @@ def reaumur_to_celsius(reaumur: float, ndigits: int = 2) -> float: 50.0 >>> reaumur_to_celsius("reaumur") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'reaumur' """ return round((float(reaumur) * 1.25), ndigits) @@ -373,7 +373,7 @@ def reaumur_to_rankine(reaumur: float, ndigits: int = 2) -> float: 581.67 >>> reaumur_to_rankine("reaumur") Traceback (most recent call last): - ... + ... ValueError: could not convert string to float: 'reaumur' """ return round((float(reaumur) * 2.25 + 32 + 459.67), ndigits) diff --git a/data_structures/binary_tree/binary_search_tree.py b/data_structures/binary_tree/binary_search_tree.py index fc60540a1..fc512944e 100644 --- a/data_structures/binary_tree/binary_search_tree.py +++ b/data_structures/binary_tree/binary_search_tree.py @@ -196,7 +196,7 @@ def binary_search_tree() -> None: 1 4 7 6 3 13 14 10 8 >>> BinarySearchTree().search(6) Traceback (most recent call last): - ... + ... IndexError: Warning: Tree is empty! please use another. """ testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7) diff --git a/data_structures/binary_tree/binary_tree_mirror.py b/data_structures/binary_tree/binary_tree_mirror.py index cdd56e35d..1ef950ad6 100644 --- a/data_structures/binary_tree/binary_tree_mirror.py +++ b/data_structures/binary_tree/binary_tree_mirror.py @@ -21,11 +21,11 @@ def binary_tree_mirror(binary_tree: dict, root: int = 1) -> dict: {1: [3, 2], 2: [5, 4], 3: [7, 6], 4: [11, 10]} >>> binary_tree_mirror({ 1: [2,3], 2: [4,5], 3: [6,7], 4: [10,11]}, 5) Traceback (most recent call last): - ... + ... ValueError: root 5 is not present in the binary_tree >>> binary_tree_mirror({}, 5) Traceback (most recent call last): - ... + ... ValueError: binary tree cannot be empty """ if not binary_tree: diff --git a/data_structures/binary_tree/number_of_possible_binary_trees.py b/data_structures/binary_tree/number_of_possible_binary_trees.py index 1ad8f2ed4..684c518b1 100644 --- a/data_structures/binary_tree/number_of_possible_binary_trees.py +++ b/data_structures/binary_tree/number_of_possible_binary_trees.py @@ -67,7 +67,7 @@ def factorial(n: int) -> int: True >>> factorial(-5) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... ValueError: factorial() not defined for negative values """ if n < 0: diff --git a/data_structures/linked_list/doubly_linked_list.py b/data_structures/linked_list/doubly_linked_list.py index 9e996ef0f..90b6b6eb2 100644 --- a/data_structures/linked_list/doubly_linked_list.py +++ b/data_structures/linked_list/doubly_linked_list.py @@ -64,11 +64,11 @@ class DoublyLinkedList: >>> linked_list = DoublyLinkedList() >>> linked_list.insert_at_nth(-1, 666) Traceback (most recent call last): - .... + .... IndexError: list index out of range >>> linked_list.insert_at_nth(1, 666) Traceback (most recent call last): - .... + .... IndexError: list index out of range >>> linked_list.insert_at_nth(0, 2) >>> linked_list.insert_at_nth(0, 1) @@ -78,7 +78,7 @@ class DoublyLinkedList: '1->2->3->4' >>> linked_list.insert_at_nth(5, 5) Traceback (most recent call last): - .... + .... IndexError: list index out of range """ if not 0 <= index <= len(self): @@ -114,7 +114,7 @@ class DoublyLinkedList: >>> linked_list = DoublyLinkedList() >>> linked_list.delete_at_nth(0) Traceback (most recent call last): - .... + .... IndexError: list index out of range >>> for i in range(0, 5): ... linked_list.insert_at_nth(i, i + 1) @@ -128,7 +128,7 @@ class DoublyLinkedList: '2->4' >>> linked_list.delete_at_nth(2) Traceback (most recent call last): - .... + .... IndexError: list index out of range """ if not 0 <= index <= len(self) - 1: diff --git a/data_structures/linked_list/singly_linked_list.py b/data_structures/linked_list/singly_linked_list.py index 89a05ae81..3e52c7e43 100644 --- a/data_structures/linked_list/singly_linked_list.py +++ b/data_structures/linked_list/singly_linked_list.py @@ -95,11 +95,11 @@ class LinkedList: True >>> linked_list[-10] Traceback (most recent call last): - ... + ... ValueError: list index out of range. >>> linked_list[len(linked_list)] Traceback (most recent call last): - ... + ... ValueError: list index out of range. """ if not 0 <= index < len(self): @@ -122,11 +122,11 @@ class LinkedList: -666 >>> linked_list[-10] = 666 Traceback (most recent call last): - ... + ... ValueError: list index out of range. >>> linked_list[len(linked_list)] = 666 Traceback (most recent call last): - ... + ... ValueError: list index out of range. """ if not 0 <= index < len(self): @@ -233,7 +233,7 @@ class LinkedList: 'third' >>> linked_list.delete_head() Traceback (most recent call last): - ... + ... IndexError: List index out of range. """ return self.delete_nth(0) @@ -260,7 +260,7 @@ class LinkedList: 'first' >>> linked_list.delete_tail() Traceback (most recent call last): - ... + ... IndexError: List index out of range. """ return self.delete_nth(len(self) - 1) @@ -281,11 +281,11 @@ class LinkedList: first->third >>> linked_list.delete_nth(5) # this raises error Traceback (most recent call last): - ... + ... IndexError: List index out of range. >>> linked_list.delete_nth(-1) # this also raises error Traceback (most recent call last): - ... + ... IndexError: List index out of range. """ if not 0 <= index <= len(self) - 1: # test if index is valid diff --git a/data_structures/queue/linked_queue.py b/data_structures/queue/linked_queue.py index 3675da7db..3af97d28e 100644 --- a/data_structures/queue/linked_queue.py +++ b/data_structures/queue/linked_queue.py @@ -96,7 +96,7 @@ class LinkedQueue: >>> queue = LinkedQueue() >>> queue.get() Traceback (most recent call last): - ... + ... IndexError: dequeue from empty queue >>> for i in range(1, 6): ... queue.put(i) @@ -116,7 +116,7 @@ class LinkedQueue: >>> queue = LinkedQueue() >>> queue.get() Traceback (most recent call last): - ... + ... IndexError: dequeue from empty queue >>> queue = LinkedQueue() >>> for i in range(1, 6): diff --git a/data_structures/queue/priority_queue_using_list.py b/data_structures/queue/priority_queue_using_list.py index c5cf26433..f61b5e8e6 100644 --- a/data_structures/queue/priority_queue_using_list.py +++ b/data_structures/queue/priority_queue_using_list.py @@ -58,7 +58,7 @@ class FixedPriorityQueue: 4 >>> fpq.dequeue() Traceback (most recent call last): - ... + ... data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty >>> print(fpq) Priority 0: [] diff --git a/data_structures/stacks/infix_to_postfix_conversion.py b/data_structures/stacks/infix_to_postfix_conversion.py index b812d108e..901744309 100644 --- a/data_structures/stacks/infix_to_postfix_conversion.py +++ b/data_structures/stacks/infix_to_postfix_conversion.py @@ -21,7 +21,7 @@ def infix_to_postfix(expression_str: str) -> str: """ >>> infix_to_postfix("(1*(2+3)+4))") Traceback (most recent call last): - ... + ... ValueError: Mismatched parentheses >>> infix_to_postfix("") '' diff --git a/data_structures/stacks/stack_with_singly_linked_list.py b/data_structures/stacks/stack_with_singly_linked_list.py index 903ae39db..f5ce83b86 100644 --- a/data_structures/stacks/stack_with_singly_linked_list.py +++ b/data_structures/stacks/stack_with_singly_linked_list.py @@ -109,7 +109,7 @@ class LinkedStack(Generic[T]): >>> stack = LinkedStack() >>> stack.pop() Traceback (most recent call last): - ... + ... IndexError: pop from empty stack >>> stack.push("c") >>> stack.push("b") diff --git a/dynamic_programming/longest_common_substring.py b/dynamic_programming/longest_common_substring.py index 84a9f1860..e2f944a5e 100644 --- a/dynamic_programming/longest_common_substring.py +++ b/dynamic_programming/longest_common_substring.py @@ -32,7 +32,7 @@ def longest_common_substring(text1: str, text2: str) -> str: 'Site:Geeks' >>> longest_common_substring(1, 1) Traceback (most recent call last): - ... + ... ValueError: longest_common_substring() takes two strings for inputs """ diff --git a/genetic_algorithm/basic_string.py b/genetic_algorithm/basic_string.py index 3227adf53..5cf8d691b 100644 --- a/genetic_algorithm/basic_string.py +++ b/genetic_algorithm/basic_string.py @@ -32,17 +32,17 @@ def basic(target: str, genes: list[str], debug: bool = True) -> tuple[int, int, >>> genes.remove("e") >>> basic("test", genes) Traceback (most recent call last): - ... + ... ValueError: ['e'] is not in genes list, evolution cannot converge >>> genes.remove("s") >>> basic("test", genes) Traceback (most recent call last): - ... + ... ValueError: ['e', 's'] is not in genes list, evolution cannot converge >>> genes.remove("t") >>> basic("test", genes) Traceback (most recent call last): - ... + ... ValueError: ['e', 's', 't'] is not in genes list, evolution cannot converge """ diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index b9791c860..079731487 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -168,7 +168,7 @@ class Vector: 9.539392014169456 >>> Vector([]).euclidean_length() Traceback (most recent call last): - ... + ... Exception: Vector is empty """ if len(self.__components) == 0: @@ -186,7 +186,7 @@ class Vector: 85.40775111366095 >>> Vector([3, 4, -1]).angle(Vector([2, -1])) Traceback (most recent call last): - ... + ... Exception: invalid operand! """ num = self * other diff --git a/machine_learning/similarity_search.py b/machine_learning/similarity_search.py index ec1b9f9e3..2f5fc46c0 100644 --- a/machine_learning/similarity_search.py +++ b/machine_learning/similarity_search.py @@ -70,7 +70,7 @@ def similarity_search( >>> value_array = np.array([1]) >>> similarity_search(dataset, value_array) Traceback (most recent call last): - ... + ... ValueError: Wrong input data's dimensions... dataset : 2, value_array : 1 2. If data's shapes are different. @@ -80,7 +80,7 @@ def similarity_search( >>> value_array = np.array([[0, 0, 0], [0, 0, 1]]) >>> similarity_search(dataset, value_array) Traceback (most recent call last): - ... + ... ValueError: Wrong input data's shape... dataset : 2, value_array : 3 3. If data types are different. @@ -90,7 +90,7 @@ def similarity_search( >>> value_array = np.array([[0, 0], [0, 1]], dtype=np.int32) >>> similarity_search(dataset, value_array) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): - ... + ... TypeError: Input data have different datatype... dataset : float32, value_array : int32 """ diff --git a/maths/bisection.py b/maths/bisection.py index 93cc2247b..45f26d8d8 100644 --- a/maths/bisection.py +++ b/maths/bisection.py @@ -32,7 +32,7 @@ def bisection(a: float, b: float) -> float: 3.158203125 >>> bisection(2, 3) Traceback (most recent call last): - ... + ... ValueError: Wrong space! """ # Bolzano theory in order to find if there is a root between a and b diff --git a/maths/catalan_number.py b/maths/catalan_number.py index 4a1280a45..85607dc1e 100644 --- a/maths/catalan_number.py +++ b/maths/catalan_number.py @@ -18,15 +18,15 @@ def catalan(number: int) -> int: 14 >>> catalan(0) Traceback (most recent call last): - ... + ... ValueError: Input value of [number=0] must be > 0 >>> catalan(-1) Traceback (most recent call last): - ... + ... ValueError: Input value of [number=-1] must be > 0 >>> catalan(5.0) Traceback (most recent call last): - ... + ... TypeError: Input value of [number=5.0] must be an integer """ diff --git a/maths/fibonacci.py b/maths/fibonacci.py index 07bd6d2ec..e0da66ee5 100644 --- a/maths/fibonacci.py +++ b/maths/fibonacci.py @@ -47,7 +47,7 @@ def fib_iterative(n: int) -> list[int]: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> fib_iterative(-1) Traceback (most recent call last): - ... + ... Exception: n is negative """ if n < 0: @@ -73,7 +73,7 @@ def fib_recursive(n: int) -> list[int]: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> fib_iterative(-1) Traceback (most recent call last): - ... + ... Exception: n is negative """ @@ -105,7 +105,7 @@ def fib_memoization(n: int) -> list[int]: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> fib_iterative(-1) Traceback (most recent call last): - ... + ... Exception: n is negative """ if n < 0: @@ -146,11 +146,11 @@ def fib_binet(n: int) -> list[int]: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] >>> fib_binet(-1) Traceback (most recent call last): - ... + ... Exception: n is negative >>> fib_binet(1475) Traceback (most recent call last): - ... + ... Exception: n is too large """ if n < 0: diff --git a/maths/maclaurin_series.py b/maths/maclaurin_series.py index a2619d4e6..e55839bc1 100644 --- a/maths/maclaurin_series.py +++ b/maths/maclaurin_series.py @@ -26,19 +26,19 @@ def maclaurin_sin(theta: float, accuracy: int = 30) -> float: 0.5440211108893703 >>> maclaurin_sin("10") Traceback (most recent call last): - ... + ... ValueError: maclaurin_sin() requires either an int or float for theta >>> maclaurin_sin(10, -30) Traceback (most recent call last): - ... + ... ValueError: maclaurin_sin() requires a positive int for accuracy >>> maclaurin_sin(10, 30.5) Traceback (most recent call last): - ... + ... ValueError: maclaurin_sin() requires a positive int for accuracy >>> maclaurin_sin(10, "30") Traceback (most recent call last): - ... + ... ValueError: maclaurin_sin() requires a positive int for accuracy """ @@ -78,19 +78,19 @@ def maclaurin_cos(theta: float, accuracy: int = 30) -> float: -0.8390715290764521 >>> maclaurin_cos("10") Traceback (most recent call last): - ... + ... ValueError: maclaurin_cos() requires either an int or float for theta >>> maclaurin_cos(10, -30) Traceback (most recent call last): - ... + ... ValueError: maclaurin_cos() requires a positive int for accuracy >>> maclaurin_cos(10, 30.5) Traceback (most recent call last): - ... + ... ValueError: maclaurin_cos() requires a positive int for accuracy >>> maclaurin_cos(10, "30") Traceback (most recent call last): - ... + ... ValueError: maclaurin_cos() requires a positive int for accuracy """ diff --git a/maths/proth_number.py b/maths/proth_number.py index 6b1519024..ce911473a 100644 --- a/maths/proth_number.py +++ b/maths/proth_number.py @@ -16,15 +16,15 @@ def proth(number: int) -> int: 25 >>> proth(0) Traceback (most recent call last): - ... + ... ValueError: Input value of [number=0] must be > 0 >>> proth(-1) Traceback (most recent call last): - ... + ... ValueError: Input value of [number=-1] must be > 0 >>> proth(6.0) Traceback (most recent call last): - ... + ... TypeError: Input value of [number=6.0] must be an integer """ diff --git a/maths/sylvester_sequence.py b/maths/sylvester_sequence.py index 0cd99affe..114c9dd58 100644 --- a/maths/sylvester_sequence.py +++ b/maths/sylvester_sequence.py @@ -18,12 +18,12 @@ def sylvester(number: int) -> int: >>> sylvester(-1) Traceback (most recent call last): - ... + ... ValueError: The input value of [n=-1] has to be > 0 >>> sylvester(8.0) Traceback (most recent call last): - ... + ... AssertionError: The input value of [n=8.0] is not an integer """ assert isinstance(number, int), f"The input value of [n={number}] is not an integer" diff --git a/maths/zellers_congruence.py b/maths/zellers_congruence.py index 2d4a22a0a..624bbfe10 100644 --- a/maths/zellers_congruence.py +++ b/maths/zellers_congruence.py @@ -14,11 +14,11 @@ def zeller(date_input: str) -> str: Validate out of range month >>> zeller('13-31-2010') Traceback (most recent call last): - ... + ... ValueError: Month must be between 1 - 12 >>> zeller('.2-31-2010') Traceback (most recent call last): - ... + ... ValueError: invalid literal for int() with base 10: '.2' Validate out of range date: diff --git a/neural_network/perceptron.py b/neural_network/perceptron.py index f04c81424..487842067 100644 --- a/neural_network/perceptron.py +++ b/neural_network/perceptron.py @@ -29,15 +29,15 @@ class Perceptron: >>> p = Perceptron([], (0, 1, 2)) Traceback (most recent call last): - ... + ... ValueError: Sample data can not be empty >>> p = Perceptron(([0], 1, 2), []) Traceback (most recent call last): - ... + ... ValueError: Target data can not be empty >>> p = Perceptron(([0], 1, 2), (0, 1)) Traceback (most recent call last): - ... + ... ValueError: Sample data and Target data do not have matching lengths """ self.sample = sample diff --git a/project_euler/problem_004/sol1.py b/project_euler/problem_004/sol1.py index db6133a1a..b1e229289 100644 --- a/project_euler/problem_004/sol1.py +++ b/project_euler/problem_004/sol1.py @@ -26,7 +26,7 @@ def solution(n: int = 998001) -> int: 39893 >>> solution(10000) Traceback (most recent call last): - ... + ... ValueError: That number is larger than our acceptable range. """ diff --git a/project_euler/problem_010/sol3.py b/project_euler/problem_010/sol3.py index 72e2894df..60abbd571 100644 --- a/project_euler/problem_010/sol3.py +++ b/project_euler/problem_010/sol3.py @@ -30,15 +30,15 @@ def solution(n: int = 2000000) -> int: 10 >>> solution(7.1) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: 'float' object cannot be interpreted as an integer >>> solution(-7) # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... IndexError: list assignment index out of range >>> solution("seven") # doctest: +ELLIPSIS Traceback (most recent call last): - ... + ... TypeError: can only concatenate str (not "int") to str """ diff --git a/searches/interpolation_search.py b/searches/interpolation_search.py index f4fa8e120..35e6bc506 100644 --- a/searches/interpolation_search.py +++ b/searches/interpolation_search.py @@ -101,7 +101,7 @@ def __assert_sorted(collection): True >>> __assert_sorted([10, -1, 5]) Traceback (most recent call last): - ... + ... ValueError: Collection must be ascending sorted """ if collection != sorted(collection): diff --git a/sorts/bead_sort.py b/sorts/bead_sort.py index d22367c52..e51173643 100644 --- a/sorts/bead_sort.py +++ b/sorts/bead_sort.py @@ -20,12 +20,12 @@ def bead_sort(sequence: list) -> list: >>> bead_sort([1, .9, 0.0, 0, -1, -.9]) Traceback (most recent call last): - ... + ... TypeError: Sequence must be list of non-negative integers >>> bead_sort("Hello world") Traceback (most recent call last): - ... + ... TypeError: Sequence must be list of non-negative integers """ if any(not isinstance(x, int) or x < 0 for x in sequence): diff --git a/sorts/msd_radix_sort.py b/sorts/msd_radix_sort.py index 7430fc5a6..84460e47b 100644 --- a/sorts/msd_radix_sort.py +++ b/sorts/msd_radix_sort.py @@ -23,7 +23,7 @@ def msd_radix_sort(list_of_ints: list[int]) -> list[int]: [1, 45, 1209, 540402, 834598] >>> msd_radix_sort([-1, 34, 45]) Traceback (most recent call last): - ... + ... ValueError: All numbers must be positive """ if not list_of_ints: @@ -93,7 +93,7 @@ def msd_radix_sort_inplace(list_of_ints: list[int]): >>> lst = [-1, 34, 23, 4, -42] >>> msd_radix_sort_inplace(lst) Traceback (most recent call last): - ... + ... ValueError: All numbers must be positive """ diff --git a/strings/barcode_validator.py b/strings/barcode_validator.py index 2e1ea8703..e050cd337 100644 --- a/strings/barcode_validator.py +++ b/strings/barcode_validator.py @@ -47,7 +47,7 @@ def is_valid(barcode: int) -> bool: False >>> is_valid(dwefgiweuf) Traceback (most recent call last): - ... + ... NameError: name 'dwefgiweuf' is not defined """ return len(str(barcode)) == 13 and get_check_digit(barcode) == barcode % 10 @@ -61,7 +61,7 @@ def get_barcode(barcode: str) -> int: 8718452538119 >>> get_barcode("dwefgiweuf") Traceback (most recent call last): - ... + ... ValueError: Barcode 'dwefgiweuf' has alphabetic characters. """ if str(barcode).isalpha(): diff --git a/strings/join.py b/strings/join.py index c17ddd144..739856c1a 100644 --- a/strings/join.py +++ b/strings/join.py @@ -15,7 +15,7 @@ def join(separator: str, separated: list[str]) -> str: 'You are amazing!' >>> join("#", ["a", "b", "c", 1]) Traceback (most recent call last): - ... + ... Exception: join() accepts only strings to be joined """ joined = ""