def test_constant_time(self): stocks = range(10000000, 1, -1) start = time.time() self.assertTrue(main.best(stocks) == 0, "Best trade is no trade") end = time.time() self.assertTrue(start-end < 5, "Takes less than 5s (works in constant space and O(n) time")
async def work1(): url = "wss://sprs.herokuapp.com/first/" + SessionID async with websockets.connect(url) as websocket: await websocket.send("Let's start") response = await websocket.recv() print(f"\n>Request: Let's start \n<Response: {response}") temp = response.split(" ") bWidth = int(temp[0]) bHeight = int(temp[1]) numAmount = int(temp[2]) width = bWidth * hScale height = bHeight * vScale temp = str(hScale) + " " + str(vScale) + " " + str(level) + " " + str( length) + " on" await websocket.send(temp) response = await websocket.recv() print(f"\n>Request: {temp} \n<Response: collected") dictionary = m.list(m.parseEven(response, 0, 0), numAmount, width * height) for step in range(0, length): await websocket.send("Ready") response = await websocket.recv() print( f"\n>Request: Ready \n<Response: Task-{step + 1} \n{response}\n" ) x = m.parseEven(response, step) probs = [] if (level == 0): answer = m.find(x, dictionary) elif (level == 1): answer = m.find(m.invert(x), dictionary) else: for k in range(0, numAmount): a = m.best(x, dictionary[k], level) probs.append(a) answer = m.maxInd(probs) await websocket.send(f"{step + 1} {answer}") response = await websocket.recv() print( f"\n>Request: answer - {answer} \n<Response: correct - {response}" ) await websocket.send("Bye") response = await websocket.recv() print(f"\n>Request: Bye \n<Response: {response}") input("Press enter...")
def test_basic_case(self): stocks = [10, 7, 5, 8, 11, 9] self.assertTrue(main.best(stocks) == 6, "Best trade on example is 6")
def test_no_trade(self): stocks = [10, 9, 8, 7] self.assertTrue(main.best(stocks) == 0, "Best trade is no trade")
def test_longer_case(self): stocks = [10, 7, 11, 8, 5, 9] self.assertTrue(main.best(stocks) == 4, "Best trade on example is 4")