<s> from certfuzz . fuzztools . hamming import bitwise_hd <EOL> from certfuzz . fuzztools . hamming import bytewise_hamming_distance <EOL> from certfuzz . fuzztools . hamming import bytemap <EOL> from certfuzz . fuzztools . hamming import bitwise_hamming_distance <EOL> from certfuzz . fuzztools . hamming import vector_compare <EOL> from certfuzz . fuzztools . hamming import bytewise_hd <EOL> import os <EOL> import tempfile <EOL> import itertools <EOL> '''<STR_LIT>''' <EOL> import unittest <EOL> class Test ( unittest . TestCase ) : <EOL> def delete_files ( self , * files ) : <EOL> for f in files : <EOL> os . remove ( f ) <EOL> self . assertFalse ( os . path . exists ( f ) ) <EOL> def setUp ( self ) : <EOL> ( f1d , f1 ) = tempfile . mkstemp ( text = True ) <EOL> ( f2d , f2 ) = tempfile . mkstemp ( text = True ) <EOL> [ os . close ( fd ) for fd in ( f1d , f2d ) ] <EOL> self . f1 = f1 <EOL> self . f2 = f2 <EOL> def tearDown ( self ) : <EOL> self . delete_files ( self . f1 , self . f2 ) <EOL> def test_bytewise_hd ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> s3 = "<STR_LIT>" <EOL> self . assertEqual ( bytewise_hd ( s1 , s2 ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( bytewise_hd ( s2 , s3 ) , <NUM_LIT:11> ) <EOL> self . assertEqual ( bytewise_hd ( s1 , s3 ) , <NUM_LIT:10> ) <EOL> self . assertEqual ( bytewise_hd ( s1 , s1 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( bytewise_hd ( s2 , s2 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( bytewise_hd ( s3 , s3 ) , <NUM_LIT:0> ) <EOL> self . assertRaises ( AssertionError , bytewise_hd , s1 , s2 + "<STR_LIT:foo>" ) <EOL> def test_bitwise_hd ( self ) : <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:0>' , '<STR_LIT:1>' ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:0>' , '<STR_LIT:a>' ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:0>' , '<STR_LIT:c>' ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:1>' , '<STR_LIT:a>' ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:1>' , '<STR_LIT:c>' ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( bitwise_hd ( '<STR_LIT:a>' , '<STR_LIT:c>' ) , <NUM_LIT:1> ) <EOL> [ self . assertEqual ( bitwise_hd ( c , c ) , <NUM_LIT:0> ) for c in "<STR_LIT>" ] <EOL> def test_bytwise_hamming_distance ( self ) : <EOL> f1d = open ( self . f1 , '<STR_LIT:w>' ) <EOL> f2d = open ( self . f2 , '<STR_LIT:w>' ) <EOL> f1d . write ( "<STR_LIT>" ) <EOL> f2d . write ( "<STR_LIT>" ) <EOL> f1d . close ( ) <EOL> f2d . close ( ) <EOL> self . assertEqual ( bytewise_hamming_distance ( self . f1 , self . f2 ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( bytewise_hamming_distance ( self . f1 , self . f1 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( bytewise_hamming_distance ( self . f2 , self . f2 ) , <NUM_LIT:0> ) <EOL> def test_bytemap ( self ) : <EOL> s1 = "<STR_LIT>" <EOL> s2 = "<STR_LIT>" <EOL> s3 = "<STR_LIT>" <EOL> self . assertEqual ( bytemap ( s1 , s2 ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> ] ) <EOL> self . assertEqual ( bytemap ( s1 , s3 ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:11> , <NUM_LIT:12> ] ) <EOL> self . assertEqual ( bytemap ( s2 , s3 ) , [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT> ] ) <EOL> self . assertEqual ( bytemap ( s1 , s1 ) , [ ] ) <EOL> self . assertEqual ( bytemap ( s2 , s2 ) , [ ] ) <EOL> self . assertEqual ( bytemap ( s3 , s3 ) , [ ] ) <EOL> for x , y in itertools . product ( [ s1 , s2 , s3 ] , [ s1 , s2 , s3 ] ) : <EOL> self . assertEqual ( bytemap ( bytearray ( x ) , bytearray ( y ) ) , bytemap ( x , y ) ) <EOL> self . assertRaises ( AssertionError , bytemap , s1 , s2 + "<STR_LIT:foo>" ) <EOL> def test_bitwise_hamming_distance ( self ) : <EOL> f1d = open ( self . f1 , '<STR_LIT:w>' ) <EOL> f2d = open ( self . f2 , '<STR_LIT:w>' ) <EOL> f1d . write ( "<STR_LIT>" ) <EOL> f2d . write ( "<STR_LIT>" ) <EOL> f1d . close ( ) <EOL> f2d . close ( ) <EOL> self . assertEqual ( bitwise_hamming_distance ( self . f1 , self . f2 ) , <NUM_LIT:6> ) <EOL> self . assertEqual ( bitwise_hamming_distance ( self . f1 , self . f1 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( bitwise_hamming_distance ( self . f2 , self . f2 ) , <NUM_LIT:0> ) <EOL> def test_vector_compare ( self ) : <EOL> v1 = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> v2 = [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> v3 = [ <NUM_LIT:2> ] <EOL> self . assertEqual ( vector_compare ( v1 , v2 ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( vector_compare ( v1 , v3 ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( vector_compare ( v2 , v3 ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( vector_compare ( v1 , v1 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( vector_compare ( v2 , v2 ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( vector_compare ( v3 , v3 ) , <NUM_LIT:0> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
