From 56d42f2287b19fcbfa47c8601b0ca31574634d3e Mon Sep 17 00:00:00 2001 From: Atin Bainada <61903527+atin@users.noreply.github.com> Date: Sat, 24 Apr 2021 23:52:15 +0530 Subject: [PATCH] chore(Python): add doctest for jump_search (#255) --- algorithms/Python/searching/jump_search.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/algorithms/Python/searching/jump_search.py b/algorithms/Python/searching/jump_search.py index 5721ed3b..86b81f90 100644 --- a/algorithms/Python/searching/jump_search.py +++ b/algorithms/Python/searching/jump_search.py @@ -10,8 +10,14 @@ Space Complexity: O(1) import math +arr = [0, 1, 2, 8, 13, 17, 19, 25, 31, 32, 42] +target = 25 def jump_search(arr: list, x: int) -> int: + """ + >>> jump_search(arr, target) == (arr.index(target) if target in arr else -1) + True + """ n = len(arr) step = int(math.floor(math.sqrt(n))) prev = 0 @@ -37,8 +43,6 @@ def check_sort(test: list) -> bool: if __name__ == "__main__": - arr = [0, 1, 2, 8, 13, 17, 19, 25, 31, 32, 42] - target = 25 if check_sort(arr): res = jump_search(arr, target) if res == -1: @@ -46,4 +50,4 @@ if __name__ == "__main__": else: print(f"Number {target} is at index {res}") else: - print("Given list is not sorted!") \ No newline at end of file + print("Given list is not sorted!")