Skip to content

Commit 571dcd1

Browse files
Added tests (#222)
1 parent 6cc969c commit 571dcd1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pydatastructs import MAryTree
2+
3+
def test_MAryTree():
4+
m = MAryTree(1, 1)
5+
assert str(m) == '[(1, 1)]'

pydatastructs/utils/misc_util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def add_children(self, *children):
148148
for child in children:
149149
self.children.append(child)
150150

151+
def __str__(self):
152+
return str((self.key, self.data))
153+
151154

152155
class LinkedListNode(Node):
153156
"""

pydatastructs/utils/tests/test_misc_util.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from pydatastructs.utils import AdjacencyListGraphNode, AdjacencyMatrixGraphNode, GraphEdge
1+
from pydatastructs.utils import (AdjacencyListGraphNode, AdjacencyMatrixGraphNode,
2+
GraphEdge, BinomialTreeNode, MAryTreeNode)
23
from pydatastructs.utils.raises_util import raises
34

45
def test_AdjacencyListGraphNode():
@@ -25,3 +26,15 @@ def test_GraphEdge():
2526
g_2 = AdjacencyListGraphNode('g_2', 2)
2627
e = GraphEdge(g_1, g_2, value=2)
2728
assert str(e) == "('g_1', 'g_2')"
29+
30+
def test_BinomialTreeNode():
31+
b = BinomialTreeNode(1,1)
32+
b.add_children(*[BinomialTreeNode(i,i) for i in range(2,10)])
33+
assert str(b) == '(1, 1)'
34+
assert str(b.children) == "['(2, 2)', '(3, 3)', '(4, 4)', '(5, 5)', '(6, 6)', '(7, 7)', '(8, 8)', '(9, 9)']"
35+
36+
def test_MAryTreeNode():
37+
m = MAryTreeNode(1, 1)
38+
m.add_children(*[i for i in range(2,10)])
39+
assert str(m) == "(1, 1)"
40+
assert str(m.children) == "['2', '3', '4', '5', '6', '7', '8', '9']"

0 commit comments

Comments
 (0)