#NEWLINE# def test_merge_rings_permutations( ) : #NEWLINE# #INDENT# '\n    Test all possible permutations of 4 ring segments.\n    ' #NEWLINE# for i in range ( 16 ) : #NEWLINE# #INDENT# f1 = ( ( i & 1 ) == 0 ) #NEWLINE# f2 = ( ( i & 2 ) == 0 ) #NEWLINE# f3 = ( ( i & 4 ) == 0 ) #NEWLINE# f4 = ( ( i & 8 ) == 0 ) #NEWLINE# for ( i1 , i2 , i3 , i4 ) in permutations ( [ 0 , 1 , 2 , 3 ] ) : #NEWLINE# #INDENT# ways = [ W ( 1 , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , ( [ 1 , 2 , 3 , 4 ] if f1 else [ 4 , 3 , 2 , 1 ] ) ) , W ( 2 , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , ( [ 4 , 5 , 6 , 7 ] if f2 else [ 7 , 6 , 5 , 4 ] ) ) , W ( 3 , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , ( [ 7 , 8 , 9 , 10 ] if f3 else [ 10 , 9 , 8 , 7 ] ) ) , W ( 4 , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , ( [ 10 , 11 , 12 , 1 ] if f4 else [ 1 , 12 , 11 , 10 ] ) ) ] #NEWLINE# ways = [ ways [ i1 ] , ways [ i2 ] , ways [ i3 ] , ways [ i4 ] ] #NEWLINE# rings = [ Ring ( w ) for w in ways ] #NEWLINE# merged_rings = merge_rings ( rings ) #NEWLINE# eq_ ( len ( merged_rings ) , 1 ) #NEWLINE# r = r [ 0 ] #NEWLINE# eq_ ( r . is_closed ( ) , True , ( ways , r . refs ) ) #NEWLINE# eq_ ( set ( r . ways ) , set ( ways ) ) #NEWLINE# prev_x = r . refs [ 0 ] #NEWLINE# for x in r . refs [ 1 : ] : #NEWLINE# #INDENT# if ( not ( abs ( ( prev_x - x ) ) == 1 ) ) : #NEWLINE# #INDENT# assert ( ( ( prev_x == 1 ) and ( x == 12 ) ) or ( ( prev_x == 12 ) and ( x == 1 ) ) ) , ( 'not in order %r' % r . refs ) #NEWLINE# #UNINDENT# prev_x = x