refactor: Indent ... for visual purposes (#7744)

This commit is contained in:
Caeden Perelli-Harris 2022-10-27 18:42:30 +01:00 committed by GitHub
parent e8915097c4
commit 9bba42eca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 134 additions and 134 deletions

View File

@ -8,7 +8,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
1.0000000149011612 1.0000000149011612
>>> bisection(lambda x: x ** 3 - 1, 2, 1000) >>> bisection(lambda x: x ** 3 - 1, 2, 1000)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not find root in given interval. ValueError: could not find root in given interval.
>>> bisection(lambda x: x ** 2 - 4 * x + 3, 0, 2) >>> bisection(lambda x: x ** 2 - 4 * x + 3, 0, 2)
1.0 1.0
@ -16,7 +16,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
3.0 3.0
>>> bisection(lambda x: x ** 2 - 4 * x + 3, 4, 1000) >>> bisection(lambda x: x ** 2 - 4 * x + 3, 4, 1000)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not find root in given interval. ValueError: could not find root in given interval.
""" """
start: float = a start: float = a

View File

@ -10,7 +10,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl
0.9999999999954654 0.9999999999954654
>>> intersection(lambda x: x ** 3 - 1, 5, 5) >>> intersection(lambda x: x ** 3 - 1, 5, 5)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ZeroDivisionError: float division by zero, could not find root ZeroDivisionError: float division by zero, could not find root
>>> intersection(lambda x: x ** 3 - 1, 100, 200) >>> intersection(lambda x: x ** 3 - 1, 100, 200)
1.0000000000003888 1.0000000000003888
@ -24,7 +24,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl
0.0 0.0
>>> intersection(math.cos, -math.pi, math.pi) >>> intersection(math.cos, -math.pi, math.pi)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ZeroDivisionError: float division by zero, could not find root ZeroDivisionError: float division by zero, could not find root
""" """
x_n: float = x0 x_n: float = x0

View File

@ -42,7 +42,7 @@ def jacobi_iteration_method(
>>> iterations = 3 >>> iterations = 3
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations) >>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Coefficient matrix dimensions must be nxn but received 2x3 ValueError: Coefficient matrix dimensions must be nxn but received 2x3
>>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]]) >>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]])
@ -51,7 +51,7 @@ def jacobi_iteration_method(
>>> iterations = 3 >>> iterations = 3
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations) >>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Coefficient and constant matrices dimensions must be nxn and nx1 but ValueError: Coefficient and constant matrices dimensions must be nxn and nx1 but
received 3x3 and 2x1 received 3x3 and 2x1
@ -61,7 +61,7 @@ def jacobi_iteration_method(
>>> iterations = 3 >>> iterations = 3
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations) >>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Number of initial values must be equal to number of rows in coefficient ValueError: Number of initial values must be equal to number of rows in coefficient
matrix but received 2 and 3 matrix but received 2 and 3
@ -71,7 +71,7 @@ def jacobi_iteration_method(
>>> iterations = 0 >>> iterations = 0
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations) >>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Iterations must be at least 1 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]]) >>> table = np.array([[4, 1, 1, 2], [1, 5, 2, -6], [1, 2, 3, -4]])
>>> strictly_diagonally_dominant(table) >>> strictly_diagonally_dominant(table)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Coefficient matrix is not strictly diagonally dominant ValueError: Coefficient matrix is not strictly diagonally dominant
""" """

View File

@ -31,7 +31,7 @@ def lower_upper_decomposition(
>>> matrix = np.array([[2, -2, 1], [0, 1, 2]]) >>> matrix = np.array([[2, -2, 1], [0, 1, 2]])
>>> lower_upper_decomposition(matrix) >>> lower_upper_decomposition(matrix)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: 'table' has to be of square shaped array but got a 2x3 array: ValueError: 'table' has to be of square shaped array but got a 2x3 array:
[[ 2 -2 1] [[ 2 -2 1]
[ 0 1 2]] [ 0 1 2]]

View File

@ -28,7 +28,7 @@ def newton(
1.5707963267948966 1.5707963267948966
>>> newton(math.cos, lambda x: -math.sin(x), 0) >>> newton(math.cos, lambda x: -math.sin(x), 0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ZeroDivisionError: Could not find root ZeroDivisionError: Could not find root
""" """
prev_guess = float(starting_int) prev_guess = float(starting_int)

View File

@ -32,7 +32,7 @@ def newton_raphson(
1.2186556186174883e-10 1.2186556186174883e-10
>>> newton_raphson('cos(x)', 0) >>> newton_raphson('cos(x)', 0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ZeroDivisionError: Could not find root ZeroDivisionError: Could not find root
""" """

View File

@ -78,7 +78,7 @@ def open_knight_tour(n: int) -> list[list[int]]:
>>> open_knight_tour(2) >>> open_knight_tour(2)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Open Kight Tour cannot be performed on a board of size 2 ValueError: Open Kight Tour cannot be performed on a board of size 2
""" """

View File

@ -12,15 +12,15 @@ def bin_to_decimal(bin_string: str) -> int:
0 0
>>> bin_to_decimal("a") >>> bin_to_decimal("a")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-binary value was passed to the function ValueError: Non-binary value was passed to the function
>>> bin_to_decimal("") >>> bin_to_decimal("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
>>> bin_to_decimal("39") >>> bin_to_decimal("39")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-binary value was passed to the function ValueError: Non-binary value was passed to the function
""" """
bin_string = str(bin_string).strip() bin_string = str(bin_string).strip()

View File

@ -30,11 +30,11 @@ def bin_to_hexadecimal(binary_str: str) -> str:
'-0x1d' '-0x1d'
>>> bin_to_hexadecimal('a') >>> bin_to_hexadecimal('a')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-binary value was passed to the function ValueError: Non-binary value was passed to the function
>>> bin_to_hexadecimal('') >>> bin_to_hexadecimal('')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
""" """
# Sanitising parameter # Sanitising parameter

View File

@ -9,11 +9,11 @@ The function below will convert any binary string to the octal equivalent.
>>> bin_to_octal("") >>> bin_to_octal("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
>>> bin_to_octal("a-1") >>> bin_to_octal("a-1")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-binary value was passed to the function ValueError: Non-binary value was passed to the function
""" """

View File

@ -29,32 +29,32 @@ def decimal_to_any(num: int, base: int) -> str:
>>> # negatives will error >>> # negatives will error
>>> decimal_to_any(-45, 8) # doctest: +ELLIPSIS >>> decimal_to_any(-45, 8) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: parameter must be positive int ValueError: parameter must be positive int
>>> # floats will error >>> # floats will error
>>> decimal_to_any(34.4, 6) # doctest: +ELLIPSIS >>> decimal_to_any(34.4, 6) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: int() can't convert non-string with explicit base TypeError: int() can't convert non-string with explicit base
>>> # a float base will error >>> # a float base will error
>>> decimal_to_any(5, 2.5) # doctest: +ELLIPSIS >>> decimal_to_any(5, 2.5) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'float' object cannot be interpreted as an integer TypeError: 'float' object cannot be interpreted as an integer
>>> # a str base will error >>> # a str base will error
>>> decimal_to_any(10, '16') # doctest: +ELLIPSIS >>> decimal_to_any(10, '16') # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'str' object cannot be interpreted as an integer TypeError: 'str' object cannot be interpreted as an integer
>>> # a base less than 2 will error >>> # a base less than 2 will error
>>> decimal_to_any(7, 0) # doctest: +ELLIPSIS >>> decimal_to_any(7, 0) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: base must be >= 2 ValueError: base must be >= 2
>>> # a base greater than 36 will error >>> # a base greater than 36 will error
>>> decimal_to_any(34, 37) # doctest: +ELLIPSIS >>> decimal_to_any(34, 37) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: base must be <= 36 ValueError: base must be <= 36
""" """
if isinstance(num, float): if isinstance(num, float):

View File

@ -19,12 +19,12 @@ def decimal_to_binary(num: int) -> str:
>>> # other floats will error >>> # other floats will error
>>> decimal_to_binary(16.16) # doctest: +ELLIPSIS >>> decimal_to_binary(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'float' object cannot be interpreted as an integer TypeError: 'float' object cannot be interpreted as an integer
>>> # strings will error as well >>> # strings will error as well
>>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS >>> decimal_to_binary('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'str' object cannot be interpreted as an integer TypeError: 'str' object cannot be interpreted as an integer
""" """

View File

@ -7,7 +7,7 @@ def binary_recursive(decimal: int) -> str:
'1001000' '1001000'
>>> binary_recursive("number") >>> binary_recursive("number")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: invalid literal for int() with base 10: 'number' ValueError: invalid literal for int() with base 10: 'number'
""" """
decimal = int(decimal) decimal = int(decimal)
@ -30,11 +30,11 @@ def main(number: str) -> str:
'-0b101000' '-0b101000'
>>> main(40.8) >>> main(40.8)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value is not an integer ValueError: Input value is not an integer
>>> main("forty") >>> main("forty")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value is not an integer ValueError: Input value is not an integer
""" """
number = str(number).strip() number = str(number).strip()

View File

@ -46,12 +46,12 @@ def decimal_to_hexadecimal(decimal: float) -> str:
>>> # other floats will error >>> # other floats will error
>>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS >>> decimal_to_hexadecimal(16.16) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
AssertionError AssertionError
>>> # strings will error as well >>> # strings will error as well
>>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS >>> decimal_to_hexadecimal('0xfffff') # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
AssertionError AssertionError
>>> # results are the same when compared to Python's default hex function >>> # results are the same when compared to Python's default hex function
>>> decimal_to_hexadecimal(-256) == hex(-256) >>> decimal_to_hexadecimal(-256) == hex(-256)

View File

@ -21,11 +21,11 @@ def hex_to_bin(hex_num: str) -> int:
-1111111111111111 -1111111111111111
>>> hex_to_bin("F-f") >>> hex_to_bin("F-f")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Invalid value was passed to the function ValueError: Invalid value was passed to the function
>>> hex_to_bin("") >>> hex_to_bin("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: No value was passed to the function ValueError: No value was passed to the function
""" """

View File

@ -18,15 +18,15 @@ def hex_to_decimal(hex_string: str) -> int:
-255 -255
>>> hex_to_decimal("F-f") >>> hex_to_decimal("F-f")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-hexadecimal value was passed to the function ValueError: Non-hexadecimal value was passed to the function
>>> hex_to_decimal("") >>> hex_to_decimal("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
>>> hex_to_decimal("12m") >>> hex_to_decimal("12m")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-hexadecimal value was passed to the function ValueError: Non-hexadecimal value was passed to the function
""" """
hex_string = hex_string.strip().lower() hex_string = hex_string.strip().lower()

View File

@ -4,27 +4,27 @@ def oct_to_decimal(oct_string: str) -> int:
>>> oct_to_decimal("") >>> oct_to_decimal("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
>>> oct_to_decimal("-") >>> oct_to_decimal("-")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("e") >>> oct_to_decimal("e")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("8") >>> oct_to_decimal("8")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("-e") >>> oct_to_decimal("-e")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("-8") >>> oct_to_decimal("-8")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("1") >>> oct_to_decimal("1")
1 1
@ -38,7 +38,7 @@ def oct_to_decimal(oct_string: str) -> int:
-37 -37
>>> oct_to_decimal("-") >>> oct_to_decimal("-")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("0") >>> oct_to_decimal("0")
0 0
@ -46,15 +46,15 @@ def oct_to_decimal(oct_string: str) -> int:
-2093 -2093
>>> oct_to_decimal("2-0Fm") >>> oct_to_decimal("2-0Fm")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
>>> oct_to_decimal("") >>> oct_to_decimal("")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Empty string was passed to the function ValueError: Empty string was passed to the function
>>> oct_to_decimal("19") >>> oct_to_decimal("19")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Non-octal value was passed to the function ValueError: Non-octal value was passed to the function
""" """
oct_string = str(oct_string).strip() oct_string = str(oct_string).strip()

View File

@ -23,7 +23,7 @@ def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float:
104.0 104.0
>>> celsius_to_fahrenheit("celsius") >>> celsius_to_fahrenheit("celsius")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'celsius' ValueError: could not convert string to float: 'celsius'
""" """
return round((float(celsius) * 9 / 5) + 32, ndigits) return round((float(celsius) * 9 / 5) + 32, ndigits)
@ -47,7 +47,7 @@ def celsius_to_kelvin(celsius: float, ndigits: int = 2) -> float:
313.15 313.15
>>> celsius_to_kelvin("celsius") >>> celsius_to_kelvin("celsius")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'celsius' ValueError: could not convert string to float: 'celsius'
""" """
return round(float(celsius) + 273.15, ndigits) return round(float(celsius) + 273.15, ndigits)
@ -71,7 +71,7 @@ def celsius_to_rankine(celsius: float, ndigits: int = 2) -> float:
563.67 563.67
>>> celsius_to_rankine("celsius") >>> celsius_to_rankine("celsius")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'celsius' ValueError: could not convert string to float: 'celsius'
""" """
return round((float(celsius) * 9 / 5) + 491.67, ndigits) 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 37.78
>>> fahrenheit_to_celsius("fahrenheit") >>> fahrenheit_to_celsius("fahrenheit")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'fahrenheit' ValueError: could not convert string to float: 'fahrenheit'
""" """
return round((float(fahrenheit) - 32) * 5 / 9, ndigits) return round((float(fahrenheit) - 32) * 5 / 9, ndigits)
@ -131,7 +131,7 @@ def fahrenheit_to_kelvin(fahrenheit: float, ndigits: int = 2) -> float:
310.93 310.93
>>> fahrenheit_to_kelvin("fahrenheit") >>> fahrenheit_to_kelvin("fahrenheit")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'fahrenheit' ValueError: could not convert string to float: 'fahrenheit'
""" """
return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, ndigits) 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 559.67
>>> fahrenheit_to_rankine("fahrenheit") >>> fahrenheit_to_rankine("fahrenheit")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'fahrenheit' ValueError: could not convert string to float: 'fahrenheit'
""" """
return round(float(fahrenheit) + 459.67, ndigits) return round(float(fahrenheit) + 459.67, ndigits)
@ -185,7 +185,7 @@ def kelvin_to_celsius(kelvin: float, ndigits: int = 2) -> float:
42.35 42.35
>>> kelvin_to_celsius("kelvin") >>> kelvin_to_celsius("kelvin")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'kelvin' ValueError: could not convert string to float: 'kelvin'
""" """
return round(float(kelvin) - 273.15, ndigits) return round(float(kelvin) - 273.15, ndigits)
@ -209,7 +209,7 @@ def kelvin_to_fahrenheit(kelvin: float, ndigits: int = 2) -> float:
108.23 108.23
>>> kelvin_to_fahrenheit("kelvin") >>> kelvin_to_fahrenheit("kelvin")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'kelvin' ValueError: could not convert string to float: 'kelvin'
""" """
return round(((float(kelvin) - 273.15) * 9 / 5) + 32, ndigits) 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 72.0
>>> kelvin_to_rankine("kelvin") >>> kelvin_to_rankine("kelvin")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'kelvin' ValueError: could not convert string to float: 'kelvin'
""" """
return round((float(kelvin) * 9 / 5), ndigits) return round((float(kelvin) * 9 / 5), ndigits)
@ -257,7 +257,7 @@ def rankine_to_celsius(rankine: float, ndigits: int = 2) -> float:
-97.87 -97.87
>>> rankine_to_celsius("rankine") >>> rankine_to_celsius("rankine")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'rankine' ValueError: could not convert string to float: 'rankine'
""" """
return round((float(rankine) - 491.67) * 5 / 9, ndigits) 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 -144.17
>>> rankine_to_fahrenheit("rankine") >>> rankine_to_fahrenheit("rankine")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'rankine' ValueError: could not convert string to float: 'rankine'
""" """
return round(float(rankine) - 459.67, ndigits) return round(float(rankine) - 459.67, ndigits)
@ -297,7 +297,7 @@ def rankine_to_kelvin(rankine: float, ndigits: int = 2) -> float:
22.22 22.22
>>> rankine_to_kelvin("rankine") >>> rankine_to_kelvin("rankine")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'rankine' ValueError: could not convert string to float: 'rankine'
""" """
return round((float(rankine) * 5 / 9), ndigits) return round((float(rankine) * 5 / 9), ndigits)
@ -316,7 +316,7 @@ def reaumur_to_kelvin(reaumur: float, ndigits: int = 2) -> float:
323.15 323.15
>>> reaumur_to_kelvin("reaumur") >>> reaumur_to_kelvin("reaumur")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'reaumur' ValueError: could not convert string to float: 'reaumur'
""" """
return round((float(reaumur) * 1.25 + 273.15), ndigits) 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 122.0
>>> reaumur_to_fahrenheit("reaumur") >>> reaumur_to_fahrenheit("reaumur")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'reaumur' ValueError: could not convert string to float: 'reaumur'
""" """
return round((float(reaumur) * 2.25 + 32), ndigits) return round((float(reaumur) * 2.25 + 32), ndigits)
@ -354,7 +354,7 @@ def reaumur_to_celsius(reaumur: float, ndigits: int = 2) -> float:
50.0 50.0
>>> reaumur_to_celsius("reaumur") >>> reaumur_to_celsius("reaumur")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'reaumur' ValueError: could not convert string to float: 'reaumur'
""" """
return round((float(reaumur) * 1.25), ndigits) return round((float(reaumur) * 1.25), ndigits)
@ -373,7 +373,7 @@ def reaumur_to_rankine(reaumur: float, ndigits: int = 2) -> float:
581.67 581.67
>>> reaumur_to_rankine("reaumur") >>> reaumur_to_rankine("reaumur")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: could not convert string to float: 'reaumur' ValueError: could not convert string to float: 'reaumur'
""" """
return round((float(reaumur) * 2.25 + 32 + 459.67), ndigits) return round((float(reaumur) * 2.25 + 32 + 459.67), ndigits)

View File

@ -196,7 +196,7 @@ def binary_search_tree() -> None:
1 4 7 6 3 13 14 10 8 1 4 7 6 3 13 14 10 8
>>> BinarySearchTree().search(6) >>> BinarySearchTree().search(6)
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: Warning: Tree is empty! please use another. IndexError: Warning: Tree is empty! please use another.
""" """
testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7) testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7)

View File

@ -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]} {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) >>> binary_tree_mirror({ 1: [2,3], 2: [4,5], 3: [6,7], 4: [10,11]}, 5)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: root 5 is not present in the binary_tree ValueError: root 5 is not present in the binary_tree
>>> binary_tree_mirror({}, 5) >>> binary_tree_mirror({}, 5)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: binary tree cannot be empty ValueError: binary tree cannot be empty
""" """
if not binary_tree: if not binary_tree:

View File

@ -67,7 +67,7 @@ def factorial(n: int) -> int:
True True
>>> factorial(-5) # doctest: +ELLIPSIS >>> factorial(-5) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: factorial() not defined for negative values ValueError: factorial() not defined for negative values
""" """
if n < 0: if n < 0:

View File

@ -64,11 +64,11 @@ class DoublyLinkedList:
>>> linked_list = DoublyLinkedList() >>> linked_list = DoublyLinkedList()
>>> linked_list.insert_at_nth(-1, 666) >>> linked_list.insert_at_nth(-1, 666)
Traceback (most recent call last): Traceback (most recent call last):
.... ....
IndexError: list index out of range IndexError: list index out of range
>>> linked_list.insert_at_nth(1, 666) >>> linked_list.insert_at_nth(1, 666)
Traceback (most recent call last): Traceback (most recent call last):
.... ....
IndexError: list index out of range IndexError: list index out of range
>>> linked_list.insert_at_nth(0, 2) >>> linked_list.insert_at_nth(0, 2)
>>> linked_list.insert_at_nth(0, 1) >>> linked_list.insert_at_nth(0, 1)
@ -78,7 +78,7 @@ class DoublyLinkedList:
'1->2->3->4' '1->2->3->4'
>>> linked_list.insert_at_nth(5, 5) >>> linked_list.insert_at_nth(5, 5)
Traceback (most recent call last): Traceback (most recent call last):
.... ....
IndexError: list index out of range IndexError: list index out of range
""" """
if not 0 <= index <= len(self): if not 0 <= index <= len(self):
@ -114,7 +114,7 @@ class DoublyLinkedList:
>>> linked_list = DoublyLinkedList() >>> linked_list = DoublyLinkedList()
>>> linked_list.delete_at_nth(0) >>> linked_list.delete_at_nth(0)
Traceback (most recent call last): Traceback (most recent call last):
.... ....
IndexError: list index out of range IndexError: list index out of range
>>> for i in range(0, 5): >>> for i in range(0, 5):
... linked_list.insert_at_nth(i, i + 1) ... linked_list.insert_at_nth(i, i + 1)
@ -128,7 +128,7 @@ class DoublyLinkedList:
'2->4' '2->4'
>>> linked_list.delete_at_nth(2) >>> linked_list.delete_at_nth(2)
Traceback (most recent call last): Traceback (most recent call last):
.... ....
IndexError: list index out of range IndexError: list index out of range
""" """
if not 0 <= index <= len(self) - 1: if not 0 <= index <= len(self) - 1:

View File

@ -95,11 +95,11 @@ class LinkedList:
True True
>>> linked_list[-10] >>> linked_list[-10]
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: list index out of range. ValueError: list index out of range.
>>> linked_list[len(linked_list)] >>> linked_list[len(linked_list)]
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: list index out of range. ValueError: list index out of range.
""" """
if not 0 <= index < len(self): if not 0 <= index < len(self):
@ -122,11 +122,11 @@ class LinkedList:
-666 -666
>>> linked_list[-10] = 666 >>> linked_list[-10] = 666
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: list index out of range. ValueError: list index out of range.
>>> linked_list[len(linked_list)] = 666 >>> linked_list[len(linked_list)] = 666
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: list index out of range. ValueError: list index out of range.
""" """
if not 0 <= index < len(self): if not 0 <= index < len(self):
@ -233,7 +233,7 @@ class LinkedList:
'third' 'third'
>>> linked_list.delete_head() >>> linked_list.delete_head()
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: List index out of range. IndexError: List index out of range.
""" """
return self.delete_nth(0) return self.delete_nth(0)
@ -260,7 +260,7 @@ class LinkedList:
'first' 'first'
>>> linked_list.delete_tail() >>> linked_list.delete_tail()
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: List index out of range. IndexError: List index out of range.
""" """
return self.delete_nth(len(self) - 1) return self.delete_nth(len(self) - 1)
@ -281,11 +281,11 @@ class LinkedList:
first->third first->third
>>> linked_list.delete_nth(5) # this raises error >>> linked_list.delete_nth(5) # this raises error
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: List index out of range. IndexError: List index out of range.
>>> linked_list.delete_nth(-1) # this also raises error >>> linked_list.delete_nth(-1) # this also raises error
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: List index out of range. IndexError: List index out of range.
""" """
if not 0 <= index <= len(self) - 1: # test if index is valid if not 0 <= index <= len(self) - 1: # test if index is valid

View File

@ -96,7 +96,7 @@ class LinkedQueue:
>>> queue = LinkedQueue() >>> queue = LinkedQueue()
>>> queue.get() >>> queue.get()
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: dequeue from empty queue IndexError: dequeue from empty queue
>>> for i in range(1, 6): >>> for i in range(1, 6):
... queue.put(i) ... queue.put(i)
@ -116,7 +116,7 @@ class LinkedQueue:
>>> queue = LinkedQueue() >>> queue = LinkedQueue()
>>> queue.get() >>> queue.get()
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: dequeue from empty queue IndexError: dequeue from empty queue
>>> queue = LinkedQueue() >>> queue = LinkedQueue()
>>> for i in range(1, 6): >>> for i in range(1, 6):

View File

@ -58,7 +58,7 @@ class FixedPriorityQueue:
4 4
>>> fpq.dequeue() >>> fpq.dequeue()
Traceback (most recent call last): Traceback (most recent call last):
... ...
data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty data_structures.queue.priority_queue_using_list.UnderFlowError: All queues are empty
>>> print(fpq) >>> print(fpq)
Priority 0: [] Priority 0: []

View File

@ -21,7 +21,7 @@ def infix_to_postfix(expression_str: str) -> str:
""" """
>>> infix_to_postfix("(1*(2+3)+4))") >>> infix_to_postfix("(1*(2+3)+4))")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Mismatched parentheses ValueError: Mismatched parentheses
>>> infix_to_postfix("") >>> infix_to_postfix("")
'' ''

View File

@ -109,7 +109,7 @@ class LinkedStack(Generic[T]):
>>> stack = LinkedStack() >>> stack = LinkedStack()
>>> stack.pop() >>> stack.pop()
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: pop from empty stack IndexError: pop from empty stack
>>> stack.push("c") >>> stack.push("c")
>>> stack.push("b") >>> stack.push("b")

View File

@ -32,7 +32,7 @@ def longest_common_substring(text1: str, text2: str) -> str:
'Site:Geeks' 'Site:Geeks'
>>> longest_common_substring(1, 1) >>> longest_common_substring(1, 1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: longest_common_substring() takes two strings for inputs ValueError: longest_common_substring() takes two strings for inputs
""" """

View File

@ -32,17 +32,17 @@ def basic(target: str, genes: list[str], debug: bool = True) -> tuple[int, int,
>>> genes.remove("e") >>> genes.remove("e")
>>> basic("test", genes) >>> basic("test", genes)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: ['e'] is not in genes list, evolution cannot converge ValueError: ['e'] is not in genes list, evolution cannot converge
>>> genes.remove("s") >>> genes.remove("s")
>>> basic("test", genes) >>> basic("test", genes)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: ['e', 's'] is not in genes list, evolution cannot converge ValueError: ['e', 's'] is not in genes list, evolution cannot converge
>>> genes.remove("t") >>> genes.remove("t")
>>> basic("test", genes) >>> basic("test", genes)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: ['e', 's', 't'] is not in genes list, evolution cannot converge ValueError: ['e', 's', 't'] is not in genes list, evolution cannot converge
""" """

View File

@ -168,7 +168,7 @@ class Vector:
9.539392014169456 9.539392014169456
>>> Vector([]).euclidean_length() >>> Vector([]).euclidean_length()
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: Vector is empty Exception: Vector is empty
""" """
if len(self.__components) == 0: if len(self.__components) == 0:
@ -186,7 +186,7 @@ class Vector:
85.40775111366095 85.40775111366095
>>> Vector([3, 4, -1]).angle(Vector([2, -1])) >>> Vector([3, 4, -1]).angle(Vector([2, -1]))
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: invalid operand! Exception: invalid operand!
""" """
num = self * other num = self * other

View File

@ -70,7 +70,7 @@ def similarity_search(
>>> value_array = np.array([1]) >>> value_array = np.array([1])
>>> similarity_search(dataset, value_array) >>> similarity_search(dataset, value_array)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Wrong input data's dimensions... dataset : 2, value_array : 1 ValueError: Wrong input data's dimensions... dataset : 2, value_array : 1
2. If data's shapes are different. 2. If data's shapes are different.
@ -80,7 +80,7 @@ def similarity_search(
>>> value_array = np.array([[0, 0, 0], [0, 0, 1]]) >>> value_array = np.array([[0, 0, 0], [0, 0, 1]])
>>> similarity_search(dataset, value_array) >>> similarity_search(dataset, value_array)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Wrong input data's shape... dataset : 2, value_array : 3 ValueError: Wrong input data's shape... dataset : 2, value_array : 3
3. If data types are different. 3. If data types are different.
@ -90,7 +90,7 @@ def similarity_search(
>>> value_array = np.array([[0, 0], [0, 1]], dtype=np.int32) >>> value_array = np.array([[0, 0], [0, 1]], dtype=np.int32)
>>> similarity_search(dataset, value_array) # doctest: +NORMALIZE_WHITESPACE >>> similarity_search(dataset, value_array) # doctest: +NORMALIZE_WHITESPACE
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: Input data have different datatype... TypeError: Input data have different datatype...
dataset : float32, value_array : int32 dataset : float32, value_array : int32
""" """

View File

@ -32,7 +32,7 @@ def bisection(a: float, b: float) -> float:
3.158203125 3.158203125
>>> bisection(2, 3) >>> bisection(2, 3)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Wrong space! ValueError: Wrong space!
""" """
# Bolzano theory in order to find if there is a root between a and b # Bolzano theory in order to find if there is a root between a and b

View File

@ -18,15 +18,15 @@ def catalan(number: int) -> int:
14 14
>>> catalan(0) >>> catalan(0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value of [number=0] must be > 0 ValueError: Input value of [number=0] must be > 0
>>> catalan(-1) >>> catalan(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value of [number=-1] must be > 0 ValueError: Input value of [number=-1] must be > 0
>>> catalan(5.0) >>> catalan(5.0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: Input value of [number=5.0] must be an integer TypeError: Input value of [number=5.0] must be an integer
""" """

View File

@ -47,7 +47,7 @@ def fib_iterative(n: int) -> list[int]:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1) >>> fib_iterative(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: n is negative Exception: n is negative
""" """
if n < 0: 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] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1) >>> fib_iterative(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: n is negative 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] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1) >>> fib_iterative(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: n is negative Exception: n is negative
""" """
if n < 0: 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] [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_binet(-1) >>> fib_binet(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: n is negative Exception: n is negative
>>> fib_binet(1475) >>> fib_binet(1475)
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: n is too large Exception: n is too large
""" """
if n < 0: if n < 0:

View File

@ -26,19 +26,19 @@ def maclaurin_sin(theta: float, accuracy: int = 30) -> float:
0.5440211108893703 0.5440211108893703
>>> maclaurin_sin("10") >>> maclaurin_sin("10")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_sin() requires either an int or float for theta ValueError: maclaurin_sin() requires either an int or float for theta
>>> maclaurin_sin(10, -30) >>> maclaurin_sin(10, -30)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_sin() requires a positive int for accuracy ValueError: maclaurin_sin() requires a positive int for accuracy
>>> maclaurin_sin(10, 30.5) >>> maclaurin_sin(10, 30.5)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_sin() requires a positive int for accuracy ValueError: maclaurin_sin() requires a positive int for accuracy
>>> maclaurin_sin(10, "30") >>> maclaurin_sin(10, "30")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_sin() requires a positive int for accuracy ValueError: maclaurin_sin() requires a positive int for accuracy
""" """
@ -78,19 +78,19 @@ def maclaurin_cos(theta: float, accuracy: int = 30) -> float:
-0.8390715290764521 -0.8390715290764521
>>> maclaurin_cos("10") >>> maclaurin_cos("10")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_cos() requires either an int or float for theta ValueError: maclaurin_cos() requires either an int or float for theta
>>> maclaurin_cos(10, -30) >>> maclaurin_cos(10, -30)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_cos() requires a positive int for accuracy ValueError: maclaurin_cos() requires a positive int for accuracy
>>> maclaurin_cos(10, 30.5) >>> maclaurin_cos(10, 30.5)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_cos() requires a positive int for accuracy ValueError: maclaurin_cos() requires a positive int for accuracy
>>> maclaurin_cos(10, "30") >>> maclaurin_cos(10, "30")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: maclaurin_cos() requires a positive int for accuracy ValueError: maclaurin_cos() requires a positive int for accuracy
""" """

View File

@ -16,15 +16,15 @@ def proth(number: int) -> int:
25 25
>>> proth(0) >>> proth(0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value of [number=0] must be > 0 ValueError: Input value of [number=0] must be > 0
>>> proth(-1) >>> proth(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Input value of [number=-1] must be > 0 ValueError: Input value of [number=-1] must be > 0
>>> proth(6.0) >>> proth(6.0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: Input value of [number=6.0] must be an integer TypeError: Input value of [number=6.0] must be an integer
""" """

View File

@ -18,12 +18,12 @@ def sylvester(number: int) -> int:
>>> sylvester(-1) >>> sylvester(-1)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: The input value of [n=-1] has to be > 0 ValueError: The input value of [n=-1] has to be > 0
>>> sylvester(8.0) >>> sylvester(8.0)
Traceback (most recent call last): Traceback (most recent call last):
... ...
AssertionError: The input value of [n=8.0] is not an integer 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" assert isinstance(number, int), f"The input value of [n={number}] is not an integer"

View File

@ -14,11 +14,11 @@ def zeller(date_input: str) -> str:
Validate out of range month Validate out of range month
>>> zeller('13-31-2010') >>> zeller('13-31-2010')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Month must be between 1 - 12 ValueError: Month must be between 1 - 12
>>> zeller('.2-31-2010') >>> zeller('.2-31-2010')
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: invalid literal for int() with base 10: '.2' ValueError: invalid literal for int() with base 10: '.2'
Validate out of range date: Validate out of range date:

View File

@ -29,15 +29,15 @@ class Perceptron:
>>> p = Perceptron([], (0, 1, 2)) >>> p = Perceptron([], (0, 1, 2))
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Sample data can not be empty ValueError: Sample data can not be empty
>>> p = Perceptron(([0], 1, 2), []) >>> p = Perceptron(([0], 1, 2), [])
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Target data can not be empty ValueError: Target data can not be empty
>>> p = Perceptron(([0], 1, 2), (0, 1)) >>> p = Perceptron(([0], 1, 2), (0, 1))
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Sample data and Target data do not have matching lengths ValueError: Sample data and Target data do not have matching lengths
""" """
self.sample = sample self.sample = sample

View File

@ -26,7 +26,7 @@ def solution(n: int = 998001) -> int:
39893 39893
>>> solution(10000) >>> solution(10000)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: That number is larger than our acceptable range. ValueError: That number is larger than our acceptable range.
""" """

View File

@ -30,15 +30,15 @@ def solution(n: int = 2000000) -> int:
10 10
>>> solution(7.1) # doctest: +ELLIPSIS >>> solution(7.1) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: 'float' object cannot be interpreted as an integer TypeError: 'float' object cannot be interpreted as an integer
>>> solution(-7) # doctest: +ELLIPSIS >>> solution(-7) # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
IndexError: list assignment index out of range IndexError: list assignment index out of range
>>> solution("seven") # doctest: +ELLIPSIS >>> solution("seven") # doctest: +ELLIPSIS
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: can only concatenate str (not "int") to str TypeError: can only concatenate str (not "int") to str
""" """

View File

@ -101,7 +101,7 @@ def __assert_sorted(collection):
True True
>>> __assert_sorted([10, -1, 5]) >>> __assert_sorted([10, -1, 5])
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Collection must be ascending sorted ValueError: Collection must be ascending sorted
""" """
if collection != sorted(collection): if collection != sorted(collection):

View File

@ -20,12 +20,12 @@ def bead_sort(sequence: list) -> list:
>>> bead_sort([1, .9, 0.0, 0, -1, -.9]) >>> bead_sort([1, .9, 0.0, 0, -1, -.9])
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: Sequence must be list of non-negative integers TypeError: Sequence must be list of non-negative integers
>>> bead_sort("Hello world") >>> bead_sort("Hello world")
Traceback (most recent call last): Traceback (most recent call last):
... ...
TypeError: Sequence must be list of non-negative integers TypeError: Sequence must be list of non-negative integers
""" """
if any(not isinstance(x, int) or x < 0 for x in sequence): if any(not isinstance(x, int) or x < 0 for x in sequence):

View File

@ -23,7 +23,7 @@ def msd_radix_sort(list_of_ints: list[int]) -> list[int]:
[1, 45, 1209, 540402, 834598] [1, 45, 1209, 540402, 834598]
>>> msd_radix_sort([-1, 34, 45]) >>> msd_radix_sort([-1, 34, 45])
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: All numbers must be positive ValueError: All numbers must be positive
""" """
if not list_of_ints: 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] >>> lst = [-1, 34, 23, 4, -42]
>>> msd_radix_sort_inplace(lst) >>> msd_radix_sort_inplace(lst)
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: All numbers must be positive ValueError: All numbers must be positive
""" """

View File

@ -47,7 +47,7 @@ def is_valid(barcode: int) -> bool:
False False
>>> is_valid(dwefgiweuf) >>> is_valid(dwefgiweuf)
Traceback (most recent call last): Traceback (most recent call last):
... ...
NameError: name 'dwefgiweuf' is not defined NameError: name 'dwefgiweuf' is not defined
""" """
return len(str(barcode)) == 13 and get_check_digit(barcode) == barcode % 10 return len(str(barcode)) == 13 and get_check_digit(barcode) == barcode % 10
@ -61,7 +61,7 @@ def get_barcode(barcode: str) -> int:
8718452538119 8718452538119
>>> get_barcode("dwefgiweuf") >>> get_barcode("dwefgiweuf")
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Barcode 'dwefgiweuf' has alphabetic characters. ValueError: Barcode 'dwefgiweuf' has alphabetic characters.
""" """
if str(barcode).isalpha(): if str(barcode).isalpha():

View File

@ -15,7 +15,7 @@ def join(separator: str, separated: list[str]) -> str:
'You are amazing!' 'You are amazing!'
>>> join("#", ["a", "b", "c", 1]) >>> join("#", ["a", "b", "c", 1])
Traceback (most recent call last): Traceback (most recent call last):
... ...
Exception: join() accepts only strings to be joined Exception: join() accepts only strings to be joined
""" """
joined = "" joined = ""