def test_bubble_sort(self): """ Testing speed for 'bubblesort' """ print("Bubblesort") Sorting.bubble_sort(self.postList, 'likes') print("Bubblesort test done")
def test_quick_sort(self): """ Testing speed for 'Quicksort' """ print("Quicsort") lenlist = len(self.postList) Sorting.quick_sort(self.postList, 0, lenlist-1, 'likes') print("Quicksort test done")
def test_get_median(self): lenlist = len(self.alist) # necessary to sort the list first on the relevant attribute Sorting.quick_sort(self.alist, 0 , lenlist-1, 'likes') median = statistical.get_median(self.alist, 'likes') self.assertEqual(median, 15)
def test_quick_sort1(self): """ Testing functionality for 'Quicksort' """ lenoflist = len(self.shortlist) Sorting.quick_sort(self.shortlist, 0, lenoflist-1, 'likes') tweet.print_tweetlist(self.shortlist) self.assertEqual(self.shortlist[0].get_likes(), 1) self.assertEqual(self.shortlist[1].get_likes(), 2) self.assertEqual(self.shortlist[2].get_likes(), 3) self.assertEqual(self.shortlist[3].get_likes(), 4) self.assertEqual(self.shortlist[4].get_likes(), 5) self.assertEqual(self.shortlist[5].get_likes(), 6) self.assertEqual(self.shortlist[6].get_likes(), 7) self.assertEqual(self.shortlist[7].get_likes(), 8) self.assertEqual(self.shortlist[8].get_likes(), 9) self.assertEqual(self.shortlist[9].get_likes(), 10)
def test_bubble_sort1(self): """ Testing functionality for 'Bubblesort' Also testing stability of 'bubblesort' """ SortedList = Sorting.bubble_sort(self.shorterlist, 'likes') tweet.print_tweetlist(SortedList) self.assertEqual(SortedList[0].get_likes(), 0) self.assertEqual(SortedList[1].get_likes(), 2) self.assertEqual(SortedList[2].get_likes(), 3) self.assertEqual(SortedList[3].get_likes(), 3) #testing stability: self.assertEqual(SortedList[2].get_message(), "first2") self.assertEqual(SortedList[3].get_message(), "second2") self.assertEqual(SortedList[4].get_likes(), 4) self.assertEqual(SortedList[5].get_likes(), 5) self.assertEqual(SortedList[6].get_likes(), 15)
import random from Sorting import Sorting testCases = [] # small testcase testCases.append(random.sample(range(-99, 99), 10)) # medium testcase testCases.append(random.sample(range(-999, 999), 1000)) # large testcase testCases.append(random.sample(range(-9999, 9999), 10000)) for testCase in testCases: n = len(testCase) s = Sorting() print("Initial unsorted list: {}".format(testCase)) s.bubbleSort(testCase, n) s.selectionSort(testCase, n) s.insertionSort(testCase, n) s.mergeSort(testCase, n) s.radixSort(testCase, n) s.heapSort(testCase, n) s.quicksort(testCase, n) print("\n\n")
import csv import argparse import sys import requests from Filtering import Filtering from Sorting import Sorting from File_processing import File_processing file_processing = File_processing() filtering = Filtering() sorting = Sorting() file_processing.Save_file() parser = argparse.ArgumentParser(description='Arguments') parser.add_argument("--sort_by", type=str, help="Name of column") parser.add_argument("--filter_by", required=False, type=str, help="", nargs=2) args = parser.parse_args() sort_by_args = args.sort_by filter_by_args = args.filter_by if len(sys.argv) == 1: print("Choose one option: sort_by or filter_by") elif sys.argv[1] == "--sort_by": sorting.Sort(sort_by_args) elif sys.argv[1] == "--filter_by": filtering.Filter(sys.argv[2], sys.argv[3])