コード例 #1
0
ファイル: FPS.py プロジェクト: DatRollingStone/nwidget
 def test_fps(self):
     clock.set_default(clock.Clock())
     self.assertTrue(clock.get_fps() == 0)
     for i in range(10):
         time.sleep(0.2)
         clock.tick()
     result = clock.get_fps()
     self.assertTrue(abs(result - 5.0) < 0.05)
コード例 #2
0
ファイル: FPS.py プロジェクト: njoubert/UndergraduateProjects
 def test_fps(self):
     clock.set_default(clock.Clock())
     self.assertTrue(clock.get_fps() == 0)
     for i in range(10):
         time.sleep(0.2)
         clock.tick()
     result = clock.get_fps()
     self.assertTrue(abs(result - 5.0) < 0.05)
コード例 #3
0
ファイル: TICK.py プロジェクト: DatRollingStone/nwidget
 def test_tick(self):
     clock.set_default(clock.Clock())
     result = clock.tick()
     self.assertTrue(result == 0)
     time.sleep(1)
     result_1 = clock.tick()
     time.sleep(1)
     result_2 = clock.tick()
     self.assertTrue(abs(result_1 - 1.0) < 0.05)
     self.assertTrue(abs(result_2 - 1.0) < 0.05)
コード例 #4
0
 def test_tick(self):
     clock.set_default(clock.Clock())
     result = clock.tick()
     self.assertTrue(result == 0)
     time.sleep(1)
     result_1 = clock.tick()
     time.sleep(1)
     result_2 = clock.tick()
     self.assertTrue(abs(result_1 - 1.0) < 0.05)
     self.assertTrue(abs(result_2 - 1.0) < 0.05)
コード例 #5
0
    def test_schedule_multiple(self):
        clock.set_default(clock.Clock())
        clock.schedule(self.callback)
        clock.schedule(self.callback)
        self.callback_count = 0

        clock.tick()
        self.assertTrue(self.callback_count == 2)

        clock.tick()
        self.assertTrue(self.callback_count == 4)
コード例 #6
0
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick()  # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
コード例 #7
0
ファイル: FPS_LIMIT.py プロジェクト: DatRollingStone/nwidget
    def test_fps_limit(self):
        clock.set_default(clock.Clock())
        clock.set_fps_limit(20)
        self.assertTrue(clock.get_fps() == 0)

        t1 = time.time()
        clock.tick() # One to get it going
        for i in range(20):
            clock.tick()
        t2 = time.time()
        self.assertTrue(abs((t2 - t1) - 1.) < 0.05)
コード例 #8
0
    def test_unschedule(self):
        clock.set_default(clock.Clock())
        clock.schedule(self.callback)

        result = clock.tick()
        self.assertTrue(result == self.callback_dt)
        self.callback_dt = None
        time.sleep(1)
        clock.unschedule(self.callback)

        result = clock.tick()
        self.assertTrue(self.callback_dt == None)
コード例 #9
0
    def test_schedule_once(self):
        self.clear()
        clock.set_default(clock.Clock())
        clock.schedule_once(self.callback_1, 0.1)
        clock.schedule_once(self.callback_2, 0.35)
        clock.schedule_once(self.callback_3, 0.07)

        t = 0
        while t < 1:
            t += clock.tick()
        self.assertTrue(self.callback_1_count == 1)
        self.assertTrue(self.callback_2_count == 1)
        self.assertTrue(self.callback_3_count == 1)
コード例 #10
0
    def test_schedule_interval(self):
        self.clear()
        clock.set_default(clock.Clock())
        clock.schedule_interval(self.callback_1, 0.1) 
        clock.schedule_interval(self.callback_2, 0.35)
        clock.schedule_interval(self.callback_3, 0.07)

        t = 0
        while t < 2.04:   # number chosen to avoid +/- 1 errors in div
            t += clock.tick()
        self.assertTrue(self.callback_1_count == int(t / 0.1))
        self.assertTrue(self.callback_2_count == int(t / 0.35))
        self.assertTrue(self.callback_3_count == int(t / 0.07))
コード例 #11
0
    def test_schedule_interval(self):
        self.clear()
        clock.set_default(clock.Clock())
        clock.schedule_interval(self.callback_1, 0.1)
        clock.schedule_interval(self.callback_2, 0.35)
        clock.schedule_interval(self.callback_3, 0.07)

        t = 0
        while t < 2.04:  # number chosen to avoid +/- 1 errors in div
            t += clock.tick()
        self.assertTrue(self.callback_1_count == int(t / 0.1))
        self.assertTrue(self.callback_2_count == int(t / 0.35))
        self.assertTrue(self.callback_3_count == int(t / 0.07))
コード例 #12
0
    def test_schedule_once(self):
        self.clear()
        clock.set_default(clock.Clock())
        clock.schedule_once(self.callback_1, 0.1) 
        clock.schedule_once(self.callback_2, 0.35)
        clock.schedule_once(self.callback_3, 0.07)

        t = 0
        while t < 1:
            t += clock.tick()
        self.assertTrue(self.callback_1_count == 1)
        self.assertTrue(self.callback_2_count == 1)
        self.assertTrue(self.callback_3_count == 1)
コード例 #13
0
ファイル: test_clock_fps.py プロジェクト: SwineEngine/pyglet
 def setUp(self):
     # since clock is global,
     # we initialize a new clock on every test
     clock.set_default(clock.Clock())
コード例 #14
0
from pyglet import clock

from ..annotations import skip_if_continuous_integration


def sleep(seconds):
    """Busy sleep on the CPU which is very precise"""
    pyclock = clock.get_default()
    start = pyclock.time()
    while pyclock.time() - start < seconds:
        pass


# since clock is global, we initialize a new clock on every test
clock.set_default(clock.Clock())


def test_first_tick_is_delta_zero():
    """
    Tests that the first tick is dt = 0.
    """
    dt = clock.tick()
    assert dt == 0


def test_start_at_zero_fps():
    """
    Tests that the default clock starts
    with zero fps.
    """
コード例 #15
0
ファイル: FPS.py プロジェクト: DiscoBizzle/Ghost-Simulator
 def setUp(self):
     # since clock is global,
     # we initialize a new clock on every test
     clock.set_default(clock.Clock())
コード例 #16
0
ファイル: test_clock_fps.py プロジェクト: einarf/pyglet
def newclock():
    clock.set_default(clock.Clock())
    yield clock