def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' dictInput = pickle.load( open("testInputA4.pkl" )) ## load the dictionary containing output types and test cases testCases = dictInput['testCases'] outputType = dictInput['outputType'] if partIdx == 0: # This is A4-part-1: extractMainLobe for line in testCases['A4-part-1']: answer = extractMainLobe(**line) if outputType['A4-part-1'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-1'][0], partIdx) return '' #sys.exit(1) elif partIdx == 1: # This is A4-part-2: computeSNR for line in testCases['A4-part-2']: answer = computeSNR(**line) if outputType['A4-part-2'][0] == type(answer): if len(answer) == 2: outputString += convertNpObjToStr( np.array([answer[0], answer[1]])) + '\n' else: print "Error in Part 2 - The output python tuple should contain only 2 elements (SNR1, SNR2)" return '' #sys.exit(1) else: wrongOutputTypeError(outputType['A4-part-2'][0], partIdx) return '' #sys.exit(1) elif partIdx == 2: # This is A4-part-3: computeEngEnv for line in testCases['A4-part-3']: answer = computeEngEnv(**line) if outputType['A4-part-3'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-3'][0], partIdx) return '' #sys.exit(1) elif partIdx == 3: # This is A2-part-4: computeODF for line in testCases['A4-part-4']: answer = computeODF(**line) if outputType['A4-part-4'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-4'][0], partIdx) return '' #sys.exit(1) return outputString.strip()
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' dictInput = pickle.load(open("testInputA4.pkl")) ## load the dictionary containing output types and test cases testCases = dictInput['testCases'] outputType = dictInput['outputType'] if partIdx == 0: # This is A4-part-1: extractMainLobe for line in testCases['A4-part-1']: answer = extractMainLobe(**line) if outputType['A4-part-1'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-1'][0],partIdx) return '' #sys.exit(1) elif partIdx == 1: # This is A4-part-2: computeSNR for line in testCases['A4-part-2']: answer = computeSNR(**line) if outputType['A4-part-2'][0] == type(answer): if len(answer)==2: outputString += convertNpObjToStr(np.array([answer[0], answer[1]])) + '\n' else: print "Error in Part 2 - The output python tuple should contain only 2 elements (SNR1, SNR2)" return '' #sys.exit(1) else: wrongOutputTypeError(outputType['A4-part-2'][0],partIdx) return '' #sys.exit(1) elif partIdx == 2: # This is A4-part-3: computeEngEnv for line in testCases['A4-part-3']: answer = computeEngEnv(**line) if outputType['A4-part-3'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-3'][0],partIdx) return '' #sys.exit(1) elif partIdx == 3: # This is A2-part-4: computeODF for line in testCases['A4-part-4']: answer = computeODF(**line) if outputType['A4-part-4'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A4-part-4'][0],partIdx) return '' #sys.exit(1) return outputString.strip()