def test_mult_pop_stack(): stack = Stack() stack.push('1') stack.push('2') stack.pop() stack.pop() assert stack.is_empty() == True
def test_if_stack_is_empty_boolean(stack): """Returns boolean is stack is empty""" empty_stack = Stack() stack.push('mouse') actual = [empty_stack.is_empty(), stack.is_empty()] expected = [True, False] assert actual == expected
def depth_first(self, starting_vertex): """ Method to do depth-first traversal on a graph. Input: starting vertex Output: list of vertices in the depth-first order """ vertices = [] depth = Stack() if starting_vertex not in self._adjacency_list: raise ValueError depth.push(starting_vertex) while not depth.is_empty(): top_vertex = depth.pop() vertices.append(top_vertex.value) top_node_neighbors = self.get_neighbors(top_vertex) for neighbor in top_node_neighbors[::-1]: if not neighbor[0].visited: top_vertex.visited = True neighbor[0].visited = True depth.push(neighbor[0]) for node in self._adjacency_list: node.visited = False return vertices
def test_check_not_empty(): s = Stack() s.push("apple") s.push("banana") actual = s.is_empty() expected = False assert actual == expected
class PseudoQueue: def __init__(self): self.stack1 = Stack() self.stack2 = Stack() def enqueue(self,data): self.stack1.push(data) # self.stack2.push(data) def dequeue(self): if self.stack1.is_empty() and self.stack2.is_empty(): raise AttributeError('The PseudoQueue is empty') if self.stack2.is_empty(): while self.stack1.top != None: self.stack2.push(self.stack1.pop()) return self.stack2.pop() else: return self.stack2.pop()
def test_pop_until_empty(): s = Stack() s.push("apple") s.push("banana") s.push("cucumber") s.pop() s.pop() s.pop() actual = s.is_empty() expected = True assert actual == expected
def depth_first(self, node): nodes = [] depth = Stack() depth.push(node) visited = {node: True} while not depth.is_empty(): front = depth.pop() nodes.append(front.value) for el in self.adjacency_list[front]: if el.node not in visited: visited[el.node] = True depth.push(el.node) return nodes
def test_stack_is_empty(): test_stack = create_stack(['a', 'b', 'c', 'd']) assert test_stack.is_empty() == False test_stack = Stack() assert test_stack.is_empty() == True
def test_queue_is_empty(): test_queue = create_queue(['a', 'b', 'c', 'd']) assert test_queue.is_empty() == False test_queue = Stack() assert test_queue.is_empty() == True
def test_stack_is_empty(): testing_stack = Stack() expected = True actual = testing_stack.is_empty() assert actual == expected