def output(self, s, e): # # sidl EXPECTED INCOMING TYPES # ============================ # int s # int e # # # sidl EXPECTED RETURN VALUE(s) # ============================= # None # """\ Print elements s through e-1 """ # DO-NOT-DELETE splicer.begin(output) size = self.__IORself.getLength() listcontents = "list" for i in xrange(size): listcontents = listcontents + " " + str(self.d_elements[i]) RegOut.getInstance().writeComment(listcontents)
def sortAndReport(alg, cont, comp, result): tracker = RegOut.getInstance() alg.reset() alg.sort(cont, comp) swpCnt = alg.getSwapCounter() cmpCnt = alg.getCompareCounter() tracker.writeComment("compares (" + str(cmpCnt.getCount()) + ") swaps (" + str(swpCnt.getCount()) + ")") if (notSorted(cont, comp)): tracker.writeComment("sort failed!!") result = 0 return result
def stressTest(algs): # # sidl EXPECTED INCOMING TYPES # ============================ # array<sort.SortingAlgorithm> algs # # # sidl EXPECTED RETURN VALUE(s) # ============================= # bool _return # """\ Perform the array stress test. Return true if all the algorithms work okay. """ # DO-NOT-DELETE splicer.begin(stressTest) result = 1 tracker = RegOut.getInstance() for alg in algs: data = sort.IntegerContainer.IntegerContainer() cont = sort.Container.Container(data) intcomp = sort.CompInt.CompInt() comp = sort.Comparator.Comparator(intcomp) name = alg.getName() tracker.writeComment("****ALGORITHM IS " + name + "****") for size in testSizes: intcomp.setSortIncreasing(1) tracker.writeComment("DATA SIZE " + str(size)) data.setLength(size) result = sortAndReport(alg, cont, comp, result) tracker.writeComment("pre-sorted list") result = sortAndReport(alg, cont, comp, result) tracker.writeComment("reverse sorted list") intcomp.setSortIncreasing(0) result = sortAndReport(alg, cont, comp, result) sys.stdout.flush() return result
def stressTest(algs): # # sidl EXPECTED INCOMING TYPES # ============================ # array<sorting.SortingAlgorithm> algs # # # sidl EXPECTED RETURN VALUE(s) # ============================= # bool _return # """\ Perform the array stress test. Return true if all the algorithms work okay. """ # DO-NOT-DELETE splicer.begin(stressTest) result = 1 tracker = RegOut.getInstance() for alg in algs: data = sorting.IntegerContainer.IntegerContainer() cont = sorting.Container.Container(data) intcomp = sorting.CompInt.CompInt() comp = sorting.Comparator.Comparator(intcomp) name = alg.getName() tracker.writeComment("****ALGORITHM IS " + name + "****") for size in testSizes: intcomp.setSortIncreasing(1) tracker.writeComment("DATA SIZE " + str(size)) data.setLength(size) result = sortAndReport(alg, cont, comp, result) tracker.writeComment("pre-sorted list") result = sortAndReport(alg, cont, comp, result) tracker.writeComment("reverse sorted list") intcomp.setSortIncreasing(0) result = sortAndReport(alg, cont, comp, result) sys.stdout.flush() return result