def test_to_range() -> None: r = Range(1, "to", 8) assert r.left == 1 assert r.direction == "to" assert r.right == 8 assert len(r) == 8 assert list(r) == [1, 2, 3, 4, 5, 6, 7, 8] assert list(reversed(r)) == [8, 7, 6, 5, 4, 3, 2, 1] assert r[0] == 1 assert r[7] == 8 with pytest.raises(IndexError): r[8] assert r[3:7] == Range(4, "to", 7) assert 8 in r assert 10 not in r assert r.index(7) == 6 with pytest.raises(ValueError): r.index(9) assert r.count(4) == 1 assert r.count(10) == 0
def test_downto_range() -> None: r = Range(4, "downto", -3) assert r.left == 4 assert r.direction == "downto" assert r.right == -3 assert len(r) == 8 assert list(r) == [4, 3, 2, 1, 0, -1, -2, -3] assert list(reversed(r)) == [-3, -2, -1, 0, 1, 2, 3, 4] assert r[0] == 4 assert r[7] == -3 with pytest.raises(IndexError): r[8] assert r[3:7] == Range(1, "downto", -2) assert 0 in r assert 10 not in r assert r.index(2) == 2 with pytest.raises(ValueError): r.index(9) assert r.count(4) == 1 assert r.count(10) == 0
def test_null_range() -> None: r = Range(1, "downto", 4) assert r.left == 1 assert r.direction == "downto" assert r.right == 4 assert len(r) == 0 assert list(r) == [] assert list(reversed(r)) == [] with pytest.raises(IndexError): r[0] assert 2 not in r with pytest.raises(ValueError): r.index(4) assert r.count(4) == 0