#NEWLINE# def test_power_representation( ) : #NEWLINE# #INDENT# tests = [ ( 1729 , 3 , 2 ) , ( 234 , 2 , 4 ) , ( 2 , 1 , 2 ) , ( 3 , 1 , 3 ) , ( 5 , 2 , 2 ) , ( 12352 , 2 , 4 ) , ( 32760 , 2 , 3 ) ] #NEWLINE# for test in tests : #NEWLINE# #INDENT# ( n , p , k ) = test #NEWLINE# f = power_representation ( n , p , k ) #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# l = next ( f ) #NEWLINE# assert ( len ( l ) == k ) #NEWLINE# chk_sum = 0 #NEWLINE# for l_i in l : #NEWLINE# #INDENT# chk_sum = ( chk_sum + ( l_i ** p ) ) #NEWLINE# #UNINDENT# assert ( chk_sum == n ) #NEWLINE# #UNINDENT# except StopIteration : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# assert ( list ( power_representation ( 20 , 2 , 4 , True ) ) == [ ( 1 , 1 , 3 , 3 ) , ( 0 , 0 , 2 , 4 ) ] ) #NEWLINE# raises ( ValueError , ( lambda : list ( power_representation ( 1.2 , 2 , 2 ) ) ) ) #NEWLINE# raises ( ValueError , ( lambda : list ( power_representation ( 2 , 0 , 2 ) ) ) ) #NEWLINE# raises ( ValueError , ( lambda : list ( power_representation ( 2 , 2 , 0 ) ) ) ) #NEWLINE# assert ( list ( power_representation ( ( - 1 ) , 2 , 2 ) ) == [ ] ) #NEWLINE# assert ( list ( power_representation ( 1 , 1 , 1 ) ) == [ ( 1 , ) ] ) #NEWLINE# assert ( list ( power_representation ( 3 , 2 , 1 ) ) == [ ] ) #NEWLINE# assert ( list ( power_representation ( 4 , 2 , 1 ) ) == [ ( 2 , ) ] ) #NEWLINE# assert ( list ( power_representation ( ( 3 ** 4 ) , 4 , 6 , zeros = True ) ) == [ ( 1 , 2 , 2 , 2 , 2 , 2 ) , ( 0 , 0 , 0 , 0 , 0 , 3 ) ] ) #NEWLINE# assert ( list ( power_representation ( ( 3 ** 4 ) , 4 , 5 , zeros = False ) ) == [ ] ) #NEWLINE# assert ( list ( power_representation ( ( - 2 ) , 3 , 2 ) ) == [ ( ( - 1 ) , ( - 1 ) ) ] ) #NEWLINE# assert ( list ( power_representation ( ( - 2 ) , 4 , 2 ) ) == [ ] ) #NEWLINE# assert ( list ( power_representation ( 0 , 3 , 2 , True ) ) == [ ( 0 , 0 ) ] ) #NEWLINE# assert ( list ( power_representation ( 0 , 3 , 2 , False ) ) == [ ] ) #NEWLINE# assert ( len ( list ( power_representation ( ( ( 4 ** 10 ) * ( ( 8 * 10 ) + 7 ) ) , 2 , 3 ) ) ) == 0 ) #NEWLINE# big = ( 2 ** 30 ) #NEWLINE# for i in [ 13 , 10 , 7 , 5 , 4 , 2 , 1 ] : #NEWLINE# #INDENT# assert ( list ( sum_of_powers ( big , 2 , ( big - i ) ) ) == [ ] )