本文整理汇总了Python中trie.Trie.nodeCount方法的典型用法代码示例。如果您正苦于以下问题:Python Trie.nodeCount方法的具体用法?Python Trie.nodeCount怎么用?Python Trie.nodeCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trie.Trie
的用法示例。
在下文中一共展示了Trie.nodeCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTrie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import nodeCount [as 别名]
class TestTrie(unittest.TestCase):
def setUp(self):
self.trie = Trie()
def _square_brackets(self, key):
return self.trie[key]
def test_basicAssignment(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
self.assertEquals(1, len(self.trie))
self.assertEquals(3, self.trie.nodeCount())
self.assertTrue("Foo" in self.trie)
self.trie["Bar"] = None
self.assertTrue("Bar" in self.trie)
def test_basicRemoval(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
del self.trie["Foo"]
self.assertRaises(KeyError, self._square_brackets, "Foo")
self.assertEquals(0, len(self.trie))
self.assertEquals(0, self.trie.nodeCount())
self.assertFalse("Foo" in self.trie)
def test_MixedTypes(self):
self.trie["Foo"] = True
self.trie[[1, 2, 3]] = True
self.assertTrue(self.trie["Foo"])
self.assertTrue(self.trie[[1, 2, 3]])
self.assertTrue([1, 2, 3] in self.trie)
self.assertTrue("Foo" in self.trie)
del self.trie[[1, 2, 3]]
self.assertFalse([1, 2, 3] in self.trie)
def test_Iteration(self):
self.trie["Foo"] = True
self.trie["Bar"] = True
self.trie["Grok"] = True
for k in self.trie:
self.assertTrue(k in self.trie)
self.assertTrue(self.trie[k])
def test_Addition(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = t2 + self.trie
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.assertTrue("Foo" in t3)
self.assertTrue("Food" in t3)
def test_Subtraction(self):
self.trie["Food"] = True
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = self.trie - t2
t4 = t2 - self.trie
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.assertTrue("Foo" in t3)
self.assertFalse("Food" in t3)
self.assertFalse("Foo" in t4)
self.assertFalse("Food" in t4)
def test_SelfAdd(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.trie += t2
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in self.trie)
def test_SelfSub(self):
self.trie["Foo"] = True
self.trie["Food"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.trie -= t2
self.assertFalse("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
def test_SelfGet(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
#.........这里部分代码省略.........
示例2: TestTrie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import nodeCount [as 别名]
class TestTrie(unittest.TestCase):
def setUp(self):
self.trie = Trie()
def _square_brackets(self, key):
return self.trie[key]
def test_basicAssignment(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
self.assertEquals(1, len(self.trie))
self.assertEquals(3, self.trie.nodeCount())
self.assertTrue("Foo" in self.trie)
self.trie["Bar"] = None
self.assertTrue("Bar" in self.trie)
def test_basicRemoval(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
del self.trie["Foo"]
self.assertRaises(KeyError, self._square_brackets, "Foo")
self.assertEquals(0, len(self.trie))
self.assertEquals(0, self.trie.nodeCount())
self.assertFalse("Foo" in self.trie)
def test_MixedTypes(self):
self.trie["Foo"] = True
self.trie[[1, 2, 3]] = True
self.assertTrue(self.trie["Foo"])
self.assertTrue(self.trie[[1, 2, 3]])
self.assertTrue([1, 2, 3] in self.trie)
self.assertTrue("Foo" in self.trie)
del self.trie[[1, 2, 3]]
self.assertFalse([1, 2, 3] in self.trie)
def test_Iteration(self):
self.trie["Foo"] = True
self.trie["Bar"] = True
self.trie["Grok"] = True
for k in self.trie:
self.assertTrue(k in self.trie)
self.assertTrue(self.trie[k])
def test_Addition(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = t2 + self.trie
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.assertTrue("Foo" in t3)
self.assertTrue("Food" in t3)
def test_Subtraction(self):
self.trie["Food"] = True
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = self.trie - t2
t4 = t2 - self.trie
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.assertTrue("Foo" in t3)
self.assertFalse("Food" in t3)
self.assertFalse("Foo" in t4)
self.assertFalse("Food" in t4)
def test_SelfAdd(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.trie += t2
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in self.trie)
def test_SelfSub(self):
self.trie["Foo"] = True
self.trie["Food"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.trie -= t2
self.assertFalse("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
def test_SelfGet(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
#.........这里部分代码省略.........
示例3: TestTrie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import nodeCount [as 别名]
class TestTrie(unittest.TestCase):
def setUp(self):
self.trie = Trie()
def _square_brackets(self, key):
return self.trie[key]
def test_basicAssignment(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
self.assertEquals(1, len(self.trie))
self.assertEquals(3, self.trie.nodeCount())
self.assertTrue("Foo" in self.trie)
self.trie["Bar"] = None
self.assertTrue("Bar" in self.trie)
def test_basicRemoval(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
del self.trie["Foo"]
self.assertRaises(KeyError, self._square_brackets, "Foo")
self.assertEquals(0, len(self.trie))
self.assertEquals(0, self.trie.nodeCount())
self.assertFalse("Foo" in self.trie)
def test_MixedTypes(self):
self.trie["Foo"] = True
self.trie[[1, 2, 3]] = True
self.assertTrue(self.trie["Foo"])
self.assertTrue(self.trie[[1, 2, 3]])
self.assertTrue([1, 2, 3] in self.trie)
self.assertTrue("Foo" in self.trie)
del self.trie[[1, 2, 3]]
self.assertFalse([1, 2, 3] in self.trie)
def test_Iteration(self):
self.trie["Foo"] = True
self.trie["Bar"] = True
self.trie["Grok"] = True
for k in self.trie:
self.assertTrue(k in self.trie)
self.assertTrue(self.trie[k])
def test_Addition(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = t2 + self.trie
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.assertTrue("Foo" in t3)
self.assertTrue("Food" in t3)
def test_Subtraction(self):
self.trie["Food"] = True
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = self.trie - t2
t4 = t2 - self.trie
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.assertTrue("Foo" in t3)
self.assertFalse("Food" in t3)
self.assertFalse("Foo" in t4)
self.assertFalse("Food" in t4)
def test_SelfAdd(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.trie += t2
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in self.trie)
def test_SelfSub(self):
self.trie["Foo"] = True
self.trie["Food"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.trie -= t2
self.assertFalse("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
def test_SelfGet(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
#.........这里部分代码省略.........
示例4: TestTrie
# 需要导入模块: from trie import Trie [as 别名]
# 或者: from trie.Trie import nodeCount [as 别名]
class TestTrie(unittest.TestCase):
def setUp(self):
self.trie = Trie()
def _square_brackets(self, key):
return self.trie[key]
def test_basicAssignment(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
self.assertEquals(1, len(self.trie))
self.assertEquals(3, self.trie.nodeCount())
self.assertTrue("Foo" in self.trie)
self.trie["Bar"] = None
self.assertTrue("Bar" in self.trie)
def test_basicRemoval(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
del self.trie["Foo"]
self.assertRaises(KeyError, self._square_brackets, "Foo")
self.assertEquals(0, len(self.trie))
self.assertEquals(0, self.trie.nodeCount())
self.assertFalse("Foo" in self.trie)
def test_MixedTypes(self):
self.trie["Foo"] = True
self.trie[[1, 2, 3]] = True
self.assertTrue(self.trie["Foo"])
self.assertTrue(self.trie[[1, 2, 3]])
self.assertTrue([1, 2, 3] in self.trie)
self.assertTrue("Foo" in self.trie)
del self.trie[[1, 2, 3]]
self.assertFalse([1, 2, 3] in self.trie)
def test_Iteration(self):
self.trie["Foo"] = True
self.trie["Bar"] = True
self.trie["Grok"] = True
for k in self.trie:
self.assertTrue(k in self.trie)
self.assertTrue(self.trie[k])
def test_Addition(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = t2 + self.trie
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.assertTrue("Foo" in t3)
self.assertTrue("Food" in t3)
def test_Subtraction(self):
self.trie["Food"] = True
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
t3 = self.trie - t2
t4 = t2 - self.trie
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.assertTrue("Foo" in t3)
self.assertFalse("Food" in t3)
self.assertFalse("Foo" in t4)
self.assertFalse("Food" in t4)
def test_SelfAdd(self):
self.trie["Foo"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Foo" in self.trie)
self.assertFalse("Food" in self.trie)
self.assertTrue("Food" in t2)
self.assertFalse("Foo" in t2)
self.trie += t2
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in self.trie)
def test_SelfSub(self):
self.trie["Foo"] = True
self.trie["Food"] = True
t2 = Trie()
t2["Food"] = True
self.assertTrue("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
self.trie -= t2
self.assertFalse("Food" in self.trie)
self.assertTrue("Foo" in self.trie)
self.assertTrue("Food" in t2)
def test_SelfGet(self):
self.trie["Foo"] = True
self.assertTrue(self.trie["Foo"])
self.assertRaises(KeyError, self._square_brackets, "Food")
#.........这里部分代码省略.........