MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _validate_point

Function _validate_point

maths/manhattan_distance.py:46–78  ·  view source on GitHub ↗

>>> _validate_point(None) Traceback (most recent call last): ... ValueError: Missing an input >>> _validate_point([1,"one"]) Traceback (most recent call last): ... TypeError: Expected a list of numbers as input, found str >>> _validate_point(1) Trac

(point: list[float])

Source from the content-addressed store, hash-verified

44
45
46def _validate_point(point: list[float]) -> None:
47 """
48 >>> _validate_point(None)
49 Traceback (most recent call last):
50 ...
51 ValueError: Missing an input
52 >>> _validate_point([1,"one"])
53 Traceback (most recent call last):
54 ...
55 TypeError: Expected a list of numbers as input, found str
56 >>> _validate_point(1)
57 Traceback (most recent call last):
58 ...
59 TypeError: Expected a list of numbers as input, found int
60 >>> _validate_point("not_a_list")
61 Traceback (most recent call last):
62 ...
63 TypeError: Expected a list of numbers as input, found str
64 """
65 if point:
66 if isinstance(point, list):
67 for item in point:
68 if not isinstance(item, (int, float)):
69 msg = (
70 "Expected a list of numbers as input, found "
71 f"{type(item).__name__}"
72 )
73 raise TypeError(msg)
74 else:
75 msg = f"Expected a list of numbers as input, found {type(point).__name__}"
76 raise TypeError(msg)
77 else:
78 raise ValueError("Missing an input")
79
80
81def manhattan_distance_one_liner(point_a: list, point_b: list) -> float:

Callers 2

manhattan_distanceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected