本文整理汇总了Python中bst.BST.minKey方法的典型用法代码示例。如果您正苦于以下问题:Python BST.minKey方法的具体用法?Python BST.minKey怎么用?Python BST.minKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bst.BST
的用法示例。
在下文中一共展示了BST.minKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BSTTestCase
# 需要导入模块: from bst import BST [as 别名]
# 或者: from bst.BST import minKey [as 别名]
class BSTTestCase(unittest.TestCase):
def setUp(self):
self.tree = BST()
self.nodes = {5: 'five', 7: 'seven', 2: 'two', 3: 'three', 1: 'one', 8: 'eight'}
for k, v in self.nodes.items():
self.tree.put(k,v)
def tearDown(self):
del self.tree
del self.nodes
def testPutGet(self):
for k, v in self.nodes.items():
self.assertEqual(v, self.tree.get(k))
for k in [4,6,9]:
self.assertIsNone(self.tree.get(k))
def testLen(self):
self.assertEqual(6, len(self.tree))
def testMinKey(self):
self.assertEqual(1, self.tree.minKey())
def testMin(self):
self.assertTupleEqual((1, 'one'), self.tree.min())
def testMaxKey(self):
self.assertEqual(8, self.tree.maxKey())
def testMax(self):
self.assertTupleEqual((8, 'eight'), self.tree.max())
def testIsEmpty(self):
self.assertFalse(self.tree.isEmpty())
self.assertTrue(BST().isEmpty())
def testItems(self):
self.assertSequenceEqual(sorted(self.nodes.items()), list(self.tree.items()))
def testKeys(self):
self.assertSequenceEqual(sorted(self.nodes.keys()), list(self.tree.keys()))
def testContains(self):
self.assertTrue(self.tree.contains(8))
self.assertFalse(self.tree.contains(13))
def testKeysBetween(self):
self.assertSequenceEqual([2,3,5], list(self.tree.keys_between(2, 6)))
def testNumKeysBetween(self):
# self.nodes = {5: 'five', 7: 'seven', 2: 'two', 3: 'three', 1: 'one', 8: 'eight'}
self.assertEqual(4, self.tree.num_between(3, 8))
def testRank(self):
self.assertEqual(2, self.tree.rank(3))