def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' dictInput = pickle.load(open("testInputA2.pkl")) ## load the dictionary containing output types and test cases testCases = dictInput['testCases'] outputType = dictInput['outputType'] if partIdx == 0: # This is A2-part-1: genSine for line in testCases['A2-part-1']: answer = genSine(**line) if outputType['A2-part-1'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-1'][0],partIdx) return '' #sys.exit(1) elif partIdx == 1: # This is A2-part-2: genComplexSine for line in testCases['A2-part-2']: answer = genComplexSine(**line) if outputType['A2-part-2'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-2'][0],partIdx) return '' #sys.exit(1) elif partIdx == 2: # This is A2-part-3: DFT for line in testCases['A2-part-3']: answer = DFT(**line) if outputType['A2-part-3'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-3'][0],partIdx) return '' #sys.exit(1) elif partIdx == 3: # This is A2-part-4: IDFT for line in testCases['A2-part-4']: answer = IDFT(**line) if outputType['A2-part-4'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-4'][0],partIdx) return '' #sys.exit(1) elif partIdx == 4: # This is A2-part-5: genMagSpec for line in testCases['A2-part-5']: answer = genMagSpec(**line) if outputType['A2-part-5'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-5'][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("testInputA2.pkl")) ## load the dictionary containing output types and test cases testCases = dictInput['testCases'] outputType = dictInput['outputType'] if partIdx == 0: # This is A2-part-1: genSine for line in testCases['A2-part-1']: answer = genSine(**line) if outputType['A2-part-1'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-1'][0]) sys.exit(1) elif partIdx == 1: # This is A2-part-2: genComplexSine for line in testCases['A2-part-2']: answer = genComplexSine(**line) if outputType['A2-part-2'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-2'][0]) sys.exit(1) elif partIdx == 2: # This is A2-part-3: DFT for line in testCases['A2-part-3']: answer = DFT(**line) if outputType['A2-part-3'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-3'][0]) sys.exit(1) elif partIdx == 3: # This is A2-part-4: IDFT for line in testCases['A2-part-4']: answer = IDFT(**line) if outputType['A2-part-4'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-4'][0]) sys.exit(1) elif partIdx == 4: # This is A2-part-5: genMagSpec for line in testCases['A2-part-5']: answer = genMagSpec(**line) if outputType['A2-part-5'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-5'][0]) sys.exit(1) return outputString.strip()
def test_genSine(self): expected = np.array( [0.54030231, -0.63332387, -0.93171798, 0.05749049, 0.96724906]) actual = genSine(1.0, 10.0, 1.0, 50.0, 0.1) self.assertTrue(np.isclose(expected, actual).all())
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = '' filename = open('testInputA2.pkl','rb') try: ## load the dict containing output types and test cases dictInput = pickle.load(filename,encoding='latin1') ## python3 except TypeError: dictInput = pickle.load(filename) ## python2 testCases = dictInput['testCases'] outputType = dictInput['outputType'] if partIdx == 0: # This is A2-part-1: genSine for line in testCases['A2-part-1']: answer = genSine(**line) if outputType['A2-part-1'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-1'][0],partIdx) return '' #sys.exit(1) elif partIdx == 1: # This is A2-part-2: genComplexSine for line in testCases['A2-part-2']: answer = genComplexSine(**line) if outputType['A2-part-2'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-2'][0],partIdx) return '' #sys.exit(1) elif partIdx == 2: # This is A2-part-3: DFT for line in testCases['A2-part-3']: answer = DFT(**line) if outputType['A2-part-3'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-3'][0],partIdx) return '' #sys.exit(1) elif partIdx == 3: # This is A2-part-4: IDFT for line in testCases['A2-part-4']: answer = IDFT(**line) if outputType['A2-part-4'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-4'][0],partIdx) return '' #sys.exit(1) elif partIdx == 4: # This is A2-part-5: genMagSpec for line in testCases['A2-part-5']: answer = genMagSpec(**line) if outputType['A2-part-5'][0] == type(answer): outputString += convertNpObjToStr(answer) + '\n' else: wrongOutputTypeError(outputType['A2-part-5'][0],partIdx) return '' #sys.exit(1) return outputString.strip()