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

Commit 2ec1882

Browse files
committed
Added edge case tests
1 parent 73b58b5 commit 2ec1882

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

tests/bisearch/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55

66
@pytest.fixture
7-
def strings_small():
7+
def strings_small_fixture():
88
return sorted(["a", "b", "c", "ab", "bc", "ca", "abc", "bca", "cab"])
99

1010

1111
@pytest.fixture
12-
def strings_large():
12+
def strings_large_fixture():
1313
# 10_000 strings generated with https://random.org
1414
fixture_path = Path(__file__).parent.joinpath("fixtures/strings.txt")
1515
with open(fixture_path) as fixture_file:

tests/bisearch/test_prefix.py

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

66

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

1111

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

1616

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

2121

22-
def test_prefix_right_default(strings_small):
23-
assert prefix.bisect_right(strings_small) == len(strings_small)
22+
def test_prefix_right_default(strings_small_fixture):
23+
string_idx = len(strings_small_fixture)
24+
assert prefix.bisect_right(strings_small_fixture) == string_idx
2425

2526

26-
def test_prefix_left_default(strings_small):
27-
assert prefix.bisect_left(strings_small) == 0
27+
def test_prefix_left_default(strings_small_fixture):
28+
assert prefix.bisect_left(strings_small_fixture) == 0
2829

2930

30-
def test_find_all_default(strings_small):
31-
assert prefix.find_all(strings_small) == strings_small
31+
def test_find_all_default(strings_small_fixture):
32+
assert prefix.find_all(strings_small_fixture) == strings_small_fixture
3233

3334

34-
def test_prefix_right_negative(strings_small):
35+
def test_prefix_right_last(strings_small_fixture):
36+
string_idx = len(strings_small_fixture)
37+
assert prefix.bisect_right(strings_small_fixture, "cab") == string_idx
38+
39+
40+
def test_prefix_left_last(strings_small_fixture):
41+
string_idx = len(strings_small_fixture) - 1
42+
assert prefix.bisect_left(strings_small_fixture, "cab") == string_idx
43+
44+
45+
def test_prefix_right_negative(strings_small_fixture):
3546
with pytest.raises(NotFound):
36-
prefix.bisect_right(strings_small, "d")
47+
prefix.bisect_right(strings_small_fixture, "d")
3748

3849

39-
def test_prefix_left_negative(strings_small):
50+
def test_prefix_left_negative(strings_small_fixture):
4051
with pytest.raises(NotFound):
41-
prefix.bisect_left(strings_small, "d")
52+
prefix.bisect_left(strings_small_fixture, "d")
4253

4354

44-
def test_find_all_negative(strings_small):
45-
assert prefix.find_all(strings_small, "d") == []
55+
def test_find_all_negative(strings_small_fixture):
56+
assert prefix.find_all(strings_small_fixture, "d") == []

0 commit comments

Comments
 (0)