Skip to content

Indent ... for visual purposes #7744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arithmetic_analysis/bisection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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
>>> bisection(lambda x: x ** 2 - 4 * x + 3, 2, 4)
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
Expand Down
4 changes: 2 additions & 2 deletions arithmetic_analysis/intersection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions arithmetic_analysis/jacobi_iteration_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]])
Expand All @@ -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

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

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

Expand Down Expand Up @@ -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
"""

Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/lu_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arithmetic_analysis/newton_raphson_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down
2 changes: 1 addition & 1 deletion backtracking/knight_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down
6 changes: 3 additions & 3 deletions conversions/binary_to_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions conversions/binary_to_hexadecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions conversions/binary_to_octal.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

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

Expand Down
12 changes: 6 additions & 6 deletions conversions/decimal_to_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions conversions/decimal_to_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down
6 changes: 3 additions & 3 deletions conversions/decimal_to_binary_recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions conversions/decimal_to_hexadecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions conversions/hex_to_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""

Expand Down
6 changes: 3 additions & 3 deletions conversions/hexadecimal_to_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions conversions/octal_to_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,23 +38,23 @@ 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
>>> oct_to_decimal("-4055")
-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()
Expand Down
Loading