# Path: jacquard/utils_dev.py
# def shrink(data, is_valid):
#     """
#     Simplify `data` subject to `is_valid(data)`.
# 
#     `data` is any JSON-form data (strings, bools, None, ints, floats, lists,
#     and dicts). This is roughly analogous to the concept of `shrink` from
#     `QuickCheck`.
# 
#     It's used in `bugpoint`.
#     """
#     # This is in principle recursive, but we do this with explicit iteration
#     # to save on stack space.
# 
#     any_changes = True
#     while any_changes:
#         try:
#             shrinker = _SHRINKERS[type(data)]
#         except KeyError:
#             # Unshrinkable type
#             return data
#         data, any_changes = shrinker(data, is_valid)
#     return data


from jacquard.utils_dev import shrink

def test_strings_shrink_by_cutting_off_start():
    assert shrink("bees", lambda x: x.endswith("s")) == "s"


def test_strings_shrink_by_cutting_off_from_both_ends():
    assert shrink("bees", lambda x: "ee" in x) == "ee"


def test_unshrinkable_strings_are_not_shrunk():
    assert shrink("bees", lambda x: x == "bees") == "bees"


def test_strings_shrink_to_a_where_possible():
    assert shrink("bees", lambda x: len(x) >= 2) == "aa"


def test_empty_string_is_unshrunk():
    assert shrink("", lambda x: True) == ""


def test_empty_list_is_unshrunk():
    assert shrink([], lambda x: True) == []


def test_lists_shrunk_by_cutting_off_from_both_ends():
    assert shrink(list("bees"), lambda x: "ee" in "".join(x)) == ["e", "e"]


def test_lists_shrink_to_the_empty_list():

# Path: jacquard/utils_dev.py
# def shrink(data, is_valid):
#     """
#     Simplify `data` subject to `is_valid(data)`.
# 
#     `data` is any JSON-form data (strings, bools, None, ints, floats, lists,
#     and dicts). This is roughly analogous to the concept of `shrink` from
#     `QuickCheck`.
# 
#     It's used in `bugpoint`.
#     """
#     # This is in principle recursive, but we do this with explicit iteration
#     # to save on stack space.
# 
#     any_changes = True
#     while any_changes:
#         try:
#             shrinker = _SHRINKERS[type(data)]
#         except KeyError:
#             # Unshrinkable type
#             return data
#         data, any_changes = shrinker(data, is_valid)
#     return data


# Path: jacquard/tests/test_utils_dev.py
from jacquard.utils_dev import shrink


def test_strings_shrink_by_cutting_off_start():
    assert shrink("bees", lambda x: x.endswith("s")) == "s"


def test_strings_shrink_by_cutting_off_from_both_ends():
    assert shrink("bees", lambda x: "ee" in x) == "ee"


def test_unshrinkable_strings_are_not_shrunk():
    assert shrink("bees", lambda x: x == "bees") == "bees"


def test_strings_shrink_to_a_where_possible():
    assert shrink("bees", lambda x: len(x) >= 2) == "aa"


def test_empty_string_is_unshrunk():
    assert shrink("", lambda x: True) == ""


def test_empty_list_is_unshrunk():
    assert shrink([], lambda x: True) == []


def test_lists_shrunk_by_cutting_off_from_both_ends():
    assert shrink(list("bees"), lambda x: "ee" in "".join(x)) == ["e", "e"]


def test_lists_shrink_to_the_empty_list():

    assert shrink([1, 2, 3], lambda x: True) == []