def main(): try: test.tests() except AssertionError: print('Problem with tests') sys.exit() instructions.instructions() file_instruction.file_instruction() flag = True while flag: work_with_users.cli_interface() k = input("\nWant to continue?\n(yes/no/help me): ") if k == 'yes': flag = True elif k == 'no': flag = False elif k == 'help me': instructions.instructions() flag = True
import re import reprlib from test import tests RE_WORD = re.compile('\w+') class Sentence: def __init__(self, text): self.text = text self.words = RE_WORD.findall(text) def __repr__(self): return 'Sentence(%s)' % reprlib.repr(self.text) def __iter__(self): for word in self.words: yield word return tests(Sentence)
def run_grader(student_func): grade_result = dict() try: result = test.tests(student_func) correct = result == 0 comment = "" if result == 0: comment = "" elif result == 1: comment = "There was an error running your solution. Please make sure there are no syntax errors, \nindentation errors, etc. and try again." elif result == 2: comment = "search is not defined" elif result == 3: comment = "search did not return anything" elif result % 100 == 4: if result == 4: comment = "search didn't return the expected output for:\ngrid = [" else: comment = "search raised an exception for:\ngrid = [" grid = [[0, 1, 1, 1, 1], [0, 1, 0, 0, 0], [0, 0, 0, 1, 0], [1, 1, 1, 1, 0], [0, 0, 0, 1, 0]] for i in range(len(grid)): comment += str(grid[i]) if i < len(grid) - 1: comment += ',\n ' else: comment += ']' elif result % 100 == 5: if result == 5: comment = "search didn't return the expected output for:\ngrid = [" else: comment = "search raised an exception for:\ngrid = [" grid = [[0, 1, 0, 0, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1, 1], [0, 0, 0, 1, 0, 0, 0]] for i in range(len(grid)): comment += str(grid[i]) if i < len(grid) - 1: comment += ',\n ' else: comment += ']' elif result % 100 == 6: if result == 6: comment = "search didn't return the expected output for:\ngrid = [" else: comment = "search raised an exception for:\ngrid = [" grid = [[0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0], [0, 0, 1, 0, 1, 0]] for i in range(len(grid)): comment += str(grid[i]) if i < len(grid) - 1: comment += ',\n ' else: comment += ']' grade_result['correct'] = correct if correct: grade_result['comment'] = "Correct! " + comment else: grade_result['comment'] = comment except: grade_result['correct'] = False grade_result[ 'comment'] = """There was an error running your solution. Make sure that search takes four arguments: grid, init, goal, cost. Also make sure that you are not using any global variables other than delta and delta_name.""" return grade_result.get('comment')
@staticmethod def split(z): sq_z = isqrt(z) if (sq_z * sq_z) > z: sq_z = sq_z - 1 t = z - sq_z * sq_z if t < sq_z: return (sq_z, t) else: return (t - sq_z, sq_z) @staticmethod def bounds(): return (0, 0, 0) @staticmethod def generate(): u, v, w = 0, 0, 0 while True: yield (u, v) if u == w and v < w: if v < w-1: v += 1 else: u, v = 0, w elif u < w and v == w: u += 1 elif u == w and v == w: u, v, w = (u+1, 0, w+1) else: assert False if __name__ == "__main__": tests(Elegant)
q = (z + 1) // p if q % 2 == 1: return (i, q // 2) @staticmethod def bounds(): return (0, 0, 0) @staticmethod def generate(): z = 0 while True: yield Poto.split(z) z += 1 if __name__ == "__main__": tests(Poto) """ # rest in piece: attempt to do a faster generate (possible?) # stolen from: # https://www.geeksforgeeks.org/check-n-divisible-power-2-without-using-arithmetic-operators/ # Python3 implementation to chech # whether n is divisible by pow(2, m) # function to chech whether n # is divisible by pow(2, m) def isDivBy2PowerM (n, m): # if expression results to 0, then
def trains(self, net): self.logs = logger.logger() # logs.refline(1,"2334",1) # logs.refline(4,"2334",5) # logs.refline(1,"2334",6) # logs.refline() readf = readfile.readfile() aimat = float(0.0) # test.tests(net, 0, float(aimat), readf, self.logs) net.train(mode=True) torch.set_num_threads(8) criterion = nn.CrossEntropyLoss( ) # use a Classification Cross-Entropy loss optimizer = optim.SGD([{ 'params': net.features.parameters(), 'lr': 0.00001 }, { 'params': net.lin.parameters(), 'lr': 0.001 }, { 'params': net.classifier.parameters(), 'lr': 0.0005 }], momentum=0.9) # scheduler = MultiStepLR(optimizer, milestones=[10, 80], gamma=0.1) tot = 0 for epoch in range(2000): # loop over the dataset multiple times # scheduler.step() running_loss = 0.0 net.train(mode=True) for i, data in enumerate(readf.dataloader, 0): tot += 1 # get the inputs inputs, labels = data # wrap them in Variable inputs, labels = Variable(inputs), Variable(labels) # zero the parameter gradients optimizer.zero_grad() # forward + backward + optimize outputs = net(inputs) loss = criterion(outputs, labels) loss.backward() optimizer.step() # print statistics running_loss += loss.data[0] if i % 25 == 24: # print every 2000 mini-batches print('[%d, %5d] loss: %.3f' % (epoch + 1, i + 1, running_loss / 25)) self.logs.defx = tot # print(self.logs.defx) self.logs.refline(running_loss / 25 * 100, "loss") running_loss = 0.0 aimat = float(aimat) aimat = test.tests(net, epoch, float(aimat), readf, self.logs) net.train(mode=True) torch.save(net, "./mod2/handalexnet34") print("saved") print('Finished Training')
engine.say(announcement + get_news()) engine.runAndWait() def announce_weather_and_news(announcement): """ This function says out loud the content of the alarm that is expected to say also the weather and the news. It also says out loud the weather and the news. """ logging.info("Alarm with news and weather has been said") try: engine.endLoop() except: logging.error('PyTTSx3 Endloop error') engine.say(announcement + get_weather() + get_news()) engine.runAndWait() if __name__ == '__main__': try: tests() except AssertionError as message: print(message) logging.info('System starting') app.run(debug=True)
class Cantor: @staticmethod def join(x, y): return tn(x + y) + y @staticmethod def split(z): t = tr(z) return ((t * (t + 3) // 2) - z, z - ((t * (t + 1)) // 2)) @staticmethod def bounds(): return (0, 0, 0) @staticmethod def generate(): u, v = 0, 0 while True: yield (u - v, v) if u == v: u += 1 v = 0 else: v += 1 if __name__ == "__main__": tests(Cantor)
#!/usr/bin/env python from unittest import TextTestRunner import test TextTestRunner().run(test.tests())
# half pairing (only x <= y pairs) class Half: @staticmethod def join(x, y): return tn(max(x, y)) + min(x, y) @staticmethod def split(z): return (ext(z), tr(z)) @staticmethod def bounds(): return (0, 0, 0) @staticmethod def generate(): u, v = 0, 0 while True: yield (u, v) if u == v: v += 1 u = 0 else: u += 1 if __name__ == "__main__": tests(Half)
def testunit(self): """测试tests""" pows = tests(8) self.assertEquals(pows, 64)
# encoding: utf-8 import argparse import test if __name__ == '__main__': argX = argparse.ArgumentParser() argX.add_argument('--noweb', action='store_true', default=False) args = argX.parse_args() tests = test.tests(args) tests.run()