Ejemplo n.º 1
0
    def test_queue_push(self):
        A = SearchNode('A')

        stack = SearchStack()

        result = stack.push(A)

        self.assertTrue(result)
        self.assertEquals(len(stack), 1)

        stack.push(A)
        self.assertEquals(len(stack), 1)
Ejemplo n.º 2
0
    def test_queue_push(self):
        A = SearchNode('A')

        stack = SearchStack()

        result = stack.push(A)

        self.assertTrue(result)
        self.assertEquals(len(stack), 1)

        stack.push(A)
        self.assertEquals(len(stack), 1)
Ejemplo n.º 3
0
    def test_stack_pop(self):
        A = SearchNode('A')
        B = SearchNode('B')

        stack = SearchStack()

        stack.push(A)
        stack.push(B)

        self.assertEquals(len(stack), 2)

        node = stack.pop()

        self.assertEquals(len(stack), 1)
        self.assertIsInstance(node, SearchNode)
        self.assertEquals(node.name, 'B')
Ejemplo n.º 4
0
    def test_placed_by(self):
        A = SearchNode('A')
        B = SearchNode('B')

        stack = SearchStack()

        stack.push(A)
        stack.push(B, A)

        node = stack.pop()

        self.assertEquals(stack.placed_by(node.name).name, 'A')

        node = stack.pop()

        self.assertIsNone(stack.placed_by(node.name))
Ejemplo n.º 5
0
    def test_stack_pop(self):
        A = SearchNode('A')
        B = SearchNode('B')

        stack = SearchStack()

        stack.push(A)
        stack.push(B)

        self.assertEquals(len(stack), 2)

        node = stack.pop()

        self.assertEquals(len(stack), 1)
        self.assertIsInstance(node, SearchNode)
        self.assertEquals(node.name, 'B')
Ejemplo n.º 6
0
    def test_placed_by(self):
        A = SearchNode('A')
        B = SearchNode('B')

        stack = SearchStack()

        stack.push(A)
        stack.push(B, A)

        node = stack.pop()

        self.assertEquals(stack.placed_by(node.name).name, 'A')

        node = stack.pop()

        self.assertIsNone(stack.placed_by(node.name))
Ejemplo n.º 7
0
    def test_advanced_pushpop(self):
        A = SearchNode('A')

        stack = SearchStack()

        result = stack.push(A)

        self.assertTrue(result)
        self.assertEquals(len(stack), 1)

        stack.push(A)
        self.assertEquals(len(stack), 1)

        stack.pop()
        stack.push(A)
        self.assertEquals(len(stack), 0)
Ejemplo n.º 8
0
    def depth(self, start: str, end: str):
        """
        Depth first node
        :param start: node name
        :param end: node name
        :return:
        """
        start = self.__nodes[start]
        end = self.__nodes[end]

        # Create search stack
        stack = SearchStack()

        # Do a basic search using a stack
        node = SearchAlgo.basic_search(stack, start, end)

        # Build path
        if node:
            # Find path from last node
            return stack.get_path(node)
        else:
            return []
Ejemplo n.º 9
0
    def depth(self, start: str, end: str):
        """
        Depth first node
        :param start: node name
        :param end: node name
        :return:
        """
        start = self.__nodes[start]
        end = self.__nodes[end]

        # Create search stack
        stack = SearchStack()

        # Do a basic search using a stack
        node = SearchAlgo.basic_search(stack, start, end)

        # Build path
        if node:
            # Find path from last node
            return stack.get_path(node)
        else:
            return []
Ejemplo n.º 10
0
    def test_advanced_pushpop(self):
        A = SearchNode('A')

        stack = SearchStack()

        result = stack.push(A)

        self.assertTrue(result)
        self.assertEquals(len(stack), 1)

        stack.push(A)
        self.assertEquals(len(stack), 1)

        stack.pop()
        stack.push(A)
        self.assertEquals(len(stack), 0)