def testPopFront(): q = Queue() testData = getRandom(1000) for item in testData: q.pushBack(item) for i in range(len(testData)): assert q.popFront() == testData[i]
def testEmpty(): q = Queue() testData = getRandom(10) for item in testData: q.pushBack(item) q.empty() assert q.size() == 0
def testFront(): q = Queue() testData = getRandom(1000) assert q.front() == None for item in testData: q.pushBack(item) assert q.front() == testData[0]
def open(self): id = getRandom() self.player = Player(id, self) players[id] = self.player sockets[self] = id print 'connection opened with id =', id self.write_message(msg.init(id))
def testEQ(): q1, q2 = Queue(), Queue() testData = getRandom(1000) for item in testData: q1.pushBack(item) assert q1 != q2 q2.pushBack(item) assert q1 == q1 q1.empty() assert q1 != q2
def open(self): id = getRandom() player = Player(id, self) players[id] = player sockets[self] = id print 'connection opened with id =', id self.write_message(msg.init(id)) if len(free_players) != 0: print 'match waiting player' another_player = free_players.pop() Game(player, another_player).start() else: print 'wait for another player' free_players.append(player)
def setKey(self, id: int, beginDate: datetime.date, endDate: datetime.date, checkin: datetime.time, checkout: datetime.time, name: str = "pin", debug: bool = False, pin: str = None) -> Tuple[str, bool]: """Sets a key for a lock with the specified id and writes the pin down to the sql database\n The pin is returned for further use and a bool if the pin was succesfully set""" if pin is None: pin = utils.getRandom(1, 9) if pin.startswith("12"): pin.replace("12", utils.getRandom(1, 9, 2), 1) header = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': self.api_key } start = datetime.datetime(beginDate.year, beginDate.month, beginDate.day, checkin.hour, checkin.minute, checkin.second) end = datetime.datetime(endDate.year, endDate.month, endDate.day, checkout.hour, checkout.minute, checkout.second) data = { "name": name, "type": 13, "code": int(pin), "allowedFromDate": utils.buildDateString(start), "allowedUntilDate": utils.buildDateString(end), "allowedWeekDays": 127, } if debug: print("header:", header) if debug: print("data:", data) back = None url = self.api_url + "smartlock/" + str(id) + "/auth" if not debug: back = requests.put(url, headers=header, data=json.dumps(data)) if back.ok: succesfull = True else: print("Set key on " + str(id) + " didn't succeded additional infos:") print("Reason: " + str(back.reason)) print("Status Code: " + str(back.status_code)) succesfull = False else: succesfull = True return pin, succesfull
def testSize(): q = Queue() testData = getRandom(100) for i in range(len(testData)): assert q.size() == i q.pushBack(testData[i])