Пример #1
0
 def test_no_subscribers(self):
     """Tests case where we have no subscribers left"""
     imp_graph = RideD.get_importance_graph(self.tree, [], self.root)
     for u, v, imp in imp_graph.edges(data=RideD.IMPORTANCE_ATTRIBUTE_NAME):
         self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                          0)
     self.assertEqual(self.tree.number_of_edges(),
                      imp_graph.number_of_edges())
Пример #2
0
 def test_basic(self):
     """Basic test case where all leaves are subscribers"""
     imp_graph = RideD.get_importance_graph(self.tree, self.subscribers,
                                            self.root)
     self.assertEqual(imp_graph[0][1][RideD.IMPORTANCE_ATTRIBUTE_NAME], 3)
     self.assertEqual(imp_graph[1][3][RideD.IMPORTANCE_ATTRIBUTE_NAME], 2)
     for u, v in ((0, 7), (1, 2), (3, 4), (3, 5), (5, 6), (7, 8), (8, 9)):
         self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                          1)
Пример #3
0
    def test_subscriber_subset(self):
        """Tests case where not all leaf nodes are subscribers"""
        imp_graph = RideD.get_importance_graph(self.tree, [2, 4, 6], self.root)
        self.assertEqual(imp_graph[0][1][RideD.IMPORTANCE_ATTRIBUTE_NAME], 3)
        self.assertEqual(imp_graph[1][3][RideD.IMPORTANCE_ATTRIBUTE_NAME], 2)
        for u, v in ((1, 2), (3, 4), (3, 5), (5, 6)):
            self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                             1)

        for u, v in ((0, 7), (7, 8), (8, 9)):
            self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                             0)
Пример #4
0
    def test_internal_subscribers(self):
        """Tests case where some subscribers are non-leaf nodes"""
        subs = [2, 4, 6, 3]
        imp_graph = RideD.get_importance_graph(self.tree, subs, self.root)
        # Only these two links should have increased 'importance'
        self.assertEqual(imp_graph[0][1][RideD.IMPORTANCE_ATTRIBUTE_NAME], 4)
        self.assertEqual(imp_graph[1][3][RideD.IMPORTANCE_ATTRIBUTE_NAME], 3)

        for u, v in ((1, 2), (3, 4), (3, 5), (5, 6)):
            self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                             1)

        for u, v in ((0, 7), (7, 8), (8, 9)):
            self.assertEqual(imp_graph[u][v][RideD.IMPORTANCE_ATTRIBUTE_NAME],
                             0)