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
>>> 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

View File

@ -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

View File

@ -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
"""

View File

@ -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]]

View File

@ -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)

View File

@ -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
"""

View File

@ -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
"""

View File

@ -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()

View File

@ -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

View File

@ -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
"""

View File

@ -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):

View File

@ -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
"""

View File

@ -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()

View File

@ -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)

View File

@ -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
"""

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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)

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]}
>>> 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:

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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: []

View File

@ -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("")
''

View File

@ -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")

View File

@ -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
"""

View File

@ -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
"""

View File

@ -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

View File

@ -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
"""

View File

@ -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

View File

@ -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
"""

View File

@ -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:

View File

@ -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
"""

View File

@ -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
"""

View File

@ -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"

View File

@ -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:

View File

@ -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

View File

@ -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.
"""

View File

@ -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
"""

View File

@ -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):

View File

@ -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):

View File

@ -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
"""

View File

@ -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():

View File

@ -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 = ""