示例#1
0
def test_one_returns_item_if_list_has_one_item():
    list = List(['Only you.'])

    actual = list.one()
    expected = 'Only you.'

    assert actual == expected
示例#2
0
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
示例#3
0
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
示例#4
0
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
示例#5
0
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
示例#6
0
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')
示例#7
0
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
示例#8
0
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
示例#9
0
def test_one_raises_exception_if_list_has_not_one_item():
    list = List([
        'We',
        'are',
        'the',
        'champions'
    ])

    with pytest.raises(Exception):
        list.one()
示例#10
0
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
示例#11
0
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
示例#12
0
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
示例#13
0
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
示例#14
0
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
示例#15
0
def test_distinct_not_modify_collection():
    actual = List(['A', 'B', 'C'])
    actual.distinct()

    assert actual == ['A', 'B', 'C']
示例#16
0
def test_distinct_returns_all_values_if_no_distinct_elements():
    actual = List(['a', 'b', 'c']).distinct()
    expected = ['a', 'b', 'c']

    assert actual == expected
示例#17
0
def test_append_not_changing_old_list():
    actual = List(['A', 'B', 'C'])
    actual.append('D')

    assert actual == ['A', 'B', 'C']
示例#18
0
def test_first_returns_first_value():
    assert List(['A', 'B', 'C']).first() == 'A'
示例#19
0
def test_first_not_modify_collection():
    actual = List(['A', 'B', 'C'])
    actual.first()

    assert actual == ['A', 'B', 'C']
示例#20
0
def test_any_returns_false_if_no_item_matching_predicate():
    assert List(['A', None, False, 1]).any(lambda x: x == 2) is False
示例#21
0
def test_any_returns_true_if_list_not_empty():
    assert List(['a']).any() is True
示例#22
0
def test_aggregate_not_modify_collection():
    actual = List(['A', 'B', 'C'])
    actual.aggregate(lambda x, y: x + y)

    assert actual == List(['A', 'B', 'C'])
示例#23
0
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
示例#24
0
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
示例#25
0
def test_aggregate_returns_string():
    actual = List(['a', 'b', 'c', 'd']).aggregate(lambda x, y: x + y)
    expected = 'abcd'

    assert actual == expected
示例#26
0
def test_any_not_modify_collection():
    actual = List(['A', 'B', 'C'])
    actual.any()

    assert actual == List(['A', 'B', 'C'])
示例#27
0
def test_empty_ctor_not_raises_exception():
    list = List()
示例#28
0
def test_any_returns_false_if_list_empty():
    assert List([]).any() is False
示例#29
0
def test_all_not_modify_collection():
    actual = List(['A', 'B', 'C'])
    actual.all(lambda x: x[0].isupper())

    assert actual == List(['A', 'B', 'C'])
示例#30
0
def test_any_returns_true_if_one_item_matching_predicate():
    assert List(['A', None, False, 1]).any(lambda x: x == 1) is True