Exemplo n.º 1
0
def test_range_iter():
    r = range(10)
    for i, v in enumerate(r):
        assert r[i] == v
    r = range(3, 10, 3)
    for i, v in enumerate(r):
        assert r[i] == v
Exemplo n.º 2
0
def test_range_iter():
    r = range(10)
    for i, v in enumerate(r):
        assert r[i] == v
    r = range(3, 10, 3)
    for i, v in enumerate(r):
        assert r[i] == v
Exemplo n.º 3
0
def test_range_reversed():
    r = range(10)
    for i, v in enumerate(reversed(r)):
        assert r[::-1][i] == v
    r = range(3, 10, 3)
    for i, v in enumerate(reversed(r)):
        assert r[::-1][i] == v
Exemplo n.º 4
0
def test_range_reversed():
    r = range(10)
    for i, v in enumerate(reversed(r)):
        assert r[::-1][i] == v
    r = range(3, 10, 3)
    for i, v in enumerate(reversed(r)):
        assert r[::-1][i] == v
Exemplo n.º 5
0
def test_vector_coverage():
    # Miscellaneous tests purely for the sake of coverage
    assert rmod(3, 3, range(10)) == set()
    assert rmod(3, 2, []) == set()
    with pytest.raises(ValueError):
        rmod(0, 1, range(10))
    with pytest.raises(ValueError):
        rdiv(0, 1)
Exemplo n.º 6
0
def test_vector_coverage():
    # Miscellaneous tests purely for the sake of coverage
    assert rmod(3, 3, range(10)) == set()
    assert rmod(3, 2, []) == set()
    with pytest.raises(ValueError):
        rmod(0, 1, range(10))
    with pytest.raises(ValueError):
        rdiv(0, 1)
Exemplo n.º 7
0
def test_range_init():
    assert range(10).start == 0
    assert range(1, 10).step == 1
    assert range(3, 10, 3) == range(3, 10, 3)
    with pytest.raises(ValueError):
        range(0, 10, 0)
    with pytest.raises(TypeError):
        range(0.0, 10.0, 0.5)
Exemplo n.º 8
0
def test_range_init():
    assert range(10).start == 0
    assert range(1, 10).step == 1
    assert range(3, 10, 3) == range(3, 10, 3)
    with pytest.raises(ValueError):
        range(0, 10, 0)
    with pytest.raises(TypeError):
        range(0.0, 10.0, 0.5)
Exemplo n.º 9
0
def test_range_index():
    assert range(10).index(0) == 0
    assert range(10).index(9) == 9
    assert range(3, 10, 3).index(3) == 0
    assert range(3, 10, 3).index(9) == 2
    assert range(3, 10, 3)[::-1].index(9) == 0
    with pytest.raises(ValueError):
        range(10).index(10)
Exemplo n.º 10
0
def test_range_index():
    assert range(10).index(0) == 0
    assert range(10).index(9) == 9
    assert range(3, 10, 3).index(3) == 0
    assert range(3, 10, 3).index(9) == 2
    assert range(3, 10, 3)[::-1].index(9) == 0
    with pytest.raises(ValueError):
        range(10).index(10)
Exemplo n.º 11
0
def test_range_get():
    r = range(10)
    t = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for v1, v2 in zip_longest(r, t):
        assert v1 == v2
    r = range(3, 10, 3)
    t = [3, 6, 9]
    for v1, v2 in zip_longest(r, t):
        assert v1 == v2
    with pytest.raises(IndexError):
        range(10)[10]
    with pytest.raises(IndexError):
        range(10)[-11]
Exemplo n.º 12
0
def test_range_get():
    r = range(10)
    t = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for v1, v2 in zip_longest(r, t):
        assert v1 == v2
    r = range(3, 10, 3)
    t = [3, 6, 9]
    for v1, v2 in zip_longest(r, t):
        assert v1 == v2
    with pytest.raises(IndexError):
        range(10)[10]
    with pytest.raises(IndexError):
        range(10)[-11]
Exemplo n.º 13
0
def test_range_get_slice():
    assert range(10)[1:] == range(1, 10)
    assert range(10)[-5:] == range(5, 10)
    assert range(10)[20:] == range(1, 1)
    assert range(10)[:5] == range(5)
    assert range(10)[:-2] == range(8)
    assert range(10)[:20] == range(10)
    assert range(10)[1:-1] == range(1, 9)
    assert range(10)[::-1] == range(9, -1, -1)
    assert range(10)[2::-1] == range(2, -1, -1)
    assert range(3, 10, 3)[1:] == range(6, 12, 3)
    assert range(3, 10, 3)[::-1] == range(9, 0, -3)
    assert range(3, 10, 3)[2::-1] == range(9, 0, -3)
    assert range(0, 10, 3)[:-3:-1] == range(9, 3, -3)
    with pytest.raises(ValueError):
        range(10)[::0]
Exemplo n.º 14
0
def test_range_bool():
    assert range(10)
    assert not range(10, 10)
    assert range(3, 10, 3)
Exemplo n.º 15
0
def test_range_len():
    assert len(range(10)) == 10
    assert len(range(10, 10)) == 0
    assert len(range(10)[::-1]) == 10
    assert len(range(3, 10, 3)) == 3
Exemplo n.º 16
0
def test_range_equality():
    assert range(10) == range(10)
    assert range(10, 10) == range(1, 1)
    assert range(10, 11) == range(10, 9, -1)
    assert range(0, 10, 3) == range(0, 11, 3)
    assert range(0, 10, 3) != range(0, 13, 3)
    # Yeah ... this one's weird, but it matches Py3 behaviour ...
    assert range(10) != [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Exemplo n.º 17
0
def test_range_count():
    assert range(10).count(0) == 1
    assert range(10).count(10) == 0
    assert range(3, 10, 3).count(4) == 0
    assert range(3, 10, 3).count(6) == 1
Exemplo n.º 18
0
def test_range_get_slice():
    assert range(10)[1:] == range(1, 10)
    assert range(10)[-5:] == range(5, 10)
    assert range(10)[20:] == range(1, 1)
    assert range(10)[:5] == range(5)
    assert range(10)[:-2] == range(8)
    assert range(10)[:20] == range(10)
    assert range(10)[1:-1] == range(1, 9)
    assert range(10)[::-1] == range(9, -1, -1)
    assert range(10)[2::-1] == range(2, -1, -1)
    assert range(3, 10, 3)[1:] == range(6, 12, 3)
    assert range(3, 10, 3)[::-1] == range(9, 0, -3)
    assert range(3, 10, 3)[2::-1] == range(9, 0, -3)
    assert range(0, 10, 3)[:-3:-1] == range(9, 3, -3)
    with pytest.raises(ValueError):
        range(10)[::0]
Exemplo n.º 19
0
def test_range_bool():
    assert range(10)
    assert not range(10, 10)
    assert range(3, 10, 3)
Exemplo n.º 20
0
def test_range_count():
    assert range(10).count(0) == 1
    assert range(10).count(10) == 0
    assert range(3, 10, 3).count(4) == 0
    assert range(3, 10, 3).count(6) == 1
Exemplo n.º 21
0
def test_range_contains():
    assert 0 in range(10)
    assert 10 not in range(10)
    assert 3 in range(3, 10, 3)
    assert 3 in range(3, 10, 3)[::-1]
    assert 0 not in range(3, 10, 3)
Exemplo n.º 22
0
def test_range_equality():
    assert range(10) == range(10)
    assert range(10, 10) == range(1, 1)
    assert range(10, 11) == range(10, 9, -1)
    assert range(0, 10, 3) == range(0, 11, 3)
    assert range(0, 10, 3) != range(0, 13, 3)
    # Yeah ... this one's weird, but it matches Py3 behaviour ...
    assert range(10) != [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Exemplo n.º 23
0
def test_range_contains():
    assert 0 in range(10)
    assert 10 not in range(10)
    assert 3 in range(3, 10, 3)
    assert 3 in range(3, 10, 3)[::-1]
    assert 0 not in range(3, 10, 3)
Exemplo n.º 24
0
def test_range_len():
    assert len(range(10)) == 10
    assert len(range(10, 10)) == 0
    assert len(range(10)[::-1]) == 10
    assert len(range(3, 10, 3)) == 3