Esempio n. 1
0
 def test_init(self):
     with self.assertRaises(TypeError):
         test_stack = LimitedStack("hello")
     with self.assertRaises(TypeError):
         test_stack = LimitedStack(None)
     with self.assertRaises(ValueError):
         test_stack = LimitedStack(-1)
Esempio n. 2
0
    def test_last_in_first_out(self):
        test_stack = LimitedStack(3)
        test_stack.push(LimitedStackTestCase.ITEM_1)
        test_stack.push(LimitedStackTestCase.ITEM_2)
        test_stack.push(LimitedStackTestCase.ITEM_3)
        self.assertEqual(3, test_stack.size())

        self.assertEqual(LimitedStackTestCase.ITEM_3, test_stack.pop())
        self.assertEqual(LimitedStackTestCase.ITEM_2, test_stack.pop())
        self.assertEqual(LimitedStackTestCase.ITEM_1, test_stack.pop())
Esempio n. 3
0
 def test_peek_size_remains(self):
     test_stack = LimitedStack(3)
     test_stack.push(LimitedStackTestCase.ITEM_1)
     self.assertEqual(LimitedStackTestCase.ITEM_1, test_stack.peek())
     self.assertEqual(1, test_stack.size())
Esempio n. 4
0
 def test_push_increases_size(self):
     test_stack = LimitedStack(3)
     test_stack.push(LimitedStackTestCase.ITEM_1)
     self.assertEqual(1, test_stack.size())
Esempio n. 5
0
 def test_base_stack_empty(self):
     test_stack = LimitedStack(3)
     self.assertEqual(0, test_stack.size())
Esempio n. 6
0
 def test_overpush(self):
     test_stack = LimitedStack(2)
     test_stack.push(LimitedStackTestCase.ITEM_1)
     test_stack.push(LimitedStackTestCase.ITEM_2)
     with self.assertRaises(Exception):
         test_stack.push(LimitedStackTestCase.ITEM_3)
Esempio n. 7
0
 def test_pop_single_item(self):
     test_stack = LimitedStack(3)
     test_stack.push(LimitedStackTestCase.ITEM_1)
     self.assertEqual(LimitedStackTestCase.ITEM_1, test_stack.pop())
     self.assertEqual(0, test_stack.size())
Esempio n. 8
0
 def test_pop_empty_stack(self):
     test_stack = LimitedStack(3)
     self.assertEqual(None, test_stack.pop())
Esempio n. 9
0
 def test_push_none(self):
     test_stack = LimitedStack(3)
     with self.assertRaises(TypeError):
         test_stack.push(None)
Esempio n. 10
0
 def test_limited_behavior(self):
     test_stack = LimitedStack(2)
     test_stack.push(STC.ITEM_3)
     test_stack.push(STC.ITEM_3)
     with self.assertRaises(test_stack.LimitedStackOverflowError):
         test_stack.push(STC.ITEM_1)