コード例 #1
0
def test_unshift():
    assert ImmutableList.of(1, 2).unshift(0) == ImmutableList.of(0, 1, 2)
コード例 #2
0
def test_append():
    assert ImmutableList.of(1, 2).append(3) == ImmutableList.of(1, 2, 3)
コード例 #3
0
def test_find_positive():
    assert ImmutableList.of(1, 2, 3, 4).find(lambda item: item % 2 == 0) == 2
コード例 #4
0
def test_find_negative():
    assert ImmutableList.of(1, 2, 3, 4).find(lambda item: item < 0) is None
コード例 #5
0
def test_plus_operator_exception():
    with pytest.raises(ValueError):
        ImmutableList.of(0) + [1]
コード例 #6
0
def test_eq():
    assert len(ImmutableList()) == 0
    assert len(ImmutableList(1)) == 1
    assert len(ImmutableList(1).unshift(0)) == 2
コード例 #7
0
def test_empty_filter():
    assert ImmutableList.of(
        1, 2, 3, 4).filter(lambda item: False) == ImmutableList.empty()
コード例 #8
0
def test_plus_operator():
    assert ImmutableList.of(1, 2) + ImmutableList.of(3, 4) == ImmutableList.of(
        1, 2, 3, 4)
コード例 #9
0
def test_filter():
    assert ImmutableList.of(
        1, 2, 3,
        4).filter(lambda item: item % 2 == 0) == ImmutableList.of(2, 4)
コード例 #10
0
def test_map():
    assert ImmutableList.of(1, 2, 3,
                            4).map(lambda item: item + 1) == ImmutableList.of(
                                2, 3, 4, 5)
コード例 #11
0
def test_of():
    assert ImmutableList.of(1, 2, 3, 4).to_list() == [1, 2, 3, 4]
コード例 #12
0
def test_to_list():
    assert ImmutableList(1).unshift(0).to_list() == [0, 1]
コード例 #13
0
def test_immutable():
    lst = ImmutableList(1)
    lst2 = lst.append(2)
    assert lst is not lst2