<s> from graphserver . core import Vertex , Edge , Link , Street , Path <EOL> import unittest <EOL> from graphserver . gsdll import lgs <EOL> from ctypes import addressof <EOL> class TestPathCreate ( unittest . TestCase ) : <EOL> def test_path_new ( self ) : <EOL> """<STR_LIT>""" <EOL> path = Path ( Vertex ( "<STR_LIT:A>" ) ) <EOL> self . assertTrue ( path ) <EOL> def test_path_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> pp = Path ( Vertex ( "<STR_LIT:A>" ) ) <EOL> self . assertEqual ( pp . num_elements , <NUM_LIT:0> ) <EOL> class TestPathSize ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . aa = Vertex ( "<STR_LIT>" ) <EOL> self . path = Path ( self . aa ) <EOL> def test_zero ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEquals ( self . path . num_elements , <NUM_LIT:0> ) <EOL> def test_one ( self ) : <EOL> """<STR_LIT>""" <EOL> bb = Vertex ( "<STR_LIT>" ) <EOL> ee = Edge ( self . aa , bb , Link ( ) ) <EOL> self . path . addSegment ( bb , ee ) <EOL> self . assertEqual ( self . path . num_elements , <NUM_LIT:1> ) <EOL> def test_ten ( self ) : <EOL> """<STR_LIT>""" <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> aa = Vertex ( "<STR_LIT>" ) <EOL> bb = Vertex ( "<STR_LIT>" ) <EOL> payload = Link ( ) <EOL> self . path . addSegment ( bb , Edge ( aa , bb , payload ) ) <EOL> self . assertEquals ( self . path . num_elements , <NUM_LIT:10> ) <EOL> class TestAddAndGetSegments ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . aa = Vertex ( "<STR_LIT:A>" ) <EOL> self . bb = Vertex ( "<STR_LIT:B>" ) <EOL> self . ep = Link ( ) <EOL> self . path = Path ( self . aa ) <EOL> def test_none ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( IndexError , self . path . getVertex , - <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , <NUM_LIT:10> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , - <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , <NUM_LIT:0> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , <NUM_LIT:10> ) <EOL> self . assertEquals ( self . path . getVertex ( <NUM_LIT:0> ) . soul , self . aa . soul ) <EOL> def test_one ( self ) : <EOL> """<STR_LIT>""" <EOL> ee = Edge ( self . aa , self . bb , self . ep ) <EOL> self . path . addSegment ( self . bb , ee ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , - <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , - <NUM_LIT:1> ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:0> ) . soul , self . aa . soul ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:1> ) . soul , self . bb . soul ) <EOL> self . assertEqual ( self . path . getEdge ( <NUM_LIT:0> ) . soul , ee . soul ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , <NUM_LIT:2> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , <NUM_LIT:1> ) <EOL> def test_two ( self ) : <EOL> """<STR_LIT>""" <EOL> ee1 = Edge ( self . aa , self . bb , Link ( ) ) <EOL> ee2 = Edge ( self . bb , self . aa , Link ( ) ) <EOL> self . path . addSegment ( self . bb , ee1 ) <EOL> self . path . addSegment ( self . aa , ee2 ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , - <NUM_LIT:1> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , - <NUM_LIT:1> ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:0> ) . soul , self . aa . soul ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:1> ) . soul , self . bb . soul ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:2> ) . soul , self . aa . soul ) <EOL> self . assertEqual ( self . path . getEdge ( <NUM_LIT:0> ) . soul , ee1 . soul ) <EOL> self . assertEqual ( self . path . getEdge ( <NUM_LIT:1> ) . soul , ee2 . soul ) <EOL> self . assertRaises ( IndexError , self . path . getVertex , <NUM_LIT:3> ) <EOL> self . assertRaises ( IndexError , self . path . getEdge , <NUM_LIT:2> ) <EOL> def test_expand ( self ) : <EOL> """<STR_LIT>""" <EOL> pathlen = <NUM_LIT:50> <EOL> segments = [ ] <EOL> for i in range ( pathlen ) : <EOL> vv = Vertex ( str ( i ) ) <EOL> ee = Edge ( vv , vv , Link ( ) ) <EOL> segments . append ( ( vv , ee ) ) <EOL> for vv , ee in segments : <EOL> self . path . addSegment ( vv , ee ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT:0> ) . label , "<STR_LIT:A>" ) <EOL> for i in range ( <NUM_LIT:1> , pathlen + <NUM_LIT:1> ) : <EOL> self . assertEqual ( i - <NUM_LIT:1> , int ( self . path . getVertex ( i ) . label ) ) <EOL> vv = Vertex ( "<STR_LIT:B>" ) <EOL> ee = Edge ( vv , vv , Link ( ) ) <EOL> self . path . addSegment ( vv , ee ) <EOL> self . assertEqual ( self . path . getVertex ( <NUM_LIT> ) . label , "<STR_LIT:B>" ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
