<s> from stress_utils import get_mem_usage <EOL> import sys <EOL> sys . path . append ( "<STR_LIT:..>" ) <EOL> from graphserver . core import * <EOL> def grind ( func , n , threshold = <NUM_LIT:10> ) : <EOL> mperc , m0 = get_mem_usage ( ) <EOL> g = Graph ( ) <EOL> for i in xrange ( n ) : <EOL> func ( ) <EOL> mperc , m1 = get_mem_usage ( ) <EOL> print m0 , m1 <EOL> assert m1 <= m0 + threshold <EOL> import unittest <EOL> class StressTest ( unittest . TestCase ) : <EOL> def test_state_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = State ( <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_simple_vertex_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = Vertex ( "<STR_LIT>" ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_street_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = Street ( "<STR_LIT>" , <NUM_LIT> ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_link_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = Link ( ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_trip_board_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> sc = ServiceCalendar ( ) <EOL> sc . add_period ( <NUM_LIT:0> , <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> - <NUM_LIT:1> , [ '<STR_LIT>' ] ) <EOL> sc . add_period ( <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> , <NUM_LIT:2> * <NUM_LIT> * <NUM_LIT> - <NUM_LIT:1> , [ '<STR_LIT>' ] ) <EOL> tz = Timezone ( ) <EOL> tz . add_period ( TimezonePeriod ( <NUM_LIT:0> , <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> , <NUM_LIT:0> ) ) <EOL> def func ( ) : <EOL> tb = TripBoard ( "<STR_LIT>" , sc , tz , <NUM_LIT:0> ) <EOL> tb . add_boarding ( "<STR_LIT>" , <NUM_LIT:50> , <NUM_LIT:0> ) <EOL> tb . add_boarding ( "<STR_LIT>" , <NUM_LIT:100> , <NUM_LIT:0> ) <EOL> tb . add_boarding ( "<STR_LIT>" , <NUM_LIT:200> , <NUM_LIT:0> ) <EOL> tb . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_crossing_destroy ( self ) : <EOL> def func ( ) : <EOL> cr = Crossing ( ) <EOL> cr . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_alight_destroy ( self ) : <EOL> tz = Timezone ( ) <EOL> cal = ServiceCalendar ( ) <EOL> def func ( ) : <EOL> al = TripAlight ( <NUM_LIT:0> , cal , tz , <NUM_LIT:0> ) <EOL> al . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> tz . destroy ( ) <EOL> cal . destroy ( ) <EOL> def test_minimal_graph_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = Graph ( ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_min_vertex_graph_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> def func ( ) : <EOL> s = Graph ( ) <EOL> s . add_vertex ( "<STR_LIT:A>" ) <EOL> s . add_vertex ( "<STR_LIT:B>" ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_minimal_spt_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> s = Graph ( ) <EOL> s . add_vertex ( "<STR_LIT:A>" ) <EOL> s . add_vertex ( "<STR_LIT:B>" ) <EOL> s . add_vertex ( "<STR_LIT:C>" ) <EOL> s . add_edge ( "<STR_LIT:A>" , "<STR_LIT:B>" , Street ( "<STR_LIT:1>" , <NUM_LIT> ) ) <EOL> s . add_edge ( "<STR_LIT:B>" , "<STR_LIT:A>" , Street ( "<STR_LIT:1>" , <NUM_LIT> ) ) <EOL> s . add_edge ( "<STR_LIT:B>" , "<STR_LIT:C>" , Street ( "<STR_LIT:2>" , <NUM_LIT> ) ) <EOL> def func ( ) : <EOL> spt = s . shortest_path_tree ( "<STR_LIT:A>" , "<STR_LIT:C>" , State ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> spt . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> def test_shortest_path_grind ( self ) : <EOL> s = Graph ( ) <EOL> s . add_vertex ( "<STR_LIT:A>" ) <EOL> s . add_vertex ( "<STR_LIT:B>" ) <EOL> s . add_vertex ( "<STR_LIT:C>" ) <EOL> s . add_edge ( "<STR_LIT:A>" , "<STR_LIT:B>" , Street ( "<STR_LIT:1>" , <NUM_LIT> ) ) <EOL> s . add_edge ( "<STR_LIT:B>" , "<STR_LIT:A>" , Street ( "<STR_LIT:1>" , <NUM_LIT> ) ) <EOL> s . add_edge ( "<STR_LIT:B>" , "<STR_LIT:C>" , Street ( "<STR_LIT:2>" , <NUM_LIT> ) ) <EOL> def func ( ) : <EOL> spt = s . shortest_path_tree ( "<STR_LIT:A>" , "<STR_LIT:C>" , State ( <NUM_LIT:1> , <NUM_LIT:0> ) ) <EOL> sp = spt . path ( "<STR_LIT:C>" ) <EOL> spt . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> class WaitStressTest ( unittest . TestCase ) : <EOL> def test_wait_destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> tz = Timezone . generate ( "<STR_LIT>" ) <EOL> def func ( ) : <EOL> s = Wait ( <NUM_LIT> , tz ) <EOL> s . destroy ( ) <EOL> grind ( func , <NUM_LIT> ) <EOL> from random import randint <EOL> def random_graph ( nvertices , nedges ) : <EOL> """<STR_LIT>""" <EOL> vertices = [ str ( x ) for x in range ( nvertices ) ] <EOL> g = Graph ( ) <EOL> for vertex in vertices : <EOL> g . add_vertex ( vertex ) <EOL> for i in range ( nedges ) : <EOL> a = vertices [ randint ( <NUM_LIT:0> , len ( vertices ) - <NUM_LIT:1> ) ] <EOL> b = a <EOL> while b == a : <EOL> b = vertices [ randint ( <NUM_LIT:0> , len ( vertices ) - <NUM_LIT:1> ) ] <EOL> g . add_edge ( a , b , Link ( ) ) <EOL> return g <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tl = unittest . TestLoader ( ) <EOL> testables = [ StressTest , <EOL> WaitStressTest , <EOL> ] <EOL> for testable in testables : <EOL> suite = tl . loadTestsFromTestCase ( testable ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( suite ) </s>
