def testGraph6(self):
        g = WorkflowDependencyGraph(self._s)
        c1 = Connection(self._nodes[0], 0, self._nodes[2], 0)
        c2 = Connection(self._nodes[1], 0, self._nodes[2], 0)
        c3 = Connection(self._nodes[2], 0, self._nodes[3], 0)
        c4 = Connection(self._nodes[2], 0, self._nodes[4], 0)
        c5 = Connection(self._nodes[6], 0, self._nodes[0], 0)
        c6 = Connection(self._nodes[6], 0, self._nodes[1], 0)
        self._s.addItem(self._nodes[0])
        self._s.addItem(self._nodes[1])
        self._s.addItem(self._nodes[2])
        self._s.addItem(self._nodes[3])
        self._s.addItem(self._nodes[4])
        self._s.addItem(self._nodes[5])
        self._s.addItem(self._nodes[6])
        self._s.addItem(c1)
        self._s.addItem(c2)
        self._s.addItem(c3)
        self._s.addItem(c4)
        self._s.addItem(c5)
        self._s.addItem(c6)

        nodes = g._findAllConnectedNodes()
        self.assertEqual(6, len(nodes))
        graph = g._calculateDependencyGraph()
        starting_set = g._findStartingSet(graph, nodes)
        self.assertEqual(1, len(starting_set))
        order = g._determineTopologicalOrder(graph, starting_set)
        self.assertEqual(6, len(order))
        index0 = order.index(self._nodes[6])
        index1 = order.index(self._nodes[1])
        self.assertLess(index0, index1)
    def testGraph8(self):
        '''
        Testing graph with loop
        '''
        g = WorkflowDependencyGraph(self._s)
        c1 = Connection(self._nodes[0], 0, self._nodes[1], 0)
        c2 = Connection(self._nodes[1], 0, self._nodes[2], 0)
        c3 = Connection(self._nodes[2], 0, self._nodes[3], 0)
        c4 = Connection(self._nodes[3], 0, self._nodes[4], 0)
        c5 = Connection(self._nodes[3], 0, self._nodes[5], 0)
        c6 = Connection(self._nodes[5], 0, self._nodes[6], 0)
        c7 = Connection(self._nodes[6], 0, self._nodes[2], 0)
        self._s.addItem(self._nodes[0])
        self._s.addItem(self._nodes[1])
        self._s.addItem(self._nodes[2])
        self._s.addItem(self._nodes[3])
        self._s.addItem(self._nodes[4])
        self._s.addItem(self._nodes[5])
        self._s.addItem(self._nodes[6])
        self._s.addItem(c1)
        self._s.addItem(c2)
        self._s.addItem(c3)
        self._s.addItem(c4)
        self._s.addItem(c5)
        self._s.addItem(c6)
        self._s.addItem(c7)

        nodes = g._findAllConnectedNodes()
        self.assertEqual(7, len(nodes))
        graph = g._calculateDependencyGraph()
        starting_set = g._findStartingSet(graph, nodes)
        self.assertEqual(1, len(starting_set))
        order = g._determineTopologicalOrder(graph, starting_set)
        self.assertEqual(0, len(order))
    def testGraph5(self):
        g = WorkflowDependencyGraph(self._s)
        c1 = Connection(self._nodes[0], 0, self._nodes[2], 0)
        c2 = Connection(self._nodes[1], 0, self._nodes[2], 0)
        c3 = Connection(self._nodes[2], 0, self._nodes[3], 0)
        c4 = Connection(self._nodes[2], 0, self._nodes[4], 0)
        self._s.addItem(self._nodes[0])
        self._s.addItem(self._nodes[1])
        self._s.addItem(self._nodes[2])
        self._s.addItem(self._nodes[3])
        self._s.addItem(self._nodes[4])
        self._s.addItem(self._nodes[5])
        self._s.addItem(c1)
        self._s.addItem(c2)
        self._s.addItem(c3)
        self._s.addItem(c4)

        nodes = g._findAllConnectedNodes()
        self.assertEqual(5, len(nodes))
        self.assertIn(self._nodes[0], nodes)
        self.assertIn(self._nodes[1], nodes)
        self.assertIn(self._nodes[2], nodes)
        self.assertIn(self._nodes[3], nodes)
        self.assertIn(self._nodes[4], nodes)
        self.assertNotIn(self._nodes[5], nodes)

        graph = g._calculateDependencyGraph()
        self.assertFalse(g._nodeIsDestination(graph, self._nodes[0]))
        self.assertFalse(g._nodeIsDestination(graph, self._nodes[1]))
        self.assertTrue(g._nodeIsDestination(graph, self._nodes[2]))
        self.assertTrue(g._nodeIsDestination(graph, self._nodes[3]))
        self.assertTrue(g._nodeIsDestination(graph, self._nodes[4]))
        self.assertFalse(g._nodeIsDestination(graph, self._nodes[5]))

        starting_set = g._findStartingSet(graph, nodes)

        self.assertEqual(2, len(starting_set))
        self.assertIn(self._nodes[0], starting_set)
        self.assertIn(self._nodes[1], starting_set)
        self.assertNotIn(self._nodes[2], starting_set)
        self.assertNotIn(self._nodes[3], starting_set)
        self.assertNotIn(self._nodes[4], starting_set)
        self.assertNotIn(self._nodes[5], starting_set)

        order = g._determineTopologicalOrder(graph, starting_set)
        self.assertEqual(5, len(order))
        index0 = order.index(self._nodes[0])
        index1 = order.index(self._nodes[1])
        index2 = order.index(self._nodes[2])
        index3 = order.index(self._nodes[3])
        index4 = order.index(self._nodes[4])
        self.assertLess(index1, index2)
        self.assertLess(index0, index2)
        self.assertLess(index2, index3)
        self.assertLess(index2, index4)