-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bisect.py
More file actions
53 lines (34 loc) · 1.25 KB
/
Copy pathtest_bisect.py
File metadata and controls
53 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flake_bisect.bisect import ddmin
def test_ddmin_finds_single_required_element():
items = list(range(1, 11))
def contains_five(xs):
return 5 in xs
assert ddmin(items, contains_five) == [5]
def test_ddmin_finds_pair_of_required_elements():
items = list(range(1, 21))
def contains_three_and_seventeen(xs):
return 3 in xs and 17 in xs
minimal = ddmin(items, contains_three_and_seventeen)
assert set(minimal) == {3, 17}
# preserves original order
assert minimal == sorted(minimal)
def test_ddmin_on_singleton_returns_singleton():
assert ddmin([42], lambda xs: 42 in xs) == [42]
def test_ddmin_respects_max_calls():
import pytest
items = list(range(50))
def pred(xs):
return 7 in xs and 23 in xs and 41 in xs
with pytest.raises(RuntimeError, match="max-runs"):
ddmin(items, pred, max_calls=1)
def test_ddmin_caches_repeated_subsets():
items = list(range(1, 9))
calls = {"n": 0}
def pred(xs):
calls["n"] += 1
return 4 in xs
result = ddmin(items, pred)
assert result == [4]
# With caching, redundant subset evaluations are avoided. The exact count
# depends on ddmin's traversal, but it must be bounded.
assert calls["n"] < 30