def test_filter(items): c = collect(items) assert type(items)([2, 1]) == c.filter(lambda x: x < 3).all() assert type(items)([2, 3, 1]) == c.all() # immutable
def test_avg(items): c = collect(items) assert -207.97 == round(c.avg(), 2)
def test_count(items): c = collect(items) assert 2 == c.count()
def test_reduce(items): c = collect(items) assert 6 == c.reduce(lambda x, y: x + y) assert type(items)([1, 2, 3]) == c.all() # immutable
def test_slice_negative_start(items): c = collect(items) assert type(items)([5, 6, 7]) == c.slice(-3).all()
def test_collection_is_not_empty(items): c = collect(items) assert not c.is_empty()
def test_last_returns_none_when_empty(): c = collect() assert None is c.last()
def test_slice_negative_start_stop_step(items): c = collect(items) assert type(items)([6, 4]) == c.slice(-2, -5, -2).all()
def test_slice_is_immutable(items): c = collect(items) assert type(items)([2, 3]) == c.slice(1).all() assert type(items)([1, 2, 3]) == c.all() # immutable
def test_slice_negative_start_positive_stop(items): c = collect(items) assert type(items)([4, 5, 6]) == c.slice(-4, 6).all()
def test_slice_step(items): c = collect(items) assert type(items)([3, 5]) == c.slice(2, 6, 2).all()
def test_slice_negative_start_negative_stop(items): c = collect(items) assert type(items)([3, 4, 5]), c.slice(-5, -2).all()
def test_append_one(items): c = collect(items) assert type(items)(['foo', 'bar', 'baz']) == c.append('baz').all() assert type(items)(['foo', 'bar']) == c.all() # immutable
def test_slice_stop(items): c = collect(items) assert type(items)([3, 4, 5]) == c.slice(2, 5).all()
def test_first_returns_first_item(items): c = collect(items) assert 'foo' == c.first()
def test_sum(items): c = collect(items) assert -623.9 == c.sum()
def test_all_returns_wrapped_items(items): c = collect(items) assert c.all() == items
def test_take(items): c = collect(items) assert type(items)(['foo', 'bar']) == c.take(2).all()
def test_last_returns_last_item(items): c = collect(items) assert 'bar' == c.last()
def test_take_last(items): c = collect(items) assert type(items)(['bar', 'baz']) == c.take(-2).all()
def test_map(items): c = collect(items) assert type(items)(['oof', 'rab']) == c.map(lambda s: s[::-1]).all() assert type(items)(['foo', 'bar']) == c.all() # immutable
def test_append_multiple(items): c = collect(items) assert type(items)(['foo', 'bar', ['baz', 'qux']]) == c.append('bar', ['baz', 'qux']).all()
def test_reverse(items): c = collect(items) assert type(items)(['baz', 'bar', 'foo']) == c.reverse().all() assert type(items)(['foo', 'bar', 'baz']) == c.all() # immutable
def test_slice_start(items): c = collect(items) assert type(items)([4, 5, 6, 7]) == c.slice(3).all()