Beispiel #1
0
	lmid.sort()
	final = []
	final.extend(lstart)
	final.extend(lmid)
	final.extend(lend)
	return(final)

l = ['a', 'g','e', 't','g','h','b','n']

q = SBList(l)
q.sort()
q.sort()
q.sort()
q.sort()
q.sort()
print(repr(q.get_undo_list()))
#####################################################################
#
#                          Testing
#
######################################################################
# generate an auto-correlated series of characters to test the
# sort routine.  The challenge is to sort a subset of input rows
# when the old sate ranges spand into or across the sort region
# of a subsort
replicates = 3000
str_len = 20
#
#print('\n---------------------------------------------------')
#print('Test module: ' + sys.argv[0])
#print('starting ' + str(replicates) + 'replications of sorting with ' \
Beispiel #2
0
	save_l.extend(l)
	q = SBList(l)	
	insert_idx = []
	for j in range(inserts):
		#### EXPAND THIS LATER TO ALLOW LST_LEN OR MORE:
		insert_idx.append(random.randint(0, list_len - 1))
	#
	planned_inserts = []
	# Now perform the inserts
	for j in range(inserts):
		# insert to the SBList and the parallel regular list
		new_s = random_string(random.randint(1, max_str_len)) \
			+ 'insrt{0:05d}'.format(j)
		q.insert(insert_idx[j], new_s)
		planned_inserts.append(['i', insert_idx[j]])
	u = q.get_undo_list()
	for j in range(len(u)):
		assert(u[j][3] == planned_inserts[j][1])

	# Now cycle through the inserts using the undo list to
	# see if I can find the numbers that I inserted with 
	# the 'insrt{0:05d}' command above
	print('The main list is:\n' + repr(q).replace(',', '\n'))
	print('Planned inserts were: ' + repr(planned_inserts))
	print('The undo list is ' + repr(u))
	u_len = len(u)
	for j in range(0, u_len):
		# u is the undo list
		#print(u[j].get_new()[-5:] + '  -  ' + str(u[j].get_state_id()))
		assert(int(u[j].get_new()[-5:]) == u[j].get_state_id())
print("finished OK")
Beispiel #3
0
assert(qo > ql)
assert(ql < qo)
#

ql.insert(3, 'hello insert to 3')#
ql.insert(5, 'abcdefg insert to 5')
print("---------- test after 2 inserts:")
print('ql is ' + repr(ql) + ' state: ' + ql.show_state())

ql.delete(2)
print("---------- test after delete 2")
print('ql is ' + repr(ql) + ' state: ' + ql.show_state())


print("TESTING UNDO STATE: " )
ul = ql.get_undo_list()
for x in ul:
		print(repr(x))


ql.delete(2)
print("---------- test after second delete 2")
print('ql is ' + repr(ql) + ' state: ' + ql.show_state())

ql.insert(3, 'replaced to 3', batch=True)
print("---------- test after batch insert to idx 3:")
print('ql is ' + repr(ql) + ' state: ' + ql.show_state())

ql.insert(5, 'insert batch to 5', batch=True)
print("---------- test after batch insert:")
print('ql is ' + repr(ql) + ' state: ' + ql.show_state())