#NEWLINE# def test_identity( ) : #NEWLINE# #INDENT# I = IdentityOperator ( ) #NEWLINE# O = Operator ( 'O' ) #NEWLINE# x = Symbol ( 'x' ) #NEWLINE# assert isinstance ( I , IdentityOperator ) #NEWLINE# assert isinstance ( I , Operator ) #NEWLINE# assert ( ( I * O ) == O ) #NEWLINE# assert ( ( O * I ) == O ) #NEWLINE# assert isinstance ( ( I * I ) , IdentityOperator ) #NEWLINE# assert isinstance ( ( 3 * I ) , Mul ) #NEWLINE# assert isinstance ( ( I * x ) , Mul ) #NEWLINE# assert ( I . inv ( ) == I ) #NEWLINE# assert ( Dagger ( I ) == I ) #NEWLINE# assert ( qapply ( ( I * O ) ) == O ) #NEWLINE# assert ( qapply ( ( O * I ) ) == O ) #NEWLINE# for n in [ 2 , 3 , 5 ] : #NEWLINE# #INDENT# assert ( represent ( IdentityOperator ( n ) ) == eye ( n ) )