def processLines(f, dictionaries): dict = {} lineCount = 0 for line in f: #Ignoring header (first line) if needed. if lineCount == 0: lineCount += 1 if ignoreHeader: continue columns = columnsMask.lower().split(separator) values = line.split(separator) for column in columns: column = Utilities.sanitise(column.lower()) #meaningless columns defined by 'null' or empty value if column == "null" or column == "": continue if len(values) <= columns.index(column): dict[column] = "" else: dict[column] = Utilities.sanitise( values[columns.index(column)]) #'name' and 'classname' are mandatory. Ignoring lines without any of these fields. if not (dict["name"] == "" or dict["classname"] == "" or dict["status"] == ""): if dict["classname"] in dictionaries: dictionaries[dict["classname"]].append(dict.copy()) else: dictionaries[dict["classname"]] = [] dictionaries[dict["classname"]].append(dict.copy())
def test_ConvertIngredientInDifferentCategoryUnit(self): ing = Models.RecipeIngredient(name='Flour', amount='10', unit='tbsps') # convert to ounces converted = RecipeOperations.RecipeOperations.convertIngredientToUnit( ing, 'oz') convertedAmount = Utilities.convert_to_float(converted.amount) self.assertAlmostEqual(2.65, round(convertedAmount, 2))
def fromInt(i): Utilities.checkRange(i, 1, 8) if i == 1 : return EnumWeekday.MONDAY elif i == 2 : return EnumWeekday.TUESDAY elif i == 3 : return EnumWeekday.WEDNESDAY elif i == 4 : return EnumWeekday.THURSDAY elif i == 5 : return EnumWeekday.FRIDAY elif i == 6 : return EnumWeekday.SATURDAY elif i == 7 : return EnumWeekday.SUNDAY
def fromInt(i): Utilities.checkRange(i, 1, 8) if i == 1: return EnumWeekday.MONDAY elif i == 2: return EnumWeekday.TUESDAY elif i == 3: return EnumWeekday.WEDNESDAY elif i == 4: return EnumWeekday.THURSDAY elif i == 5: return EnumWeekday.FRIDAY elif i == 6: return EnumWeekday.SATURDAY elif i == 7: return EnumWeekday.SUNDAY
def test_ConvertIngredientInDifferentCategoryBase(self): ing = Models.RecipeIngredient(name='Flour', amount='1 1/2', unit='c') # convert to grams converted = RecipeOperations.RecipeOperations.convertIngredientToUnit( ing, 'g') convertedAmount = Utilities.convert_to_float(converted.amount) self.assertAlmostEqual(180, round(convertedAmount))
def test_bubblesort_with_array( self): #function to test bubble_sort with array result = Utilities.bubble_sort([12, 1, 0, 5, 4, 2]) expected = [0, 1, 2, 4, 5, 2] # self.assertNotEqual( expected, result) # Checking result and expected With NotEqual Function
def test_tempconverTrue( self): #function to test temperature conversion in Celcius result = Utilities.Temp_conversion(2100, 0) #storing the result expected = 1148.888888888889 self.assertTrue( expected, result) # Checking result and expected With True Function
def test_tempconverFalse( self): #function to test temperature conversion in Farheiniet result = Utilities.Temp_conversion(1148.888888888889, 1) #storing the result expected = 2100 self.assertTrue( expected, result) # Checking result and expected With True Function
def test_bubblesort_with_True( self): # function to test bubble sort with True result = Utilities.bubble_sort([12, 1, 0, 5, 4, 2]), [ 0, 1, 2, 4, 5, 12 ] # call the utilities class and storing the result expected = True self.assertTrue( expected, result) # Checking result and expected With True Function
def test_bubblesort_with_possitive_array( self): # function to test bubble sort with positive numbers result = Utilities.bubble_sort( [12, 1, 0, 5, 4, 2]) # call the utilities class and storing the result expected = [0, 1, 2, 4, 5, 12] self.assertEqual( expected, result) # Checking result and expected With Equal Function
def test_ConvertIngredientInSameCategory(self): ing = Models.RecipeIngredient(name='Test Ingredient', amount='1 1/2', unit='cups') # convert to tbsp converted = RecipeOperations.RecipeOperations.convertIngredientToUnit( ing, 'tbsp') convertedAmount = Utilities.convert_to_float(converted.amount) self.assertAlmostEqual(24, round(convertedAmount))
ignoreHeader = args.ignoreheader isVerbose = args.verbose mandatoryColumns = ["name", "status", "classname"] # Print something to console def printToConsole(obj): if isVerbose: print str(obj) ########## STEP 1. Check column mask for mandatory columns ########## printToConsole("\nChecking the list of columns. Mandatory columns are:") for column in mandatoryColumns: printToConsole("\t - " + column) if not Utilities.checkColumnMask(columnsMask, separator, mandatoryColumns): quit() print "\nList of columns is valid" ########## STEP 2. Parse files (or pipe input) into dictionary object ########## # Process a single line def processLines(f, dictionaries): dict = {} lineCount = 0 for line in f: #Ignoring header (first line) if needed. if lineCount == 0: lineCount += 1 if ignoreHeader:
def test_dayofWeekFalse(self): #function to test daysofWeek result = Utilities.dayofWeek(14, 6, 2019) #storing the result expected = False self.assertFalse( expected, result) #Checking result and expected With False Function
def test_monthlypayment(self): #function to test monthly payment result = Utilities.calculatePayment(1200, 1, 13) # storing the result expected = 107.18073085409955 self.assertTrue( expected, result) # Checking result and expected With True Function
def __checkParam(name, tRanges): Utilities.checkInstanceString(name)
def __init__(self, day): Utilities.checkRange(day, 1, 8) self.day = day;
def test_dayofWeekTrue(self): #function to test daysofWeek result = Utilities.dayofWeek(14, 6, 2019) #storing the result expected = "Friday" self.assertTrue( expected, result) #Checking result and expected With True Function
def __checkParam(title, dept, num, sectX, tRanges, sln, description): Utilities.checkInstanceString(title) Utilities.checkInstanceString(dept) Utilities.checkRange(num, 100, 1000) Utilities.checkInstanceString(sectX) Utilities.checkInstanceString(description) # check tRanges later TODO Utilities.checkRange(sln, 0, 1000000)
def testinsertion_sort_with_negative(self): result = (Utilities.insertionSort([-1, 6, 5, 0, -1, -6])) expected = [-6, -1, -1, 0, 5, 6] self.assertEqual(expected, result) # Checking result and expected With Equal Function
def __init__(self, day): Utilities.checkRange(day, 1, 8) self.day = day
def testinsertion_sort_with_negative_num(self): # function to test insertion sort with array of -ve numbers result = (Utilities.insertionSort([-1, 2, -2, 0, -1, -6])) expected = [-6, 0, -1, -1, 0, 2] self.assertNotEqual(expected, result) # Checking result and expected With NotEqual Function
def testpalindromeFalse(self): result = Utilities.Is_palindrome('am') expected = False self.assertTrue(expected, result)
def testinsertionsort_with_possitive_num(self): # function to test insertion sort with array of +ve numbers result = (Utilities.insertionSort([12, 5, 45, 78, 1, 0])) # Pass Array To Insertion Sort Function expected = [0, 1, 5, 12, 45, 78] # Initialize Expected as Sorted Array self.assertEqual(expected, result) # Checking result and expected With Equal Function
def testpalindromeTrue(self): result = Utilities.Is_palindrome('mam') expected = True self.assertTrue(expected, result)
def test_monthlypaymentNotequal(self): #function to test monthly payment result = Utilities.calculatePayment(1200, 2, 13) # storing the result expected = 17.18073085409955 self.assertNotEqual( expected, result) # Checking result and expected With NotEqual Function
def testbinary_search_possitive(self): # function to test binarysearch of posotive number result = Utilities.binary_search(1,4,3,[1,2,3,4,5,6]) # call the uitlites class and storing the result expected = 1 self.assertEqual(expected, result) # Checking result and expected With Equal Function