#NEWLINE# def check_merge_at( self , a , b ) : #NEWLINE# #INDENT# f = self . timsort . merge_at #NEWLINE# na = len ( a ) #NEWLINE# nb = len ( b ) #NEWLINE# orig_keys = ( ( ( [ 42 ] + a ) + b ) + [ ( - 42 ) ] ) #NEWLINE# ssa = 1 #NEWLINE# ssb = ( ssa + na ) #NEWLINE# stack_sentinel = MergeRun ( ( - 42 ) , ( - 42 ) ) #NEWLINE# def run_merge_at( ms , keys , i ) : #NEWLINE# #INDENT# new_ms = f ( ms , keys , keys , i ) #NEWLINE# self . assertEqual ( keys [ 0 ] , orig_keys [ 0 ] ) #NEWLINE# self . assertEqual ( keys [ ( - 1 ) ] , orig_keys [ ( - 1 ) ] ) #NEWLINE# self . assertSorted ( orig_keys [ 1 : ( - 1 ) ] , keys [ 1 : ( - 1 ) ] ) #NEWLINE# self . assertIs ( new_ms . pending , ms . pending ) #NEWLINE# self . assertEqual ( ms . pending [ i ] , ( ssa , ( na + nb ) ) ) #NEWLINE# self . assertEqual ( ms . pending [ 0 ] , stack_sentinel ) #NEWLINE# return new_ms #NEWLINE# #UNINDENT# keys = self . array_factory ( orig_keys ) #NEWLINE# ms = self . merge_init ( keys ) #NEWLINE# ms = self . timsort . merge_append ( ms , stack_sentinel ) #NEWLINE# i = ms . n #NEWLINE# ms = self . timsort . merge_append ( ms , MergeRun ( ssa , na ) ) #NEWLINE# ms = self . timsort . merge_append ( ms , MergeRun ( ssb , nb ) ) #NEWLINE# ms = run_merge_at ( ms , keys , i ) #NEWLINE# self . assertEqual ( ms . n , ( i + 1 ) ) #NEWLINE# keys = self . array_factory ( orig_keys ) #NEWLINE# ms = self . merge_init ( keys ) #NEWLINE# ms = self . timsort . merge_append ( ms , stack_sentinel ) #NEWLINE# i = ms . n #NEWLINE# ms = self . timsort . merge_append ( ms , MergeRun ( ssa , na ) ) #NEWLINE# ms = self . timsort . merge_append ( ms , MergeRun ( ssb , nb ) ) #NEWLINE# last_run = MergeRun ( ( ssb + nb ) , 1 ) #NEWLINE# ms = self . timsort . merge_append ( ms , last_run ) #NEWLINE# ms = run_merge_at ( ms , keys , i ) #NEWLINE# self . assertEqual ( ms . n , ( i + 2 ) ) #NEWLINE# self . assertEqual ( ms . pending [ ( ms . n - 1 ) ] , last_run )