<s> """<STR_LIT>""" <EOL> import unittest <EOL> import pygraph <EOL> from pygraph . algorithms . searching import depth_first_search , breadth_first_search <EOL> from pygraph . classes . graph import graph <EOL> from pygraph . algorithms . filters . radius import radius <EOL> from pygraph . algorithms . filters . find import find <EOL> import testlib <EOL> class test_find_filter ( unittest . TestCase ) : <EOL> def test_bfs_in_empty_graph ( self ) : <EOL> gr = graph ( ) <EOL> st , lo = breadth_first_search ( gr , filter = find ( <NUM_LIT:5> ) ) <EOL> assert st == { } <EOL> assert lo == [ ] <EOL> def test_bfs_in_graph ( self ) : <EOL> gr = testlib . new_graph ( ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_edge ( ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> st , lo = breadth_first_search ( gr , root = <NUM_LIT:0> , filter = find ( '<STR_LIT>' ) ) <EOL> assert st [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> for each in st : <EOL> assert st [ each ] == None or st [ each ] == <NUM_LIT:0> or st [ st [ each ] ] == <NUM_LIT:0> <EOL> def test_bfs_in_digraph ( self ) : <EOL> gr = testlib . new_digraph ( ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_edge ( ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> st , lo = breadth_first_search ( gr , root = <NUM_LIT:0> , filter = find ( '<STR_LIT>' ) ) <EOL> assert st [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> for each in st : <EOL> assert st [ each ] == None or st [ each ] == <NUM_LIT:0> or st [ st [ each ] ] == <NUM_LIT:0> <EOL> def test_dfs_in_empty_graph ( self ) : <EOL> gr = graph ( ) <EOL> st , pre , post = depth_first_search ( gr ) <EOL> assert st == { } <EOL> assert pre == [ ] <EOL> assert post == [ ] <EOL> def test_dfs_in_graph ( self ) : <EOL> gr = testlib . new_graph ( ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_edge ( ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> gr . add_edge ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> st , pre , post = depth_first_search ( gr , root = <NUM_LIT:0> , filter = find ( '<STR_LIT>' ) ) <EOL> assert st [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> assert '<STR_LIT>' not in st <EOL> def test_dfs_in_digraph ( self ) : <EOL> gr = testlib . new_digraph ( ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_node ( '<STR_LIT>' ) <EOL> gr . add_edge ( ( <NUM_LIT:0> , '<STR_LIT>' ) ) <EOL> gr . add_edge ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> st , pre , post = depth_first_search ( gr , root = <NUM_LIT:0> , filter = find ( '<STR_LIT>' ) ) <EOL> assert st [ '<STR_LIT>' ] == <NUM_LIT:0> <EOL> assert '<STR_LIT>' not in st <EOL> class test_radius_filter ( unittest . TestCase ) : <EOL> def testbfs_in_empty_graph ( self ) : <EOL> gr = graph ( ) <EOL> st , lo = breadth_first_search ( gr , filter = radius ( <NUM_LIT:2> ) ) <EOL> assert st == { } <EOL> assert lo == [ ] <EOL> def test_bfs_in_graph ( self ) : <EOL> gr = testlib . new_graph ( ) <EOL> st , lo = breadth_first_search ( gr , root = <NUM_LIT:0> , filter = radius ( <NUM_LIT:3> ) ) <EOL> for each in st : <EOL> assert ( st [ each ] == None or st [ each ] == <NUM_LIT:0> <EOL> or st [ st [ each ] ] == <NUM_LIT:0> or st [ st [ st [ each ] ] ] == <NUM_LIT:0> ) <EOL> def test_bfs_in_digraph ( self ) : <EOL> gr = testlib . new_digraph ( ) <EOL> st , lo = breadth_first_search ( gr , root = <NUM_LIT:0> , filter = radius ( <NUM_LIT:3> ) ) <EOL> for each in st : <EOL> assert ( st [ each ] == None or st [ each ] == <NUM_LIT:0> <EOL> or st [ st [ each ] ] == <NUM_LIT:0> or st [ st [ st [ each ] ] ] == <NUM_LIT:0> ) <EOL> def test_dfs_in_empty_graph ( self ) : <EOL> gr = graph ( ) <EOL> st , pre , post = depth_first_search ( gr , filter = radius ( <NUM_LIT:2> ) ) <EOL> assert st == { } <EOL> assert pre == [ ] <EOL> assert post == [ ] <EOL> def test_dfs_in_graph ( self ) : <EOL> gr = testlib . new_graph ( ) <EOL> st , pre , post = depth_first_search ( gr , root = <NUM_LIT:0> , filter = radius ( <NUM_LIT:3> ) ) <EOL> for each in st : <EOL> assert ( st [ each ] == None or st [ each ] == <NUM_LIT:0> <EOL> or st [ st [ each ] ] == <NUM_LIT:0> or st [ st [ st [ each ] ] ] == <NUM_LIT:0> ) <EOL> def test_dfs_in_digraph ( self ) : <EOL> gr = testlib . new_graph ( ) <EOL> st , pre , post = depth_first_search ( gr , root = <NUM_LIT:0> , filter = radius ( <NUM_LIT:3> ) ) <EOL> for each in st : <EOL> assert ( st [ each ] == None or st [ each ] == <NUM_LIT:0> <EOL> or st [ st [ each ] ] == <NUM_LIT:0> or st [ st [ st [ each ] ] ] == <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
