コード例 #1
0
    def onupdate(self, ev):
        if self._as_client:
            return
        elif not self._connected_session_ids:
            return

        now = time()
        if now - self._last_send_time < 0.5:
            return

        msg = _Msg()
        msg.val = "The message, construct time: {}".format(now)

        parts = self._build_parts()

        svc = ev.svc
        assert isinstance(svc, Service)
        if self._test_type == 'send':
            session_id = Random.choice(self._connected_session_ids)
            svc.send(session_id, msg, opcode=_OPCODE, parts=parts)
        elif self._test_type == 'multicast':
            svc.multicast(self._connected_session_ids, msg, opcode=_OPCODE, parts=parts)
        else:
            svc.broadcast(msg, opcode=_OPCODE, parts=parts)

        self._last_send_time = now
コード例 #2
0
    def onupdate(self, ev):
        if self._as_client:
            return
        elif not self._connected_session_ids:
            return

        now = time()
        if now - self._last_send_time < 0.5:
            return

        msg = _Msg()
        msg.val = "The message, construct time: {}".format(now)

        parts = self._build_parts()

        svc = ev.svc
        assert isinstance(svc, Service)
        if self._test_type == 'send':
            session_id = Random.choice(self._connected_session_ids)
            svc.send(session_id, msg, opcode=_OPCODE, parts=parts)
        elif self._test_type == 'multicast':
            svc.multicast(self._connected_session_ids,
                          msg,
                          opcode=_OPCODE,
                          parts=parts)
        else:
            svc.broadcast(msg, opcode=_OPCODE, parts=parts)

        self._last_send_time = now
コード例 #3
0
ファイル: testcase_random.py プロジェクト: lailongwei/llbc
    def run(self, *args, **kwargs):
        print "Random test:"
        print "Default rand():"

        all_output = ""
        for i in range(0, 100):
            if i != 0 and i % 10 == 0:
                all_output += "\n"
            all_output += "{0:13d} ".format(Random.rand())
        print all_output

        print "rand(100):", Random.rand(100)
        print "rand(100.0):", Random.rand(100.0)
        print "rand(None, 100):", Random.rand(None, 100)
        print "rand(None, 100.0):", Random.rand(None, 100.0)
        print "rand(100, 200):", Random.rand(100, 200)
        print "rand(100, 200.0):", Random.rand(100, 200.0)
        print "rand(200.0, 100):", Random.rand(200.0, 100)
        print "rand(100.0, 200.0):", Random.rand(100.0, 200.0)
        print "rand(None, None):", Random.rand(None, None)

        print "rand53real():", Random.rand53real()

        Random.seed(int(time()))
        print "after seed(), rand():", Random.rand()

        print "Press any key to continue ..."
        _ = raw_input()

        return 0
コード例 #4
0
ファイル: testcase_random.py プロジェクト: gustars/llbc
    def run(self, *args, **kwargs):
        print 'Random test:'
        print 'Default rand():'

        all_output = ''
        for i in range(0, 100):
            if i != 0 and i % 10 == 0:
                all_output += '\n'
            all_output += '{0:13d} '.format(Random.rand())
        print all_output

        print 'rand(100):', Random.rand(100)
        print 'rand(100.0):', Random.rand(100.0)
        print 'rand(None, 100):', Random.rand(None, 100)
        print 'rand(None, 100.0):', Random.rand(None, 100.0)
        print 'rand(100, 200):', Random.rand(100, 200)
        print 'rand(100, 200.0):', Random.rand(100, 200.0)
        print 'rand(200.0, 100):', Random.rand(200.0, 100)
        print 'rand(100.0, 200.0):', Random.rand(100.0, 200.0)
        print 'rand(None, None):', Random.rand(None, None)

        print 'rand53real():', Random.rand53real()

        Random.seed(int(time()))
        print 'after seed(), rand():', Random.rand()

        print 'Press any key to continue ...'
        _ = raw_input()

        return 0
コード例 #5
0
    def run(self, *args, **kwargs):
        print 'Random test:'
        print 'Default rand():'

        random = Random()
        all_output = ''
        for i in range(0, 100):
            if i != 0 and i % 10 == 0:
                all_output += '\n'
            all_output += '{0:2d} '.format(random.rand())
        print all_output

        print 'rand(100):', random.rand(100)
        print 'rand(None, 100):', random.rand(None, 100)
        print 'rand(None, 100.0):', random.rand(None, 100.0)
        print 'rand(100, 200):', random.rand(100, 200)
        print 'rand(100, 200.0):', random.rand(100, 200.0)
        print 'rand(200.0, 100):', random.rand(200.0, 100)
        print 'rand(100.0, 200.0):', random.rand(100.0, 200.0)
        print 'rand(None, None):', random.rand(None, None)

        print 'randreal():', random.randreal()

        random.seed(int(time()))
        print 'after seed(), rand():', random.rand()

        l = [1, 3, 5, 7, 9, 100, 300, 500, 700, 900, 999]
        print 'choice list: {}: {}'.format(l, random.choice(l))

        print 'Press any key to continue ...'
        _ = raw_input()

        return 0