<s> import unittest <EOL> import itertools <EOL> import rs <EOL> class TestRSverify ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . coder = rs . RSCoder ( <NUM_LIT:255> , <NUM_LIT> ) <EOL> def test_one ( self ) : <EOL> """<STR_LIT>""" <EOL> code = self . coder . encode ( "<STR_LIT>" ) <EOL> self . assertTrue ( self . coder . verify ( code ) ) <EOL> def test_two ( self ) : <EOL> """<STR_LIT>""" <EOL> code = self . coder . encode ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for i , c in enumerate ( code ) : <EOL> if ord ( c ) == <NUM_LIT:0> : <EOL> c = chr ( <NUM_LIT:1> ) <EOL> else : <EOL> c = chr ( <NUM_LIT:0> ) <EOL> bad_code = code [ : i ] + c + code [ i + <NUM_LIT:1> : ] <EOL> self . assertFalse ( self . coder . verify ( bad_code ) ) <EOL> class TestRSdecoding ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . coder = rs . RSCoder ( <NUM_LIT:255> , <NUM_LIT> ) <EOL> self . string = "<STR_LIT>" <EOL> codestr = self . coder . encode ( self . string ) <EOL> self . code = codestr <EOL> def test_strip ( self ) : <EOL> """<STR_LIT>""" <EOL> otherstr = self . string . rjust ( <NUM_LIT> , "<STR_LIT>" ) <EOL> codestr = self . coder . encode ( otherstr ) <EOL> self . assertEqual ( <NUM_LIT:255> , len ( codestr ) ) <EOL> decode = self . coder . decode ( codestr ) <EOL> decode2 = self . coder . decode ( codestr [ : <NUM_LIT:5> ] + "<STR_LIT>" + codestr [ <NUM_LIT:6> : ] ) <EOL> self . assertEqual ( self . string , decode ) <EOL> self . assertEqual ( self . string , decode2 ) <EOL> decode = self . coder . decode ( codestr , nostrip = True ) <EOL> decode2 = self . coder . decode ( codestr [ : <NUM_LIT:5> ] + "<STR_LIT>" + codestr [ <NUM_LIT:6> : ] , nostrip = True ) <EOL> self . assertEqual ( otherstr , decode ) <EOL> self . assertEqual ( otherstr , decode2 ) <EOL> def test_noerr ( self ) : <EOL> """<STR_LIT>""" <EOL> decode = self . coder . decode ( self . code ) <EOL> self . assertEqual ( self . string , decode ) <EOL> def test_oneerr ( self ) : <EOL> """<STR_LIT>""" <EOL> for i , c in enumerate ( self . code ) : <EOL> newch = chr ( ( ord ( c ) + <NUM_LIT:50> ) % <NUM_LIT> ) <EOL> r = self . code [ : i ] + newch + self . code [ i + <NUM_LIT:1> : ] <EOL> decode = self . coder . decode ( r ) <EOL> self . assertEqual ( self . string , decode ) <EOL> def disabled_test_twoerr ( self ) : <EOL> """<STR_LIT>""" <EOL> for i1 , i2 in itertools . combinations ( range ( len ( self . code ) ) , <NUM_LIT:2> ) : <EOL> r = list ( ord ( x ) for x in self . code ) <EOL> r [ i1 ] = ( r [ i1 ] + <NUM_LIT:50> ) % <NUM_LIT> <EOL> r [ i2 ] = ( r [ i2 ] + <NUM_LIT:50> ) % <NUM_LIT> <EOL> r = "<STR_LIT>" . join ( chr ( x ) for x in r ) <EOL> decode = self . coder . decode ( r ) <EOL> self . assertEqual ( self . string , decode ) <EOL> def test_16err ( self ) : <EOL> """<STR_LIT>""" <EOL> errors = [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> r = list ( ord ( x ) for x in self . code ) <EOL> for e in errors : <EOL> r [ e ] = ( r [ e ] + <NUM_LIT:50> ) % <NUM_LIT> <EOL> r = "<STR_LIT>" . join ( chr ( x ) for x in r ) <EOL> decode = self . coder . decode ( r ) <EOL> self . assertEqual ( self . string , decode ) <EOL> def test_17err ( self ) : <EOL> """<STR_LIT>""" <EOL> errors = [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> ] <EOL> r = list ( ord ( x ) for x in self . code ) <EOL> for e in errors : <EOL> r [ e ] = ( r [ e ] + <NUM_LIT:50> ) % <NUM_LIT> <EOL> r = "<STR_LIT>" . join ( chr ( x ) for x in r ) <EOL> decode = self . coder . decode ( r ) <EOL> self . assertNotEqual ( self . string , decode ) <EOL> class TestOtherConfig ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test255_13 ( self ) : <EOL> coder = rs . RSCoder ( <NUM_LIT:255> , <NUM_LIT> ) <EOL> m = "<STR_LIT>" <EOL> code = coder . encode ( m ) <EOL> self . assertTrue ( coder . verify ( code ) ) <EOL> self . assertEqual ( m , coder . decode ( code ) ) <EOL> self . assertEqual ( <NUM_LIT:255> , len ( code ) ) <EOL> changes = [ <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:30> , <NUM_LIT:32> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:50> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:100> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <EOL> <NUM_LIT> , <NUM_LIT> ] <EOL> c = list ( ord ( x ) for x in code ) <EOL> for pos in changes : <EOL> c [ pos ] = ( c [ pos ] + <NUM_LIT:50> ) % <NUM_LIT:255> <EOL> c = "<STR_LIT>" . join ( chr ( x ) for x in c ) <EOL> decode = coder . decode ( c ) <EOL> self . assertEqual ( m , decode ) <EOL> def test30_10 ( self ) : <EOL> """<STR_LIT>""" <EOL> coder = rs . RSCoder ( <NUM_LIT:30> , <NUM_LIT:10> ) <EOL> m = "<STR_LIT>" <EOL> code = coder . encode ( m ) <EOL> self . assertTrue ( coder . verify ( code ) ) <EOL> self . assertEqual ( m , coder . decode ( code ) ) <EOL> self . assertEqual ( <NUM_LIT:30> , len ( code ) ) <EOL> changes = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:7> , <EOL> <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> c = list ( ord ( x ) for x in code ) <EOL> for pos in changes : <EOL> c [ pos ] = ( c [ pos ] + <NUM_LIT:50> ) % <NUM_LIT:255> <EOL> c = "<STR_LIT>" . join ( chr ( x ) for x in c ) <EOL> decode = coder . decode ( c ) <EOL> self . assertEqual ( m , decode ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
