import collections import random class Complains(object): def __init__(self, i): self.i = i def __lt__(self, other): # In the real test_sort when it complains is random but here use a known case which fails. if self.i==116 and other.i==120: print " complaining at", self, other raise RuntimeError return self.i < other.i def __repr__(self): return "Complains(%d)" % self.i # A specific list. The order is generated randomly in the actual test_sort but here use a know troubled one for reproducability. # Here the size is 128 not sure if thats important? x = [50, 84, 104, 51, 75, 15, 66, 43, 17, 70, 74, 60, 113, 91, 71, 56, 76, 24, 123, 30, 28, 69, 96, 58, 109, 36, 32, 57, 79, 46, 67, 99, 72, 93, 101, 63, 126, 48, 65, 10, 78, 12, 119, 115, 53, 11, 33, 87, 114, 118, 44, 3, 100, 19, 27, 122, 121, 39, 25, 22, 2, 54, 16, 52, 124, 61, 13, 88, 0, 47, 40, 116, 98, 81, 6, 102, 35, 31, 73, 105, 77, 5, 23, 20, 7, 117, 107, 106, 42, 1, 21, 29, 8, 82, 95, 111, 14, 26, 85, 108, 97, 45, 80, 38, 64, 41, 9, 59, 62, 127, 110, 125, 90, 92, 120, 34, 83, 4, 49, 103, 68, 94, 55, 112, 18, 37, 86, 89] # Make the complains list x = [Complains(i) for i in x] # Copy it for comparison after s=x[:] try: print 'Doing sort' # Do the sort this is where something goes wrong creating duplicated entries s.sort() except: pass # Just allows the test to run on jython and cpython finally: print '\n ----- Output -----\n' print 'Original =', x print 'Sorted =', s # Count the max occurance of an element in the list print 'Lentgh of original list =', len(x) print 'Lentgh of sorted list =', len(x) print 'Max occurances of an element in original list =', max(collections.Counter(x).values()) print 'Max occurances of an element in sorted list =', max(collections.Counter(s).values()) print 'Items duplicated in sorted list =', [item for item, count in collections.Counter(s).items() if count > 1] print 'Items missing from sorted list =', list(set(x) -set(s))