Added doctest to skew_heap.py (#11147)

* Added doctest to skew_heap.py

* Update skew_heap.py

* Update data_structures/heap/skew_heap.py

Co-authored-by: Saptadeep Banerjee  <69459134+imSanko@users.noreply.github.com>

* Update skew_heap.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update skew_heap.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Saptadeep Banerjee <69459134+imSanko@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Suyash Dongre 2024-01-18 18:09:27 +05:30 committed by GitHub
parent 0101dd42dc
commit 05a5cdacc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,14 +21,55 @@ class SkewNode(Generic[T]):
@property
def value(self) -> T:
"""Return the value of the node."""
"""
Return the value of the node.
>>> SkewNode(0).value
0
>>> SkewNode(3.14159).value
3.14159
>>> SkewNode("hello").value
'hello'
>>> SkewNode(None).value
>>> SkewNode(True).value
True
>>> SkewNode([]).value
[]
>>> SkewNode({}).value
{}
>>> SkewNode(set()).value
set()
>>> SkewNode(0.0).value
0.0
>>> SkewNode(-1e-10).value
-1e-10
>>> SkewNode(10).value
10
>>> SkewNode(-10.5).value
-10.5
>>> SkewNode().value
Traceback (most recent call last):
...
TypeError: SkewNode.__init__() missing 1 required positional argument: 'value'
"""
return self._value
@staticmethod
def merge(
root1: SkewNode[T] | None, root2: SkewNode[T] | None
) -> SkewNode[T] | None:
"""Merge 2 nodes together."""
"""
Merge 2 nodes together.
>>> SkewNode.merge(SkewNode(10),SkewNode(-10.5)).value
-10.5
>>> SkewNode.merge(SkewNode(10),SkewNode(10.5)).value
10
>>> SkewNode.merge(SkewNode(10),SkewNode(10)).value
10
>>> SkewNode.merge(SkewNode(-100),SkewNode(-10.5)).value
-100
"""
if not root1:
return root2