<s> import os , sys <EOL> sys . path . append ( os . path . join ( os . getcwd ( ) , os . path . pardir ) ) <EOL> import unittest <EOL> from graphs . digraph import digraph <EOL> class test_graph ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . gr = digraph ( ) <EOL> self . gr . add_nodes ( [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" , "<STR_LIT:d>" , "<STR_LIT:e>" , "<STR_LIT:f>" ] ) <EOL> self . gr . add_edges ( [ ( "<STR_LIT:a>" , "<STR_LIT:b>" ) , ( "<STR_LIT:b>" , "<STR_LIT:c>" ) , ( "<STR_LIT:a>" , "<STR_LIT:d>" ) , ( "<STR_LIT:d>" , "<STR_LIT:e>" ) , ( "<STR_LIT:d>" , "<STR_LIT:f>" ) ] ) <EOL> self . gr . add_edge ( ( "<STR_LIT:f>" , "<STR_LIT:b>" ) ) <EOL> def test_nodes_method ( self ) : <EOL> self . assertEqual ( len ( self . gr . nodes ( ) ) , <NUM_LIT:6> ) <EOL> def test_add_node_method ( self ) : <EOL> self . gr . add_node ( "<STR_LIT:g>" ) <EOL> self . assertEqual ( len ( self . gr . nodes ( ) ) , <NUM_LIT:7> ) <EOL> def test_has_node_method ( self ) : <EOL> self . assertTrue ( self . gr . has_node ( "<STR_LIT:a>" ) ) <EOL> def test_neighbors_method ( self ) : <EOL> self . assertEqual ( len ( self . gr . neighbors ( "<STR_LIT:a>" ) ) , <NUM_LIT:2> ) <EOL> def test_del_node_method ( self ) : <EOL> self . gr . del_node ( "<STR_LIT:a>" ) <EOL> self . assertFalse ( self . gr . has_node ( "<STR_LIT:a>" ) ) <EOL> self . assertEqual ( len ( self . gr . edges ( ) ) , <NUM_LIT:4> ) <EOL> def test_has_edge_method ( self ) : <EOL> self . assertTrue ( self . gr . has_edge ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) ) <EOL> self . assertFalse ( self . gr . has_edge ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) ) <EOL> def test_add_duplicate_node_method_throws_exception ( self ) : <EOL> self . assertRaises ( Exception , self . gr . add_node , "<STR_LIT:a>" ) <EOL> def test_del_nonexistent_node_throws_exception ( self ) : <EOL> self . assertRaises ( Exception , self . gr . del_node , "<STR_LIT:z>" ) <EOL> def test_add_duplicate_edge_throws_exception ( self ) : <EOL> self . assertRaises ( Exception , self . gr . add_edge , ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) <EOL> def test_adding_self_loop ( self ) : <EOL> self . gr . add_edge ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) <EOL> self . assertTrue ( self . gr . has_edge ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) ) <EOL> def test_remove_self_loop ( self ) : <EOL> self . gr . add_edge ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) <EOL> self . gr . del_edge ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) <EOL> self . assertFalse ( self . gr . has_edge ( ( "<STR_LIT:a>" , "<STR_LIT:a>" ) ) ) <EOL> def test_edges_method ( self ) : <EOL> self . assertEqual ( len ( self . gr . edges ( ) ) , <NUM_LIT:6> ) <EOL> def test_node_orders_method ( self ) : <EOL> self . assertEqual ( self . gr . node_order ( "<STR_LIT:d>" ) , <NUM_LIT:2> ) <EOL> def test_del_edge_method ( self ) : <EOL> self . gr . del_edge ( ( "<STR_LIT:b>" , "<STR_LIT:c>" ) ) <EOL> self . assertFalse ( self . gr . has_edge ( ( "<STR_LIT:b>" , "<STR_LIT:c>" ) ) ) <EOL> def test_deleting_non_existing_edge_raises_exception ( self ) : <EOL> self . assertRaises ( Exception , self . gr . del_edge , ( "<STR_LIT:a>" , "<STR_LIT:z>" ) ) <EOL> def test_get_default_weight ( self ) : <EOL> self . assertEqual ( self . gr . get_edge_weight ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) , <NUM_LIT:1> ) <EOL> def test_set_weight_on_existing_edge ( self ) : <EOL> self . gr . set_edge_weight ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( self . gr . get_edge_weight ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) , <NUM_LIT:10> ) <EOL> def test_weight_for_nonexisting_edge ( self ) : <EOL> self . assertRaises ( Exception , self . gr . get_edge_weight , ( "<STR_LIT:a>" , "<STR_LIT:c>" ) ) <EOL> def test_get_transpose_method ( self ) : <EOL> transpose = self . gr . get_transpose ( ) <EOL> self . assertEqual ( len ( transpose . nodes ( ) ) , len ( self . gr . nodes ( ) ) ) <EOL> self . assertEqual ( len ( transpose . edges ( ) ) , len ( self . gr . edges ( ) ) ) <EOL> self . assertTrue ( self . gr . has_edge ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) ) <EOL> self . assertTrue ( transpose . has_edge ( ( "<STR_LIT:b>" , "<STR_LIT:a>" ) ) ) <EOL> self . assertFalse ( transpose . has_edge ( ( "<STR_LIT:a>" , "<STR_LIT:b>" ) ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
