def test_one_returns_item_if_list_has_one_item(): list = List(['Only you.']) actual = list.one() expected = 'Only you.' assert actual == expected
def test_sum_returns_sum_of_list(): list = List([1, 2, 3, 4, 5]) actual = list.sum() expected = 1 + 2 + 3 + 4 + 5 assert actual == expected
def test_first_returns_value_if_list_has_diff_types(): list = List(['string', True, None, 123]) actual = list.first(lambda x: x == 123) expected = 123 assert actual == expected
def test_select_returns_values_as_strings(): list = List([123, True, None, 'Aaa', {}]) actual = list.select(lambda x: str(x)) expected = [str(123), str(True), str(None), str('Aaa'), str({})] assert actual == expected
def test_sum_returns_sum_of_characters_in_all_strings(): list = List(['asd', 'aaa', 'a', 'aa']) actual = list.sum(lambda x: len(x)) expected = 3 + 3 + 1 + 2 assert actual == expected
def test_first_raises_exception_if_list_has_not_matching_value(): list = List([ 'Erebor', 'Rivendell', 'Gondor', 'Isengard', 'Minas Ithil', 'Minas Tirith', 'Mordor' ]) with pytest.raises(Exception): list.first(lambda x: x == 'Shire')
def test_first_returns_value_when_list_has_matching_value(): list = List([ 'Erebor', 'Rivendell', 'Gondor', 'Isengard', 'Minas Ithil', 'Minas Tirith', 'Mordor' ]) actual = list.first(lambda x: x == 'Mordor') expected = 'Mordor' assert actual == expected
def test_where_returns_integers_less_then_50(): list = List([]) for i in range(100): list.append(i) actual = list.where(lambda x: x < 50) for item in actual: assert item < 50
def test_one_raises_exception_if_list_has_not_one_item(): list = List([ 'We', 'are', 'the', 'champions' ]) with pytest.raises(Exception): list.one()
def test_all_returns_true_if_all_items_matching_predicate(): actual = List([ 'Erebor', 'Rivendell', 'Gondor', 'Isengard', 'Minas Ithil', 'Minas Tirith', 'Mordor' ]).all(lambda x: x[0].isupper()) assert actual is True
def test_append_created_new_list(): actual = List([ 'Erebor', 'Rivendell', 'Gondor', 'Isengard', 'Minas Ithil', 'Minas Tirith', ]).append('asd')\ .append('q')\ assert 'asd' in actual and 'q' in actual
def test_all_returns_false_if_one_item_does_not_matching_predicate(): actual = List([ 'Erebor', 'Rivendell', 'Gondor', 'Isengard', 'Minas Ithil', 'Minas Tirith', 'Mordor', 'city' ]).all(lambda x: x[0].isupper()) assert actual is False
def test_where_returns_strings_started_with_capital_letter(): list = List([ 'String', None, 123, 'another string', lambda x: x + 1 ]) actual = list\ .where(lambda x: type(x) is str)\ .where(lambda x: x[0].isupper()) expected = [ 'String' ] assert actual == expected
def test_where_returns_words(): init = List(['My name is... What?', 'Knife', 'No rest for the wicked', 'Chair', 'Avada', 'Kedavra' ]) actual = init.where(lambda x: ' ' not in x) expected = [ 'Knife', 'Chair', 'Avada', 'Kedavra' ] assert actual == expected
def test_distinct_not_modify_collection(): actual = List(['A', 'B', 'C']) actual.distinct() assert actual == ['A', 'B', 'C']
def test_distinct_returns_all_values_if_no_distinct_elements(): actual = List(['a', 'b', 'c']).distinct() expected = ['a', 'b', 'c'] assert actual == expected
def test_append_not_changing_old_list(): actual = List(['A', 'B', 'C']) actual.append('D') assert actual == ['A', 'B', 'C']
def test_first_returns_first_value(): assert List(['A', 'B', 'C']).first() == 'A'
def test_first_not_modify_collection(): actual = List(['A', 'B', 'C']) actual.first() assert actual == ['A', 'B', 'C']
def test_any_returns_false_if_no_item_matching_predicate(): assert List(['A', None, False, 1]).any(lambda x: x == 2) is False
def test_any_returns_true_if_list_not_empty(): assert List(['a']).any() is True
def test_aggregate_not_modify_collection(): actual = List(['A', 'B', 'C']) actual.aggregate(lambda x, y: x + y) assert actual == List(['A', 'B', 'C'])
def test_aggregate_returns_list_sum(): actual = List([1, 2, 3, 4, 5]).aggregate(lambda x, y: x + y) expected = 1 + 2 + 3 + 4 + 5 assert actual == expected
def test_aggregate_returns_sum_of_list_plus_5(): actual = List([1, 2, 3, 4, 5]).aggregate(lambda x, y: x + y, seed=5) expected = 1 + 2 + 3 + 4 + 5 + 5 assert actual == expected
def test_aggregate_returns_string(): actual = List(['a', 'b', 'c', 'd']).aggregate(lambda x, y: x + y) expected = 'abcd' assert actual == expected
def test_any_not_modify_collection(): actual = List(['A', 'B', 'C']) actual.any() assert actual == List(['A', 'B', 'C'])
def test_empty_ctor_not_raises_exception(): list = List()
def test_any_returns_false_if_list_empty(): assert List([]).any() is False
def test_all_not_modify_collection(): actual = List(['A', 'B', 'C']) actual.all(lambda x: x[0].isupper()) assert actual == List(['A', 'B', 'C'])
def test_any_returns_true_if_one_item_matching_predicate(): assert List(['A', None, False, 1]).any(lambda x: x == 1) is True