Esempio n. 1
0
	def test_peek(self):
		my_stack.push(3)
		my_stack.push(5)

		self.assertEqual(5, my_stack.peek())
		self.assertEqual(3, my_stack.peek(1))
		self.assertEqual(5, my_stack.peek())
Esempio n. 2
0
	def test_peek(self):
		my_stack.push(3)
		my_stack.push(5)

		self.assertEqual(my_stack.peek(), 5)
		self.assertEqual(my_stack.peek(1), 3)
		self.assertEqual(my_stack.peek(), 5)
Esempio n. 3
0
	def test_multiple_pushes_pops(self):
		items = [i for i in range(10)]

		for i in items:
			my_stack.push(i)

		received_items = []
		for _ in items:
			received_items.append(my_stack.pop())

		self.assertEqual(items[::-1], received_items)
Esempio n. 4
0
	def test_multiple_pushes_pops(self):
		items = [i for i in range(10)]

		for i in items:
			my_stack.push(i)

		received_items = []
		for _ in items:
			received_items.append(my_stack.pop())

		# Добавила преобразование в list() первого аргумента, иначе типы сравниваемых объектов не совпадали
		self.assertEqual(list(reversed(items)), received_items)
def dfs(g: nx.Graph, start_node: Hashable) -> List[Hashable]:
    """
	Do an depth-first search and returns list of nodes in the visited order

	:param g: input graph
	:param start_node: starting node of search
	:return: list of nodes in the visited order
	"""
    visited = []
    st.push(start_node)
    while st.leng() > 0:
        start_node = st.pop()
        visited.append(start_node)
        neighbors = list(g.neighbors(start_node))
        for neigh in neighbors:
            if neigh not in visited:
                st.push(neigh)
    return visited
def check_brackets(brackets_row: str) -> bool:
    """
	Check whether input string is a valid bracket sequence
	Valid examples: "", "()", "()()(()())", invalid: "(", ")", ")("
	:param brackets_row: input string to be checked
	:return: True if valid, False otherwise
	"""
    m.clear()
    for i in brackets_row:
        global some_list
        if i == "(":
            m.push(i)
        if i == ")":
            if len(some_list) > 0:
                m.pop()
            else:
                return False
        print(some_list)
    return len(some_list) == 0
Esempio n. 7
0
def dfs(g: nx.Graph, start_node: Hashable) -> List[Hashable]:
    """
    Do an depth-first search and returns list of nodes in the visited order

    :param g: input graph
    :param start_node: starting node of search
    :return: list of nodes in the visited order
    """
    list_of_visit = []
    push(start_node)
    while peek(0) != None:
        node_now = pop()
        list_of_visit.append(node_now)
        neighbor_list = list(g.neighbors(node_now))
        for i in neighbor_list:
            if i in list_of_visit:
                pass
            else:
                push(i)
    return list_of_visit
Esempio n. 8
0
def check_brackets(brackets_row: str) -> bool:
    """
    Check whether input string is a valid bracket sequence
    Valid examples: "", "()", "()()(()())", invalid: "(", ")", ")("
    :param brackets_row: input string to be checked
    :return: True if valid, False otherwise
    """
    import regex

    stack.clear()

    for simb in brackets_row:
        if simb == "(":
            stack.push(")")
        elif simb == ")":
            if simb != stack.pop():
                return False
    if len(stack.lis) != 0:
        return False
    return True
Esempio n. 9
0
    def test_peek(self):
        my_stack.push(7)
        my_stack.push(3)
        my_stack.push(5)

        self.assertEqual(5, my_stack.peek())
        self.assertEqual(3, my_stack.peek(1))
        self.assertEqual(5, my_stack.peek())

        self.assertIsNone(my_stack.peek(100),
                          msg="Should return None if no elements")
Esempio n. 10
0
	def test_clear(self):
		my_stack.push(3)
		my_stack.clear()

		self.assertIsNone(my_stack.pop())
Esempio n. 11
0
	def test_push_pop(self):
		initial_elem = 3
		my_stack.push(initial_elem)

		self.assertEqual(initial_elem, my_stack.pop())
Esempio n. 12
0
    def test_clear(self):
        my_stack.push(3)
        my_stack.clear()

        self.assertIsNone(my_stack.pop(), msg="Did you clear the stack?")