Exemple #1
0
    def test_history_depth_count_should_match_number_of_pushes(self):
        s = Stack()
        #import pdb; pdb.set_trace()
        self.assertEqual(s.history_depth_count(0), 1)
        self.assertTrue(s.is_empty())
        self.assertEqual(s.contents(), [])

        for i, v in enumerate(self.init_list):
            s.push(v)

            expected = [1] * (i + 2) + [0] * (len(self.init_list) - 1)
            for depth in range(len(self.init_list) + 1):
                self.assertEqual(s.history_depth_count(depth), expected[depth])

        depth_count = s.history_depth_count()
        self.assertEqual(s.contents(), [x for x in self.init_list])
        self.assertEqual(s.tos(), self.init_list[-1])
        self.assertEqual(depth_count, [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1),
                                       (5, 1)])

        self.assertEqual(s.max_depth(), self.max_depth)

        self.assertEqual(s.total_operations(), len(self.init_list))

        empty = None
        while empty != KStack.Empty:
            empty = s.pop()

        self.assertEqual(s.total_operations(), len(self.init_list) * 2)
Exemple #2
0
 def match_in(self, stack: Stack) -> bool:
     logging.debug("match_in in_s=%s, matching against stack=%s" %
                   (self.stack_in, stack))
     try:
         result = self.map_from_input_sig(stack.contents())
         logging.debug("match_in returns True.")
         return True
     except AssertionError:
         logging.debug("match_in returns False.")
         return False
Exemple #3
0
    def test_empty_stack_copy(self) -> None:
        s = Stack()
        self.assertEqual(str(s.contents()), '[]')

        r = s.copy()

        print("Type s = %s, Type r = %s" % (type(s), type(r)))

        x = s.tos()
        y = r.tos()
        self.assertEqual(x, y)
        self.assertEqual(len(s), 0)
        self.assertEqual(len(r), 0)
Exemple #4
0
    def test_stack_copy(self) -> None:
        s = Stack()
        s.push(1)
        s.push(2)
        s.push(3)

        self.assertEqual(str(s.contents()), '[1, 2, 3]')

        r = s.copy()

        #print("Type s = %s, Type r = %s" % (type(s),type(r)))
        self.assertEqual(type(s), type(r))

        x = s.tos()
        y = r.tos()
        self.assertEqual(x, y)

        self.assertEqual(s.pop(), r.pop())
        self.assertEqual(s.pop(), r.pop())
        self.assertEqual(s.pop(), r.pop())

        self.assertEqual(len(s), len(s))
Exemple #5
0
 def test_stack_underflow_content(self) -> None:
     s = Stack(self.init_list)
     l = len(self.init_list) + 1
     with self.assertRaises(Exception) as x:
         s.contents(l)
Exemple #6
0
 def test_stack_last_content(self) -> None:
     s = Stack(self.init_list)
     assert s.contents(4) == self.init_list[-4:]
Exemple #7
0
 def test_stack_full_content(self) -> None:
     s = Stack(self.init_list)
     assert s.contents() == self.init_list