#NEWLINE# def test_collect_order( ) : #NEWLINE# #INDENT# ( a , b , x , t ) = symbols ( 'a,b,x,t' ) #NEWLINE# assert ( collect ( ( ( ( t + ( t * x ) ) + ( t * ( x ** 2 ) ) ) + O ( ( x ** 3 ) ) ) , t ) == ( t * ( ( ( 1 + x ) + ( x ** 2 ) ) + O ( ( x ** 3 ) ) ) ) ) #NEWLINE# assert ( collect ( ( ( ( t + ( t * x ) ) + ( x ** 2 ) ) + O ( ( x ** 3 ) ) ) , t ) == ( ( ( t * ( ( 1 + x ) + O ( ( x ** 3 ) ) ) ) + ( x ** 2 ) ) + O ( ( x ** 3 ) ) ) ) #NEWLINE# f = ( ( ( ( ( a * x ) + ( b * x ) ) + ( c * ( x ** 2 ) ) ) + ( d * ( x ** 2 ) ) ) + O ( ( x ** 3 ) ) ) #NEWLINE# g = ( ( ( x * ( a + b ) ) + ( ( x ** 2 ) * ( c + d ) ) ) + O ( ( x ** 3 ) ) ) #NEWLINE# assert ( collect ( f , x ) == g ) #NEWLINE# assert ( collect ( f , x , distribute_order_term = False ) == g ) #NEWLINE# f = sin ( ( a + b ) ) . series ( b , 0 , 10 ) #NEWLINE# assert ( collect ( f , [ sin ( a ) , cos ( a ) ] ) == ( ( sin ( a ) * cos ( b ) . series ( b , 0 , 10 ) ) + ( cos ( a ) * sin ( b ) . series ( b , 0 , 10 ) ) ) ) #NEWLINE# assert ( collect ( f , [ sin ( a ) , cos ( a ) ] , distribute_order_term = False ) == ( ( ( sin ( a ) * cos ( b ) . series ( b , 0 , 10 ) . removeO ( ) ) + ( cos ( t ) * sin ( b ) . series ( b , 0 , 10 ) . removeO ( ) ) ) + O ( ( b ** 10 ) ) ) )