def main(): # Check number of the arguments algo = 'bubble' if len(argv) == 2: algo = argv[1] elif len(argv) > 2: quit_with_usage() # Create a new Sorter object and set the algorithm sorter = Sorter() try: sorter.set_algorithm(algo) except AlgorithmNotImplementedError: print("No such algorithm: %s" % algo) quit_with_usage() # Doubling Test setting trials = 100 n = 64 print("# Perform a doubling test for {} sort with {} trials".format(algo, trials)) print("starting with n = {}".format(n)) # Time how long it takes to sort sorter.generate_new_tuple(n) previous = sorter.time_trials(trials) print('n: {0:7d} time: {1:7f} (n:n/2) ratio: -'.format(n, previous)) while True: n *= 2 sorter.generate_new_tuple(n) current = sorter.time_trials(trials) ratio = float(current / previous) print('n: {0:7d} time: {1:7f} (n:n/2) ratio: {2:7f}'.format(n, current, ratio)) previous = current
def test_empty_file(self): self.create_file_for_check("") sorter = Sorter(input_file_name="test.txt", separators="_", is_bar_need=False) sorter.split_file_into_sorted_tmp_files() os.chdir(sorter.path_tmp_dir) tmp_file_0 = open("0.tmp", "r") self.assertEqual("", tmp_file_0.read()) tmp_file_0.close()
class TestCompareStrings(unittest.TestCase): multisorter = Sorter(input_file_name="", separators="_", is_bar_need=False) stable_sorter = Sorter(input_file_name="", separators="_", is_multisorting=False, column_for_sort=2, is_bar_need=False) def make_test_multisorting(self, strings): self.assertEqual( self.multisorter.compare_for_multisorting(strings), self.multisorter.compare_strings(strings) ) def make_test_stable_sorting(self, strings): self.assertEqual( self.stable_sorter.compare_for_stable_sorting(strings), self.stable_sorter.compare_strings(strings) ) def test_multisorting(self): self.make_test_multisorting([""]) self.make_test_multisorting(["a"]) self.make_test_multisorting(["a", "", "b"]) self.make_test_multisorting(["", "b"]) self.make_test_multisorting(["4", "tr", "", ""]) self.make_test_multisorting(["a", "b", "c"]) self.make_test_multisorting(["a_b_c", "a_b", "a"]) self.make_test_multisorting(["ab", "aa", "ad"]) self.make_test_multisorting(["a_bz", "aaaa"]) self.multisorter.is_reverse = True self.make_test_multisorting([""]) self.make_test_multisorting(["a"]) self.make_test_multisorting(["a", "", "b"]) self.make_test_multisorting(["", "b"]) self.make_test_multisorting(["4", "tr", "", ""]) self.make_test_multisorting(["a", "b", "c"]) self.make_test_multisorting(["a_b_c", "a_b", "a"]) self.make_test_multisorting(["ab", "aa", "ad"]) self.make_test_multisorting(["a_bz", "aaaa"]) def test_stable_sorting(self): self.make_test_stable_sorting(["a_324_a_a"]) self.make_test_stable_sorting(["_0_"]) self.make_test_stable_sorting(["_4_", "aa_45_br_45"]) self.make_test_stable_sorting(["aa_35_eg", "_7_"]) self.make_test_stable_sorting(["a_4_b_a", "b_3_a_b"]) self.make_test_stable_sorting(["b_4_a_b", "b_3_c_b"]) self.make_test_stable_sorting(["a_4_b_a", "b_3_a_b", "a_0_b_a"]) self.make_test_stable_sorting(["a_4_bc", "a_12_fx"]) self.stable_sorter.is_reverse = True self.make_test_stable_sorting(["a_324_a_a"]) self.make_test_stable_sorting(["_0_"]) self.make_test_stable_sorting(["_4_", "aa_45_br_45"]) self.make_test_stable_sorting(["aa_35_eg", "_7_"]) self.make_test_stable_sorting(["a_4_b_a", "b_3_a_b"]) self.make_test_stable_sorting(["b_4_a_b", "b_3_c_b"]) self.make_test_stable_sorting(["a_4_b_a", "b_3_a_b", "a_0_b_a"]) self.make_test_stable_sorting(["a_4_bc", "a_12_fx"])
def go_sort(): arr = np.random.randint(1000, size=10).tolist() compare_arr = sorted(arr) sorter = Sorter() assert sorter.sort(arr) == compare_arr assert sorter.sort(arr, 'merge') == compare_arr assert sorter.sort(arr, 'radix') == compare_arr print sorter.sort(arr, args.mode)
def __init__(self): data_extractor = DataExtractor() self.sorter = Sorter(contigs=data_extractor.ctgs, markers=data_extractor.mrkrs) self.chr_ctg = self.sorter.chr_ctg_dict() self.ctg_fasta = list(Fasta_B10v2_c_corr().generator( )) # namedtuple('FastaRecord', ['id', 'sequence']) self.ctg_fasta_dict = self.dict_ctg_fasta() self.chr_ctg_order = self.sorter.ctg_order_in_chr() self.Contig = namedtuple("Contig", ['id', 'start', 'length', 'seq'])
def test_with_4_strig_and_sorting(self): self.create_file_for_check( "ccc_bbb_aaa\naaa_ccc_bbb\nbbb_ccc_aaa\naaa_bbb_ccc") multisorter = Sorter(input_file_name="test.txt", separators="_", strings_in_tmp_file=2, is_bar_need=False) stable_sorter = Sorter(input_file_name="test.txt", separators="_", is_multisorting=False, column_for_sort=2, strings_in_tmp_file=2, is_bar_need=False) multisorter.split_file_into_sorted_tmp_files() os.chdir(multisorter.path_tmp_dir) tmp_file_0 = open("0.tmp", "r") tmp_file_1 = open("1.tmp", "r") self.assertEqual("aaa_ccc_bbb\nccc_bbb_aaa", tmp_file_0.read()) self.assertEqual("aaa_bbb_ccc\nbbb_ccc_aaa", tmp_file_1.read()) tmp_file_0.close() tmp_file_1.close() os.chdir(stable_sorter.path_tmp_dir) stable_sorter.split_file_into_sorted_tmp_files() tmp_file_0 = open("0.tmp", "r") tmp_file_1 = open("1.tmp", "r") self.assertEqual("bbb_0_ccc_bbb_aaa\nccc_1_aaa_ccc_bbb", tmp_file_0.read()) self.assertEqual("bbb_3_aaa_bbb_ccc\nccc_2_bbb_ccc_aaa", tmp_file_1.read()) tmp_file_0.close() tmp_file_1.close() self.assertEqual( len(stable_sorter.tmp_files_names), 2 )
class TestSortText(unittest.TestCase): multisorter = Sorter(input_file_name="", is_reverse=False, is_multisorting=True, separators="_", is_bar_need=False) stable_sorter1 = Sorter(input_file_name="", is_reverse=False, is_multisorting=False, separators="_", column_for_sort=2, is_bar_need=False) stable_sorter2 = Sorter(input_file_name="", is_reverse=False, is_multisorting=False, separators="_", column_for_sort=2, is_bar_need=False) def refresh_sorter(self): self.stable_sorter1.string_counter = 0 self.stable_sorter2.string_counter = 0 def test_empty_string(self): self.refresh_sorter() self.assertEqual( self.multisorter.multisorting_text(""), self.multisorter.sort_text("") ) self.assertEqual( self.stable_sorter1.stable_sorting_text(""), self.stable_sorter2.sort_text("") ) def test_text_with_single_string(self): self.refresh_sorter() self.assertEqual( self.multisorter.multisorting_text("123_456_789"), self.multisorter.sort_text("123_456_789") ) self.assertEqual( self.stable_sorter1.stable_sorting_text("123_456_789"), self.stable_sorter2.sort_text("123_456_789") ) def test_text_with_any_string(self): self.refresh_sorter() self.assertEqual( self.multisorter.multisorting_text( "aaa_1_bbb_aaa_ccc\naaa_2_ccc_aaa_bbb\nbbb_0_aaa_bbb_ccc"), self.multisorter.sort_text( "aaa_1_bbb_aaa_ccc\naaa_2_ccc_aaa_bbb\nbbb_0_aaa_bbb_ccc") ) self.assertEqual( self.stable_sorter1.stable_sorting_text( "aaa_1_bbb_aaa_ccc\naaa_2_ccc_aaa_bbb\nbbb_0_aaa_bbb_ccc"), self.stable_sorter2.sort_text( "aaa_1_bbb_aaa_ccc\naaa_2_ccc_aaa_bbb\nbbb_0_aaa_bbb_ccc") )
class TestMultisortingTest(unittest.TestCase): sorter = Sorter(input_file_name='', separators='_', is_bar_need=False) sorter_reverse = Sorter(input_file_name='', separators='_', is_reverse=True, is_bar_need=False) def test_empty_test(self): self.assertEqual( '', self.sorter.multisorting_text('') ) self.assertEqual( '', self.sorter_reverse.multisorting_text('') ) def test_text_with_single_string(self): self.assertEqual( 'a_b_c', self.sorter.multisorting_text('a_b_c') ) self.assertEqual( 'c_b_a', self.sorter_reverse.multisorting_text('c_b_a') ) def test_text_with_any_strings(self): self.assertEqual( '1__hy_hiyb\n1_a_ij_j_jo\n2_a_yjtytj', self.sorter.multisorting_text( '1__hy_hiyb\n2_a_yjtytj\n1_a_ij_j_jo') ) self.assertEqual( '2_a_yjtytj\n1_a_ij_j_jo\n1__hy_hiyb', self.sorter_reverse .multisorting_text('1_a_ij_j_jo\n2_a_yjtytj\n1__hy_hiyb') ) def test_smth_goes_wrong(self): self.assertEqual( 'explode\nexplode acceptable capital explode', self.sorter.multisorting_text( 'explode\nexplode acceptable capital explode') ) self.assertEqual( 'explode\nexplode acceptable capital explode', self.sorter.multisorting_text( 'explode acceptable capital explode\nexplode') )
def saveConfFile(self): confBackupFilePath = os.path.join(self.scriptDir, "conf.bak") if os.path.exists(confBackupFilePath): os.remove(confBackupFilePath) shutil.copy2(os.path.join(self.scriptDir, "conf.conf"), os.path.join(self.scriptDir, "conf.bak")) confFile = open(os.path.join(self.scriptDir, "conf.conf"), "w", encoding="utf-8") listKeys = sorted(self.guiStrings.values(), key=attrgetter('order')) for key in listKeys: if key.id not in ['verify', 'save', 'proceed', 'confirm']: if key.help: confFile.write('# ' + key.help.replace('#n', '\n# ') + '\n') if key.id == 'images': imagesValue = self.guiVars[self.guiStrings['images'].label + ' #1'].get() if self.guiStrings['images'].label + ' #2' in self.guiVars: imagesValue = imagesValue + '|' + self.guiVars[ self.guiStrings['images'].label + ' #2'].get() confFile.write(key.id + ' = ' + imagesValue + '\n') elif key.id == 'keepLevel': confFile.write( key.id + ' = ' + str(Sorter.getIntStatus(self.guiVars[key.id].get())) + '\n') else: if key.id in self.guiVars: confFile.write(key.id + ' = ' + str(self.guiVars[key.id].get()) + '\n') confFile.close() self.logger.log(' Configuration saved in conf.conf file')
def make_test(self, text, result): tmp_dir = tempfile.mkdtemp() os.chdir(tmp_dir) tmp_file = open("4.tmp", "w") tmp_file.write(text) tmp_file.close() sorter = Sorter(input_file_name="", separators="_", is_multisorting=False, column_for_sort=2, is_bar_need=False) sorter.path_tmp_dir = tmp_dir sorter.prepare_stable_sorting_file_to_replace("4.tmp") tmp_file = open("4.tmp", "r") self.assertEqual( result, tmp_file.read() ) tmp_file.close()
def __init__(self, tamp): self.tamp = tamp #motor left self.motorL = Motor(self.tamp, 2, 4) self.motorL.write(1, 0) #motor right self.motorR = Motor(self.tamp, 1, 3) self.motorR.write(1, 0) #arm servo self.arm = Arm(self.tamp) #sorting servo self.sorter = Sorter(self.tamp)
def test_sortcrawl_sd_dir(self): with Sorter(db_handler=self.db_handler) as sortbot9k: sortbot9k.scrape_directories(self.sd_directory) sortbot9k.sort_onions(self.class_tests) uptodate_class, uptodate_name = \ self.db_handler.get_onion_class(self.get_cur_runtime(), True) self.assertEqual(type(uptodate_class), dict) # At least 10 of our instances should be on the latest version self.assertGreaterEqual(len(uptodate_class), 10) self.assertRegex(list(uptodate_class)[0], "http") self.assertRegex(list(uptodate_class)[0], ".onion") outofdate_class, outofdate_name = \ self.db_handler.get_onion_class(self.get_cur_runtime(), False) self.assertEqual(type(outofdate_class), dict) # At least 1 of our instances will be lagging behind versions :'( self.assertGreaterEqual(len(outofdate_class), 1) self.assertRegex(list(outofdate_class)[0], "http") self.assertRegex(list(outofdate_class)[0], ".onion") class_data = self.db_handler.get_onions(self.get_cur_runtime()) nonmonitored_name, monitored_name = class_data.keys() # Test that we get the expected class names, and data types back self.assertEqual(nonmonitored_name, 'nonmonitored') self.assertRegex(monitored_name, 'sd') nonmonitored_class, monitored_class = class_data.values() self.assertEqual(type(nonmonitored_class), dict) self.assertEqual(type(monitored_class), dict) with Crawler(db_handler=self.db_handler) as crawlbot9k: crawlbot9k.collect_set_of_traces(nonmonitored_class)
def run(self): parser = MovieIdParser(self.moviecount) parser.run_parser() fetcher = MovieDataFetcher(parser.idcontainer) fetcher.run() sortedmovies = Sorter.sort_by_year(fetcher.fullmoviesdata) #Save.save_to_csv(sortedmovies, self.file) Save.save_to_db(sortedmovies)
class TestStableSortingTest(unittest.TestCase): sorter = Sorter(separators='_', is_multisorting=False, column_for_sort=2, input_file_name="", is_bar_need=False) sorter_reverse = Sorter(separators='_', is_reverse=True, is_multisorting=False, column_for_sort=2, input_file_name="", is_bar_need=False) def refresh_sorters(self): self.sorter.string_counter = 0 self.sorter_reverse.string_counter = 0 def test_empty_text(self): self.refresh_sorters() self.assertEqual( "", self.sorter.stable_sorting_text("") ) self.assertEqual( "", self.sorter_reverse.stable_sorting_text("") ) def test_text_with_single_string(self): self.refresh_sorters() self.assertEqual( "456_0_123_456_789", self.sorter.stable_sorting_text("123_456_789") ) self.assertEqual( "456_0_123_456_789", self.sorter_reverse.stable_sorting_text("123_456_789") ) def test_any_text(self): self.refresh_sorters() self.assertEqual( "aaa_1_bbb_aaa_ccc\naaa_2_ccc_aaa_bbb\nbbb_0_aaa_bbb_ccc", self.sorter.stable_sorting_text( "aaa_bbb_ccc\nbbb_aaa_ccc\nccc_aaa_bbb") ) self.assertEqual( "bbb_0_aaa_bbb_ccc\naaa_2_ccc_aaa_bbb\naaa_1_bbb_aaa_ccc", self.sorter_reverse.stable_sorting_text( "aaa_bbb_ccc\nbbb_aaa_ccc\nccc_aaa_bbb") )
def test_sort(self): all_m = ProcessRegex.all_matches(self.regex1, self.list_tring) sorter = Sorter(SortMethod.abc, SortOrder.asc) list_s = sorter.beginSorting(all_m) self.assertEqual(list_s[3], "*****@*****.**") self.assertEqual(list_s[14], "*****@*****.**") sorter = Sorter(SortMethod.abc, SortOrder.desc) list_s = sorter.beginSorting(all_m) self.assertEqual(list_s[0], "*****@*****.**") sorter = Sorter(SortMethod.freq, SortOrder.asc) list_s = sorter.beginSorting(all_m) self.assertEqual(list_s[0], "*****@*****.**")
def make_test(self, texts, count_of_merging, result, reverse=False, multisorting=True): sorter = Sorter(input_file_name="", separators="_", is_reverse=reverse, is_multisorting=multisorting, column_for_sort=2, is_bar_need=False) self.prepare_to_check(sorter, texts) tmp_files_counter = sorter.tmp_file_counter sorter.merging_any_tmp_files(count_of_merging) self.assertTrue(sorter.tmp_file_counter - 1 == tmp_files_counter) self.assertTrue( len(sorter.tmp_files_names) == len(texts) - count_of_merging + 1) self.assertTrue(str(len(texts)) + ".tmp" in sorter.tmp_files_names) result_file = open(str(len(texts)) + ".tmp", 'r') self.assertEqual( result, result_file.read() ) result_file.close()
class SorterTests(unittest.TestCase): def setUp(self): self._unsorted = [7,2,1,8,11,5,3,4] self._sorted = [1,2,3,4,5,7,8,11] self.sorter = Sorter() def test_bubbleSort(self): self.assertEqual(self._sorted, self.sorter.bubble_sort(self._unsorted)) def test_selectionSort(self): self.assertEqual(self._sorted, self.sorter.selection_sort(self._unsorted)) def test_insertionSort(self): self.assertEqual(self._sorted, self.sorter.insertion_sort(self._unsorted)) def test_shellSort(self): self.assertEqual(self._sorted, self.sorter.shell_sort(self._unsorted))
def setUpClass(cls): cls.sorter = Sorter({ 'alex': 1120, 'andre': -130, 'bernhard': 3000, 'david': 5460, 'petra': 1120, 'olga': 1120 })
def clickProceed(self) : self.logger.log('\n<--------- Starting Process --------->') self.saveConfInMem() message=self.guiStrings['confirm'].help.replace('{outputDir}',self.guiVars['exportDir'].get()).replace('#n','\n') result = messagebox.askokcancel(self.guiStrings['confirm'].label,message) if result : self.verifyButton['state'] = 'disabled' self.saveButton['state'] = 'disabled' self.proceedButton['state'] = 'disabled' self.logger.log('\n<--------- Starting Process --------->') sorter = Sorter(self.configuration,self.scriptDir,self.logger) _thread.start_new(sorter.process,())
def do_tests(self, texts, result): sorter = Sorter(input_file_name="", separators="_", is_bar_need=False) tmp_dir = tempfile.mkdtemp() os.chdir(tmp_dir) sorter.path_tmp_dir = tmp_dir counter = 0 for text in texts: input_file = open(str(counter) + ".tmp", "w") counter += 1 sorter.tmp_file_counter += 1 sorter.tmp_files_names.append(input_file.name) input_file.write(text) input_file.close() sorter.merging_all_tmp_files() result_file = open(sorter.tmp_files_names[0], 'r') self.assertEqual( result, result_file.read() ) result_file.close()
class Actuators: def __init__(self,tamp): self.tamp=tamp #motor left self.motorL = Motor(self.tamp, 2, 4) self.motorL.write(1,0) #motor right self.motorR = Motor(self.tamp,1, 3) self.motorR.write(1,0) #arm servo self.arm = Arm(self.tamp) #sorting servo self.sorter = Sorter(self.tamp) def update(self): self.arm.update() self.sorter.update()
class Actuators: def __init__(self, tamp): self.tamp = tamp #motor left self.motorL = Motor(self.tamp, 2, 4) self.motorL.write(1, 0) #motor right self.motorR = Motor(self.tamp, 1, 3) self.motorR.write(1, 0) #arm servo self.arm = Arm(self.tamp) #sorting servo self.sorter = Sorter(self.tamp) def update(self): self.arm.update() self.sorter.update()
def run(self): # Read file file_reader = FileReader(self.file_path) file_reader.parse() # Store output in data object data = Data(raw_data=file_reader.result) # Sort data sorter = Sorter(raw_data=file_reader.result) sorter.create_time_employee() sorter.create_time_sorted() # Store sorted data in data object data.time_employee = sorter.time_employee data.time_sorted = sorter.time_sorted # Create statistics stats = StatsGenerator(data) stats.calculate_average_working_time() # Write data to files file_writer = FileWriter(data, stats.get_statistics) file_writer.create_stats_output() file_writer.create_data_output() file_writer.write2json() file_writer.write2cvs()
class ContigsCompleteData(): def __init__(self): data_extractor = DataExtractor() self.sorter = Sorter(contigs=data_extractor.ctgs, markers=data_extractor.mrkrs) self.chr_ctg = self.sorter.chr_ctg_dict() self.ctg_fasta = list(Fasta_B10v2_c_corr().generator( )) # namedtuple('FastaRecord', ['id', 'sequence']) self.ctg_fasta_dict = self.dict_ctg_fasta() self.chr_ctg_order = self.sorter.ctg_order_in_chr() self.Contig = namedtuple("Contig", ['id', 'start', 'length', 'seq']) def dict_ctg_fasta(self): return {ctg.id: ctg.sequence for ctg in self.ctg_fasta} def chr_sumCtgLen(self): ''' dict {chr: sum(ctg_len}''' ret = {} for chr in self.chr_ctg: ret[chr] = sum([ctg['contig_length'] for ctg in self.chr_ctg[chr]]) return ret def sum_ctg_exel(self): chr_sumCtg = self.chr_sumCtgLen() return sum([chr_sumCtg[chr] for chr in chr_sumCtg.keys()]) def sum_ctg_fasta(self): ''' :return sum contigs from gff file''' return sum([len(fasta.sequence) for fasta in self.ctg_fasta]) def percent_known_genome(self): return self.sum_ctg_exel() / float(self.sum_ctg_fasta()) @staticmethod def convert_int_to_ctg_id(id): return "ctg" + str(id) @staticmethod def convert_ctgId_to_int(ctg_id): return ctg_id[3:]
def test_multisort(self): with open('file.txt', 'w')as file: for i in range(11): file.write(str(i) + '\n') s = Sorter('file.txt') s.sort() sorted = get_text('file.txt') self.assertEqual(sorted, ['0', '1', '10', '2', '3', '4', '5', '6', '7', '8', '9']) s = Sorter('file.txt', is_reversible=True) s.sort() sorted = get_text('file.txt') self.assertEqual(sorted, ['9', '8', '7', '6', '5', '4', '3', '2', '10', '1', '0']) os.remove('file.txt')
def __init__(self, environment): """default constructor""" super(Main_Manager, self).__init__("main_manager", environment) self.inv_editor = Inv_Editor() self.login_controller = Login_Controller() self.searcher = Searcher() self.sorter = Sorter() self.username_entry = None self.password_entry = None self.main_menu = Main_Menu() self.working = True self.username = "" self.password = "" self.initialize_DB()
def __clickProceed(self): self.logger.log('\n<--------- Saving retroarch configuration --------->') self.__saveConfInMem() message = self.guiStrings['confirm'].help.replace('{outputDir}', self.guiVars['exportDir'].get()).replace('#n', '\n') result = messagebox.askokcancel(self.guiStrings['confirm'].label, message) if result: self.verifyButton['state'] = 'disabled' self.saveButton['state'] = 'disabled' self.proceedButton['state'] = 'disabled' self.mummy.disableOtherTabs('retroarch', self.hardware) self.logger.log('\n<--------- Starting retroarch Process --------->') sorter = Sorter(self.configuration, self.scriptDir, partial(self.postProcess), self.logger, self.hardware) _thread.start_new(sorter.process, ())
def createMasterInspectionXML(self, delChildXMLs = False): lt = ListTool() os = OSTool() sort = Sorter() insp = Inspector() xmls = os.getFilesInDir('results/') xmls = lt.popByWord(xmls, self.masterInspectionPath) XMLInspections = insp.getInspections(xmls) if len(XMLInspections) == 0: print('No files read.') exit() XMLInspections = sort.sortInspectionList(XMLInspections) xWriter = XMLWriter() xWriter.writeMIXML(XMLInspections, self.masterInspectionPath) if delChildXMLs: for xml in xmls: os.deleteFile(xml)
def saveConfInMem(self) : listKeys = sorted(self.guiStrings.values(), key=attrgetter('order')) for key in listKeys : if key.id not in ['verify','save','proceed','confirm'] : if key.id == 'images' : imagesValue = self.guiVars[self.guiStrings['images'].label+' #1'].get() if self.guiStrings['images'].label+' #2' in self.guiVars : imagesValue = imagesValue + '|' + self.guiVars[self.guiStrings['images'].label+' #2'].get() self.configuration['images']= imagesValue elif key.id == 'keepLevel' : self.configuration['keepLevel'] = str(Sorter.getIntStatus(self.guiVars[key.id].get())) else : if key.id in self.guiVars : self.configuration[key.id] = str(self.guiVars[key.id].get()) self.logger.log(' Configuration saved in memory')
def test_file_with_single_string(self): self.create_file_for_check("1_2_345_a") multisorter = Sorter(input_file_name="test.txt", separators="_", is_bar_need=False) stable_sorter = Sorter(input_file_name="test.txt", separators="_", is_multisorting=False, column_for_sort=2, is_bar_need=False) multisorter.split_file_into_sorted_tmp_files() os.chdir(multisorter.path_tmp_dir) tmp_file_0 = open("0.tmp", "r") self.assertEqual("1_2_345_a", tmp_file_0.read()) tmp_file_0.close() stable_sorter.split_file_into_sorted_tmp_files() os.chdir(stable_sorter.path_tmp_dir) tmp_file_0 = open("0.tmp", "r") self.assertEqual("2_0_1_2_345_a", tmp_file_0.read()) tmp_file_0.close()
def __init__(self,tamp): self.tamp=tamp #motor left self.motorL = Motor(self.tamp, 2, 4) self.motorL.write(1,0) #motor right self.motorR = Motor(self.tamp,1, 3) self.motorR.write(1,0) #arm servo self.arm = Arm(self.tamp) #sorting servo self.sorter = Sorter(self.tamp)
def test_million_strings(self): f = None try: f = open('million.txt', 'r') except: pass if f is not None: f.close() s = Sorter('million.txt') s.sort() f = open('million.txt', 'r') self.assertEqual(f.read(1), ' ') f.close() s = Sorter('million.txt',is_reversible=True) s.sort() f= open('million.txt', 'r') self.assertEqual(f.read(1), 'Z') f.close()
def __init__(self, **options): super().__init__(**options) self.main_guild = None self.main_channel = None self.command_channel = None self.create_voice_channel = None self.color_change_message = None self.invite_create_message = None self.shuffle_roles_message = None self.command_messages = {} self.color_roles = {} self.sorter = Sorter() self.inviter = Inviter() self.referral_patrol = ReferralPatrol() self.channel_creator = VoiceChannelCreator()
class TestMakeAndDeleteTmpDir(unittest.TestCase): sorter = Sorter(separators='', input_file_name='', is_bar_need=False) def test_all(self): self.create_tmp_dir_test() self.delete_tmp_dir_test() def create_tmp_dir_test(self): self.sorter.make_tmp_dir(None) tmp_dir_name = re.split('[\\\|/]', self.sorter.path_tmp_dir)[ len(re.split('[\\\|/]', self.sorter.path_tmp_dir)) - 1] self.assertTrue(tmp_dir_name in os.listdir(tempfile.gettempdir())) def delete_tmp_dir_test(self): self.sorter.delete_tmp_dir() tmp_dir_name = re.split('[\\\|/]', self.sorter.path_tmp_dir)[ len(re.split('[\\\|/]', self.sorter.path_tmp_dir)) - 1] self.assertFalse( tmp_dir_name in os.listdir(tempfile.gettempdir()))
def main(): keyword = str(input('please input keyword\n')) targetSite = str(input('please input target site\n')) if keyword == '': print('no keyword') else: if isFilterWanted(): filter = Filter() filter.set() else: filter = Filter() if isSortWanted(): sorter = Sorter() sorter.set() else: sorter = Sorter() if targetSite.lower() == 'pchome': search.searchOnPChome(keyword, filter, sorter) elif targetSite.lower() == 'shopee' or targetSite.lower( ) == 'xiapi' or targetSite == '蝦皮': search.searchOnShopee(keyword, filter, sorter) elif targetSite.lower() == 'qoo10': search.searchOnQoo10(keyword, filter, sorter) elif targetSite.lower() == 'etmall' or targetSite == '東森': search.searchOnEtmall(keyword, filter, sorter) elif targetSite.lower() == 'rakuten' or targetSite == '樂天': search.searchOnRakuten(keyword, filter, sorter) elif targetSite.lower() == 'all': search.searchOnPChome(keyword, filter, sorter) search.searchOnShopee(keyword, filter, sorter) search.searchOnQoo10(keyword, filter, sorter) search.searchOnEtmall(keyword, filter, sorter) elif targetSite.lower() == 'exit': exit() else: print('target site is not supported\nPlease input again or exit') main() #recursive
def do_test(self): tmp_dir = tempfile.mkdtemp() os.chdir(tmp_dir) self.create_random_file("test.txt", 5000, 30) sorter = Sorter(input_file_name="test.txt", separators=" ", is_bar_need=False) sorter.strings_in_tmp_file = 50 sorter.sort() result_file = open("test.txt", 'r') previous_string = result_file.readline().replace("\n", "") current_string = result_file.readline().replace("\n", "") while current_string != "": self.assertEqual(0, sorter.compare_strings( [previous_string, current_string])) previous_string = current_string current_string = result_file.readline().replace("\n", "") result_file.close()
def setUp(self): self._unsorted = [7,2,1,8,11,5,3,4] self._sorted = [1,2,3,4,5,7,8,11] self.sorter = Sorter()
def writeNewMasterInspectionXML(self): sort = Sorter() self.XMLInspections = sort.sortInspectionList(self.XMLInspections) xWriter = XMLWriter() xWriter.writeMIXML(self.XMLInspections, self.masterInspectionPath)