mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
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:
parent
0101dd42dc
commit
05a5cdacc3
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user