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()
def test_computeSNR3(self): result = computeSNR('../../sounds/rain.wav', 'hanning', 1024, 2048, 128) self.assertAlmostEqual(74.631476225366825, result[0], delta=10) self.assertAlmostEqual(304.26918192997738,result[1], delta=100)
def test_computeSNR2(self): result = computeSNR('../../sounds/sax-phrase-short.wav', 'hamming', 513, 1024, 64) self.assertAlmostEqual(89.510506656299285, result[0], delta=10) self.assertAlmostEqual(306.18696700251388,result[1], delta=100)
def test_computeSNR1(self): result = computeSNR('../../sounds/piano.wav', 'blackman', 513, 2048, 128) self.assertAlmostEqual(67.57748352378475, result[0], delta=10) self.assertAlmostEqual(304.68394693221649,result[1], delta=100)