class TestBiDiSearch(unittest.TestCase):
    def setUp(self):
        """The basic test's link structure will be a matrix describing 5 
        nodes with the following links between them:
            (0)-->(1)-->(2)-->(3)<--(4)
             ↑            ╲__ ↗|
             └─────────────────┘
        Same one used for every other test....
        """
        self.m = LinkMatrix(5)  # Create a 5x5 link_matrix
        self.m[0, 1] = 1
        self.m[1, 2] = 1
        self.m[2, 3] = 2
        self.m[4, 3] = 1
        self.m[3, 0] = 1

    def testSearch(self):
        # Try to find a path from 4 to 1
        self.assertEqual(search(self.m, self.m.transpose(), 4, 1),
                         [4, 3, 0, 1])
        # 2->1
        self.assertEqual(search(self.m, self.m.transpose(), 2, 1),
                         [2, 3, 0, 1])

    def testEmptySearch(self):
        # 0->4 should be empty
        self.assertEqual(search(self.m, self.m.transpose(), 0, 4), [])
class TestBiDiSearch(unittest.TestCase):
    def setUp(self):
        """The basic test's link structure will be a matrix describing 5 
        nodes with the following links between them:
            (0)-->(1)-->(2)-->(3)<--(4)
             ↑            ╲__ ↗|
             └─────────────────┘
        Same one used for every other test....
        """
        self.m=LinkMatrix(5) # Create a 5x5 link_matrix
        self.m[0, 1]=1
        self.m[1, 2]=1
        self.m[2, 3]=2
        self.m[4, 3]=1
        self.m[3, 0]=1
    def testSearch(self):
        # Try to find a path from 4 to 1
        self.assertEqual(search(self.m, self.m.transpose(), 4, 1), 
                         [4, 3, 0, 1])
        # 2->1
        self.assertEqual(search(self.m, self.m.transpose(), 2, 1),
                         [2, 3, 0, 1])
    def testEmptySearch(self):
        # 0->4 should be empty
        self.assertEqual(search(self.m, self.m.transpose(), 0, 4), [])
 def setUp(self):
     """The basic test's link structure will be a matrix describing 5 
     nodes with the following links between them:
         (0)-->(1)-->(2)-->(3)<--(4)
          ↑            ╲__ ↗|
          └─────────────────┘
     Same one used for every other test....
     """
     self.m = LinkMatrix(5)  # Create a 5x5 link_matrix
     self.m[0, 1] = 1
     self.m[1, 2] = 1
     self.m[2, 3] = 2
     self.m[4, 3] = 1
     self.m[3, 0] = 1
 def setUp(self):
     """The basic test's link structure will be a matrix describing 5 
     nodes with the following links between them:
         (0)-->(1)-->(2)-->(3)<--(4)
          ↑            ╲__ ↗|
          └─────────────────┘
     Same one used for every other test....
     """
     self.m=LinkMatrix(5) # Create a 5x5 link_matrix
     self.m[0, 1]=1
     self.m[1, 2]=1
     self.m[2, 3]=2
     self.m[4, 3]=1
     self.m[3, 0]=1
 def setUp(self):
     """Copied shamelessly from test_pageranker
     The basic test's link structure will be a matrix describing 5 
     nodes with the following links between them:
         (0)-->(1)-->(2)-->(3)<--(4)
          ↑            ╲__ ↗|
          └─────────────────┘
     With this graph, node 3 is the biggest authority, and nodes 2 and 4
     are the biggest hubs.
     """
     self.m=LinkMatrix(5) # Create a 5x5 link_matrix
     self.r=HITSCombinedRanker(epsilon=1e-30)
     self.m[0, 1]=1
     self.m[1, 2]=1
     self.m[2, 3]=2
     self.m[4, 3]=1
     self.m[3, 0]=1
Exemple #6
0
 def setUp(self):
     """The basic test's link structure will be a matrix describing 5 
     nodes with the following links between them:
         (0)-->(1)-->(2)-->(3)<--(4)
          ↑            ╲__ ↗|
          └─────────────────┘
     With this graph, node 3 should have the highest pagerank, followed by
     nodes 0, 1, 2 in that order. 4 should be the lowest.
     """
     self.m = LinkMatrix(5)  # Create a 5x5 link_matrix
     self.r = WeightedPageRanker(epsilon=1e-30)
     self.m[0, 1] = 1
     self.m[1, 2] = 1
     self.m[2, 3] = 2
     self.m[4, 3] = 1
     self.m[3, 0] = 1
     self.e = [0.15] * len(self.m)
Exemple #7
0
 def __init__(self, terms):
     LinkMatrix.__init__(self, len(terms))
     self._term_set = [x
                       for x in terms]  # Make a list-copy that will define
Exemple #8
0
 def testOnEmptyMatrix(self):
     m = LinkMatrix(5)
     self.assertRaises(ZeroDivisionError, self.r.evaluate, m,
                       [0, 0, 0, 0, 0])
Exemple #9
0
 def __init__(self, terms):
     LinkMatrix.__init__(self, len(terms))
     self._term_set=[x for x in terms] # Make a list-copy that will define