Home | History | Annotate | Download | only in altgraph_tests
      1 #!/usr/bin/env py.test
      2 import os
      3 import sys
      4 
      5 from altgraph import Graph, GraphAlgo
      6 import unittest
      7 
      8 class BasicTests (unittest.TestCase):
      9     def setUp(self):
     10         self.edges = [
     11             (1,2), (2,4), (1,3), (2,4), (3,4), (4,5), (6,5), (6,14), (14,15),
     12             (6, 15), (5,7), (7, 8), (7,13), (12,8), (8,13), (11,12), (11,9),
     13             (13,11), (9,13), (13,10)
     14         ]
     15 
     16         # these are the edges
     17         self.store = {}
     18         self.g = Graph.Graph()
     19         for head, tail in self.edges:
     20             self.store[head] = self.store[tail] = None
     21             self.g.add_edge(head, tail)
     22 
     23     def test_num_edges(self):
     24         # check the parameters
     25         self.assertEqual(self.g.number_of_nodes(), len(self.store))
     26         self.assertEqual(self.g.number_of_edges(), len(self.edges))
     27 
     28     def test_forw_bfs(self):
     29         # do a forward bfs
     30         self.assertEqual( self.g.forw_bfs(1),
     31                 [1, 2, 3, 4, 5, 7, 8, 13, 11, 10, 12, 9])
     32 
     33 
     34     def test_get_hops(self):
     35         # diplay the hops and hop numbers between nodes
     36         self.assertEqual(self.g.get_hops(1, 8),
     37                 [(1, 0), (2, 1), (3, 1), (4, 2), (5, 3), (7, 4), (8, 5)])
     38 
     39     def test_shortest_path(self):
     40         self.assertEqual(GraphAlgo.shortest_path(self.g, 1, 12),
     41                 [1, 2, 4, 5, 7, 13, 11, 12])
     42 
     43 
     44 if __name__ == "__main__":  # pragma: no cover
     45     unittest.main()
     46