本文整理汇总了Python中stack.Stack.get_size方法的典型用法代码示例。如果您正苦于以下问题:Python Stack.get_size方法的具体用法?Python Stack.get_size怎么用?Python Stack.get_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack.Stack
的用法示例。
在下文中一共展示了Stack.get_size方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestStack
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import get_size [as 别名]
class TestStack(unittest.TestCase):
def setUp(self):
self.stack = Stack()
def test_init(self):
self.assertEqual(self.stack.get_size(), 0)
new_stack = Stack("Bob")
self.assertEqual(new_stack.get_size(), 1)
def test_push(self):
initial_size = self.stack.get_size()
self.stack.push("Bob")
self.assertEqual(self.stack.get_size(), initial_size + 1)
def test_peek(self):
self.stack.push("Adrian")
self.stack.push("Bob")
self.stack.push("Claire")
self.assertEqual(self.stack.peek(), "Claire")
def test_pop(self):
self.stack.push("Adrian")
self.stack.push("Bob")
self.stack.push("Claire")
initial_size = self.stack.get_size()
popped_item = self.stack.pop()
self.assertEqual(popped_item, "Claire")
self.assertEqual(self.stack.get_size(), initial_size - 1)
def test_clear(self):
self.stack.push("Adrian")
self.stack.push("Bob")
self.stack.push("Claire")
self.assertEqual(self.stack.get_size(), 3)
self.stack.clear()
self.assertEqual(self.stack.get_size(), 0)
def test_get_size(self):
self.stack.push("Bob")
self.assertEqual(self.stack.linked_list.size, self.stack.get_size())
示例2: StackTest
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import get_size [as 别名]
class StackTest(unittest.TestCase):
def setUp(self):
self.stack = Stack([1,2,3])
def test_is_empty(self):
self.assertEqual(self.stack.is_empty(), False)
def test_peek(self):
self.assertEqual(self.stack.peek(), self.stack[-1])
self.assertEqual(len(self.stack), 3)
def test_push(self):
item = 1
self.stack.push(item)
self.assertEqual(len(self.stack), 4)
self.assertEqual(self.stack.peek(), item)
def test_pop(self):
self.assertEqual(self.stack[-1], self.stack.pop())
self.assertEqual(len(self.stack), 2)
def test_get_size(self):
self.assertEqual(self.stack.get_size(), len(self.stack))
示例3: test_init
# 需要导入模块: from stack import Stack [as 别名]
# 或者: from stack.Stack import get_size [as 别名]
def test_init(self):
self.assertEqual(self.stack.get_size(), 0)
new_stack = Stack("Bob")
self.assertEqual(new_stack.get_size(), 1)