<s> @ package ( '<STR_LIT>' ) <EOL> class Failure ( Error ) : <EOL> def __init__ ( self , message ) : <EOL> super ( ) . __init__ ( ) <EOL> self . message = message <EOL> @ package ( '<STR_LIT>' ) <EOL> class Test : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , reporter , name ) : <EOL> self . name = name <EOL> self . reporter = reporter <EOL> def assertTrue ( self , val ) : <EOL> self . reporter . add_assert ( ) <EOL> if not val : <EOL> raise Failure ( "<STR_LIT>" + val + "<STR_LIT>" ) <EOL> def assertFalse ( self , val ) : <EOL> self . reporter . add_assert ( ) <EOL> if val : <EOL> raise Failure ( "<STR_LIT>" + val + "<STR_LIT>" ) <EOL> def assertEquals ( self , a , b ) : <EOL> self . reporter . add_assert ( ) <EOL> if a != b : <EOL> raise Failure ( "<STR_LIT>" + a + "<STR_LIT>" + b + "<STR_LIT>" ) <EOL> def assertFloatEquals ( self , a , b ) : <EOL> self . reporter . add_assert ( ) <EOL> if - <NUM_LIT> < a - b < <NUM_LIT> : <EOL> raise Failure ( "<STR_LIT>" + a + "<STR_LIT>" + b + "<STR_LIT>" ) <EOL> def assertNotEquals ( self , a , b ) : <EOL> self . reporter . add_assert ( ) <EOL> if a == b : <EOL> raise Failure ( "<STR_LIT>" + a + "<STR_LIT>" + b + "<STR_LIT>" ) <EOL> def assertFloatNotEquals ( self , a , b ) : <EOL> self . reporter . add_assert ( ) <EOL> dif = a - b <EOL> if dif > <NUM_LIT> or dif < - <NUM_LIT> : <EOL> raise Failure ( "<STR_LIT>" + a + "<STR_LIT>" + b + "<STR_LIT>" ) <EOL> def run ( self ) : <EOL> self . reporter . start ( self . name ) <EOL> try : <EOL> self . test ( ) <EOL> except Failure as f : <EOL> self . reporter . fail ( f ) <EOL> except Error as e : <EOL> self . reporter . error ( e ) <EOL> else : <EOL> self . reporter . ok ( ) <EOL> @ package ( '<STR_LIT>' ) <EOL> class Reporter : <EOL> def __init__ ( self , textlabel ) : <EOL> self . textlabel = textlabel <EOL> self . number = <NUM_LIT:0> <EOL> self . successful = <NUM_LIT:0> <EOL> self . failed = <NUM_LIT:0> <EOL> self . assertions = <NUM_LIT:0> <EOL> self . at_start = False <EOL> def start ( self , name ) : <EOL> self . number += <NUM_LIT:1> <EOL> self . at_start = True <EOL> self . textlabel . appendText ( name + '<STR_LIT>' ) <EOL> def ok ( self ) : <EOL> if not self . at_start : <EOL> self . textlabel . appendText ( '<STR_LIT>' ) <EOL> self . textlabel . appendText ( '<STR_LIT>' ) <EOL> self . successful += <NUM_LIT:1> <EOL> def fail ( self , failure ) : <EOL> if not self . at_start : <EOL> self . textlabel . appendText ( '<STR_LIT>' ) <EOL> self . debug ( failure . getStackTrace ( ) ) <EOL> self . textlabel . appendText ( '<STR_LIT>' + failure . message + '<STR_LIT:\n>' ) <EOL> self . failed += <NUM_LIT:1> <EOL> def error ( self , error ) : <EOL> if not self . at_start : <EOL> self . textlabel . appendText ( '<STR_LIT>' ) <EOL> self . textlabel . appendText ( '<STR_LIT>' + error . getStackTrace ( ) + '<STR_LIT:\n>' ) <EOL> self . failed += <NUM_LIT:1> <EOL> def add_assert ( self ) : <EOL> self . assertions += <NUM_LIT:1> <EOL> def debug ( self , val ) : <EOL> if self . at_start : <EOL> self . textlabel . appendText ( '<STR_LIT:\n>' ) <EOL> self . at_start = False <EOL> self . textlabel . appendText ( '<STR_LIT>' + val + '<STR_LIT:\n>' ) <EOL> def finish ( self ) : <EOL> self . textlabel . appendText ( "<STR_LIT>" + self . number <EOL> + "<STR_LIT>" + self . successful <EOL> + "<STR_LIT>" + self . failed <EOL> + "<STR_LIT>" + self . assertions + "<STR_LIT:\n>" ) </s>
