Example #1
0
    def test_get(self) -> None:
        """Test getting an element by its index."""
        heap = ExtHeapQueue()

        heap.push(1.01, "101")

        assert heap.get(0) == "101"

        heap.push(2.02, "202")
        heap.push(3.03, "303")

        possibilities = {"101", "202", "303"}

        assert heap.get(0) in possibilities
        assert heap.get(1) in possibilities
        assert heap.get(2) in possibilities
Example #2
0
    def test_get_out_of_range(self) -> None:
        """Test raising an exception when accessing out of range."""
        heap = ExtHeapQueue()

        with pytest.raises(IndexError, match="index out of range"):
            heap.get(0)

        with pytest.raises(IndexError, match="index out of range"):
            heap.get(110)

        with pytest.raises(IndexError, match="index out of range"):
            heap.get(199)

        heap.push(1.1, "11")
        heap.push(2.2, "22")

        with pytest.raises(IndexError, match="index out of range"):
            heap.get(110)