Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 73b58b5

Browse files
committed
Updated documentations and fixtures names
1 parent 7fc5f4a commit 73b58b5

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

src/bisearch/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Binary Search
3+
=============
4+
5+
The binary search algorithm (a.k.a **half-interval search** or **bisect**)
6+
is a search algorithm that finds the position of a target value within
7+
a sorted array. The origin dataset is required to be sorted before applying
8+
to bisect. This algorithm runs in a logarithmic time in the worst case,
9+
making O(log_n) comparisons.
10+
11+
The general idea is to divide the initial array in two equal portions, and
12+
to compare the middle value with the requested one. Since array in case
13+
the middle value is greater than the search one, the left portion can be
14+
excluded from the future search (vice versa the right one excluded). After
15+
that the search algorithm is applied for the right part only.
16+
17+
.. seealso:: https://en.wikipedia.org/wiki/Binary_search_algorithm
18+
19+
"""

src/bisearch/prefix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def find_all(origin: List[str], search: str = "") -> List[str]:
8383
8484
:return: the list of strings starting with the search prefix
8585
:rtype: list[str]
86+
8687
"""
8788

8889
try:

tests/bisearch/conftest.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,25 @@ def strings_small():
99

1010

1111
@pytest.fixture
12-
def strings_fixtures():
12+
def strings_large():
13+
# 10_000 strings generated with https://random.org
1314
fixture_path = Path(__file__).parent.joinpath("fixtures/strings.txt")
1415
with open(fixture_path) as fixture_file:
1516
return fixture_file.read().splitlines()
1617

1718

1819
@pytest.fixture
19-
def fa_fixture():
20-
return (
21-
"ua",
22-
["uaeafwqbag", "uasyolgnuc", "uaszazvdez", "uavmfgakey", "uawwitgssy",
23-
"uaxxgxmsrn", "uayppkjtny", ]
24-
)
20+
def find_all_fixture():
21+
return ("ua",
22+
["uaeafwqbag", "uasyolgnuc", "uaszazvdez", "uavmfgakey",
23+
"uawwitgssy", "uaxxgxmsrn", "uayppkjtny"])
2524

2625

2726
@pytest.fixture
28-
def pr_fixture():
27+
def prefix_right_fixture():
2928
return "sh", 7045
3029

3130

3231
@pytest.fixture
33-
def pl_fixture():
32+
def prefix_left_fixture():
3433
return "vp", 8291

tests/bisearch/test_prefix.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
from bisearch.prefix import NotFound
55

66

7-
def test_prefix_right(strings_fixtures, pr_fixture):
8-
search, test_value = pr_fixture
9-
assert prefix.bisect_right(strings_fixtures, search) == test_value
7+
def test_prefix_right(strings_large, prefix_right_fixture):
8+
search, test_value = prefix_right_fixture
9+
assert prefix.bisect_right(strings_large, search) == test_value
1010

1111

12-
def test_prefix_left(strings_fixtures, pl_fixture):
13-
search, test_value = pl_fixture
14-
assert prefix.bisect_left(strings_fixtures, search) == test_value
12+
def test_prefix_left(strings_large, prefix_left_fixture):
13+
search, test_value = prefix_left_fixture
14+
assert prefix.bisect_left(strings_large, search) == test_value
1515

1616

17-
def test_find_all(strings_fixtures, fa_fixture):
18-
search, test_value = fa_fixture
19-
assert prefix.find_all(strings_fixtures, search) == test_value
17+
def test_find_all(strings_large, find_all_fixture):
18+
search, test_value = find_all_fixture
19+
assert prefix.find_all(strings_large, search) == test_value
2020

2121

2222
def test_prefix_right_default(strings_small):

0 commit comments

Comments
 (0)