class systemTestCase(unittest.TestCase): def test_includes(self): "d. check the included modules are allowed" f = open(progname) file_contents = f.read() f.close() imports = ec602lib.get_python_imports(file_contents) invalid_imports = imports - valid_imports if invalid_imports: self.fail('Invalid imports: {}'.format(" ".join( x for x in invalid_imports))) def test_same_system(self): "a. h and x same size" for (x, h, y) in Output_Same_Tests: check_output(self, x, h, y) def test_diff_system(self): "b. h and x different size" for (x, h, y) in Output_Diff_Tests: check_output(self, x, h, y) if __name__ == "__main__": print('Polynomials/Sequences System Checker Version {0}.{1}'.format( *VERSION)) _, results, _ = ec602lib.overallpy(progname, systemTestCase, refcode) # unittest.main() print(results)
self.assertLess(match_signals(filtered, m), 0.1, msg="filtered signal incorrect") def test_bach(self): "e. what is the loudest 75 Hz of Bach 10 seconds?" start = time.time() low, high, filtered = loudest_band(music, frame_rate, 75) duration = time.time() - start testing_time['bach'] = duration self.assertEqual(music.shape, filtered.shape) self.assertAlmostEqual(low / 823.5, 1.0, 2) self.assertAlmostEqual(high / 898.3, 1.0, 2) if __name__ == '__main__': from loudest import loudest_band _, results, _ = ec602lib.overallpy(progname, loudestTestCase, refcode) print(results) print() print('processing bach10sec took {:.2f} seconds'.format( testing_time['bach'])) if testing_time['bach'] > 1.0: print( "WARNING: my analysis of bach10sec takes 0.13 s, yours took {:.3f} s" .format(testing_time['bach'])) print( 'the actual checker will fail you on this test. Passing this is extra credit.' ) #unittest.main() # alternative testing suite from unittest
if error: self.fail( 'Reading from the created wav file failed. Exception: {}' .format(error)) # test rate if st_frame_rate != frame_rate: self.fail('Frame rate mismatch: {} vs {}'.format( st_frame_rate, frame_rate)) # test shape N = int(len(dig) * time_of_tone * frame_rate) if (N, ) != st_signal.shape: self.fail('Shape mismatch: {} vs {}'.format( (N, ), st_signal.shape)) # test digit creation result_digits = extract_digits(st_signal, st_frame_rate) if result_digits != dig: self.fail('Detect tones mismatch: {} vs {}'.format( result_digits, dig)) if __name__ == '__main__': from dialer import dialer _, results, _ = ec602lib.overallpy(progname, DialerTestCase, refcode) #unittest.main() print(results) unittest.main()
h = list(range(3, 2000, 2)) tot = Polynomial(g) + Polynomial(h) st = time.time() self.assertEqual(tot, Polynomial(LongAdd)) add_time = time.time() - st if add_time > 0.002: self.fail("Your add is not efficient") def test_nomods(self): "w. input sequence independent of created polynomial" L = [3, 2, 1] p = Polynomial(L) L.clear() self.assertEqual(p, Polynomial([3, 2, 1]), msg="you must not link to the sequence") L = [2, 1] p = Polynomial(L) p[1] = 3 self.assertEqual(L, [2, 1], msg="you must not modify the passed sequence") if __name__ == "__main__": from modeling import Polynomial _, results, _ = ec602lib.overallpy(progname, PolynomialTestCase, refcode) # unittest.main() print(results)