class TestMeasureStride: @given(r=ranges()) def test_measure_range_stride(self, r): s = measure_stride(r) assert s == r.step @given(r=ranges(min_size=2, max_size=1000)) def test_measure_list_stride_regular(self, r): t = list(r) s = measure_stride(t) assert s == r.step @given(r=ranges(min_size=2, max_size=1000)) def test_measure_list_stride_irregular(self, r): t = list(r) + list(r) s = measure_stride(t) assert s is None @given(s=sequences(min_size=1, max_size=1)) def test_stride_of_sequence_of_one_is_none(self, s): assert measure_stride(s) is None @given(s=sequences(max_size=0)) def test_stride_of_empty_sequence_is_none(self, s): assert measure_stride(s) is None
class TestLast: @given(s=sequences(min_size=1, max_size=100)) def test_last_sequences(self, s): assert last(s) == s[-1] @given(s=sequences(min_size=1, max_size=100)) def test_last_iterable(self, s): assert last(iter(s)) == s[-1] def test_empty_iterable_raises_value_error(self): r = range(0, 0) with raises(ValueError): last(r)
class TestFirst: @given(s=sequences(min_size=1, max_size=100)) def test_first_sequences(self, s): assert first(s) == s[0] def test_empty_iterable_raises_value_error(self): r = range(0, 0) with raises(ValueError): first(r)
class TestMinMax: def test_empty_iterable_raises_value_error(self): r = range(0, 0) with raises(ValueError): minmax(r) @given(s=sequences(min_size=1, max_size=100)) def test_minmax_sequences(self, s): a, b = minmax(s) assert a == min(s) assert b == max(s)
from collections import deque from hypothesis import given, assume from hypothesis.strategies import data, integers from pytest import raises from segpy.reversed_sequence_view import ReversedSequenceView from test.predicates import check_balanced from test.strategies import sequences @given(seq=sequences()) def test_contains(seq): rev = ReversedSequenceView(seq) assert all(item in rev for item in seq) @given(seq=sequences()) def test_length(seq): rev = ReversedSequenceView(seq) assert len(rev) == len(seq) @given(seq=sequences()) def test_iteration(seq): rev = ReversedSequenceView(seq) assert all(a == b for a, b in zip(rev, reversed(seq))) @given(seq=sequences()) def test_get_item(seq):
class TestIsSorted: @given(r=sequences(min_size=2, unique=True)) def test_is_sequence_sorted_ascending_positive(self, r): s = sorted(r) assert is_sorted(s, reverse=False, distinct=True) @given(r=sequences(min_size=2)) def test_is_sequence_sorted_ascending_negative(self, r): s = sorted(r, reverse=True) assert not is_sorted(s, reverse=False, distinct=True) @given(r=sequences(min_size=2, unique=True)) def test_is_sequence_sorted_descending_positive(self, r): s = sorted(r, reverse=True) assert is_sorted(s, reverse=True, distinct=True) @given(r=sequences(min_size=2)) def test_is_sequence_sorted_descending_negative(self, r): s = sorted(r, reverse=False) assert not is_sorted(s, reverse=True, distinct=True) @given(r=sequences(min_size=2, max_size=100)) def test_is_sequence_sorted_ascending_positive_duplicates(self, r): s = sorted(r + r, reverse=False) assert is_sorted(s, reverse=False) @given(r=sequences(min_size=2, max_size=100, unique=True)) def test_is_sequence_sorted_ascending_negative_duplicates(self, r): s = sorted(r + r, reverse=True) assert not is_sorted(s, reverse=False) @given(r=sequences(min_size=2, max_size=100)) def test_is_sequence_sorted_descending_positive_duplicates(self, r): s = sorted(r + r, reverse=True) assert is_sorted(s, reverse=True) @given(r=sequences(min_size=2, max_size=100, unique=True)) def test_is_sequence_sorted_descending_negative_duplicates(self, r): s = sorted(r + r, reverse=False) assert not is_sorted(s, reverse=True) def test_empty_sequence_is_sorted_ascending(self): assert is_sorted([], reverse=False, distinct=True) def test_empty_sequence_is_sorted_descending(self): assert is_sorted([], reverse=True, distinct=True) @given(r=sequences(min_size=1, max_size=1)) def test_sequence_of_one_is_sorted_ascending(self, r): assert is_sorted(r, reverse=False, distinct=True) @given(r=sequences(min_size=1, max_size=1)) def test_sequence_of_one_is_sorted_descending(self, r): assert is_sorted(r, reverse=True, distinct=True) @given(r=ranges(min_size=2, min_step_value=1)) def test_is_range_sorted_ascending_positive(self, r): assert is_sorted(r, reverse=False, distinct=True) @given(r=ranges(min_size=2, max_step_value=-1)) def test_is_range_sorted_ascending_negative(self, r): assert not is_sorted(r, reverse=False, distinct=True) @given(r=ranges(min_size=2, max_step_value=-1)) def test_is_range_sorted_descending_positive(self, r): assert is_sorted(r, reverse=True, distinct=True) @given(r=ranges(min_size=2, min_step_value=1)) def test_is_range_sorted_descending_negative(self, r): assert not is_sorted(r, reverse=True, distinct=True) @given(r=ranges(max_size=0)) def test_empty_range_is_sorted_ascending(self, r): assert is_sorted(r, reverse=False, distinct=True) @given(r=ranges(max_size=0)) def test_empty_range_is_sorted_descending(self, r): assert is_sorted(r, reverse=True, distinct=True) @given(r=ranges(max_size=1, min_size=1)) def test_range_of_one_is_sorted_ascending(self, r): assert is_sorted(r, reverse=False, distinct=True) @given(r=ranges(max_size=1, min_size=1)) def test_range_of_one_is_sorted_descending(self, r): assert is_sorted(r, reverse=True, distinct=True)
class TestMakeSortedDistinctSequence: @given(r=ranges(min_step_value=1)) def test_ascending_range_result_is_ascending(self, r): seq = make_sorted_distinct_sequence(r, sense=SortSense.ascending) assert seq.step > 0 @given(r=ranges(min_step_value=1)) def test_ascending_range_result_is_descending(self, r): seq = make_sorted_distinct_sequence(r, sense=SortSense.descending) assert seq.step < 0 @given(r=ranges(max_step_value=-1)) def test_descending_range_result_is_ascending(self, r): seq = make_sorted_distinct_sequence(r, sense=SortSense.ascending) assert seq.step > 0 @given(r=ranges(max_step_value=-1)) def test_descending_range_result_is_descending(self, r): seq = make_sorted_distinct_sequence(r, sense=SortSense.descending) assert seq.step < 0 @given(r=ranges()) def test_range_sense_is_preserved(self, r): seq = make_sorted_distinct_sequence(r, sense=None) assert sgn(r.step) == sgn(seq.step) def test_range_with_invalid_sense_value_raises_type_error(self): with raises(TypeError): make_sorted_distinct_sequence(range(1, 2), 42) def test_list_with_invalid_sense_value_raises_type_error(self): with raises(TypeError): make_sorted_distinct_sequence([1, 2], 42) @given(r=sequences(min_size=2, unique=True)) def test_ascending_sequence_result_is_ascending(self, r): s = sorted(r) seq = make_sorted_distinct_sequence(s, sense=SortSense.ascending) assert is_sorted(seq, reverse=False, distinct=True) @given(r=sequences(min_size=2, unique=True)) def test_ascending_sequence_result_is_descending(self, r): s = sorted(r) seq = make_sorted_distinct_sequence(s, sense=SortSense.descending) assert is_sorted(seq, reverse=True, distinct=True) @given(r=sequences(min_size=2, unique=True)) def test_descending_sequence_result_is_ascending(self, r): s = sorted(r, reverse=True) seq = make_sorted_distinct_sequence(s, sense=SortSense.ascending) assert is_sorted(seq, reverse=False, distinct=True) @given(r=sequences(min_size=2, unique=True)) def test_descending_sequence_result_is_descending(self, r): s = sorted(r, reverse=True) seq = make_sorted_distinct_sequence(s, sense=SortSense.descending) assert is_sorted(seq, reverse=True, distinct=True) @given(r=sequences(min_size=2, unique=True), b=booleans()) def test_sequence_sense_is_preserved(self, r, b): s = sorted(r, reverse=b) seq = make_sorted_distinct_sequence(s, sense=None) ascending = is_sorted(seq, reverse=False, distinct=True) descending = is_sorted(seq, reverse=True, distinct=True) assert b == descending != ascending