time_test.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import unittest
  2. import pygame
  3. Clock = pygame.time.Clock
  4. class ClockTypeTest(unittest.TestCase):
  5. def test_construction(self):
  6. """Ensure a Clock object can be created"""
  7. c = Clock()
  8. self.assertTrue(c, "Clock cannot be constructed")
  9. def todo_test_get_fps(self):
  10. # __doc__ (as of 2008-08-02) for pygame.time.Clock.get_fps:
  11. # Clock.get_fps(): return float
  12. # compute the clock framerate
  13. #
  14. # Compute your game's framerate (in frames per second). It is computed
  15. # by averaging the last few calls to Clock.tick().
  16. #
  17. self.fail()
  18. # delay_per_frame = 1 / 100.0
  19. #
  20. # c = Clock()
  21. #
  22. # for f in range(100):
  23. # c.tick()
  24. # time.sleep(delay_per_frame)
  25. #
  26. # self.assertTrue(99.0 < c.get_fps() < 101.0)
  27. def todo_test_get_rawtime(self):
  28. # __doc__ (as of 2008-08-02) for pygame.time.Clock.get_rawtime:
  29. # Clock.get_rawtime(): return milliseconds
  30. # actual time used in the previous tick
  31. #
  32. # Similar to Clock.get_time(), but this does not include any time used
  33. # while Clock.tick() was delaying to limit the framerate.
  34. #
  35. self.fail()
  36. def todo_test_get_time(self):
  37. # __doc__ (as of 2008-08-02) for pygame.time.Clock.get_time:
  38. # Clock.get_time(): return milliseconds
  39. # time used in the previous tick
  40. #
  41. # Returns the parameter passed to the last call to Clock.tick(). It is
  42. # the number of milliseconds passed between the previous two calls to
  43. # Pygame.tick().
  44. #
  45. self.fail()
  46. # c = Clock()
  47. # c.tick() #between here
  48. # time.sleep(0.02)
  49. # #get_time()
  50. # c.tick() # here
  51. #
  52. # time.sleep(0.02)
  53. #
  54. # self.assertTrue(20 <= c.get_time() <= 30)
  55. def todo_test_tick(self):
  56. # __doc__ (as of 2008-08-02) for pygame.time.Clock.tick:
  57. # Clock.tick(framerate=0): return milliseconds
  58. # control timer events
  59. # update the clock
  60. #
  61. # This method should be called once per frame. It will compute how
  62. # many milliseconds have passed since the previous call.
  63. #
  64. # If you pass the optional framerate argument the function will delay
  65. # to keep the game running slower than the given ticks per second.
  66. # This can be used to help limit the runtime speed of a game. By
  67. # calling Clock.tick(40) once per frame, the program will never run at
  68. # more than 40 frames per second.
  69. #
  70. # Note that this function uses SDL_Delay function which is not
  71. # accurate on every platform, but does not use much cpu. Use
  72. # tick_busy_loop if you want an accurate timer, and don't mind chewing
  73. # cpu.
  74. #
  75. self.fail()
  76. # collection = []
  77. # c = Clock()
  78. #
  79. # c.tick()
  80. # for i in range(100):
  81. # time.sleep(0.005)
  82. # collection.append(c.tick())
  83. #
  84. # for outlier in [min(collection), max(collection)]:
  85. # if outlier != 5: collection.remove(outlier)
  86. #
  87. # self.assertEqual(sum(collection) / len(collection), 5)
  88. def todo_test_tick_busy_loop(self):
  89. # __doc__ (as of 2008-08-02) for pygame.time.Clock.tick_busy_loop:
  90. # Clock.tick_busy_loop(framerate=0): return milliseconds
  91. # control timer events
  92. # update the clock
  93. #
  94. # This method should be called once per frame. It will compute how
  95. # many milliseconds have passed since the previous call.
  96. #
  97. # If you pass the optional framerate argument the function will delay
  98. # to keep the game running slower than the given ticks per second.
  99. # This can be used to help limit the runtime speed of a game. By
  100. # calling Clock.tick(40) once per frame, the program will never run at
  101. # more than 40 frames per second.
  102. #
  103. # Note that this function uses pygame.time.delay, which uses lots of
  104. # cpu in a busy loop to make sure that timing is more acurate.
  105. #
  106. # New in pygame 1.8.0.
  107. self.fail()
  108. class TimeModuleTest(unittest.TestCase):
  109. def todo_test_delay(self):
  110. # __doc__ (as of 2008-08-02) for pygame.time.delay:
  111. # pygame.time.delay(milliseconds): return time
  112. # pause the program for an amount of time
  113. #
  114. # Will pause for a given number of milliseconds. This function will
  115. # use the processor (rather than sleeping) in order to make the delay
  116. # more accurate than pygame.time.wait().
  117. #
  118. # This returns the actual number of milliseconds used.
  119. self.fail()
  120. def todo_test_get_ticks(self):
  121. # __doc__ (as of 2008-08-02) for pygame.time.get_ticks:
  122. # pygame.time.get_ticks(): return milliseconds
  123. # get the time in milliseconds
  124. #
  125. # Return the number of millisconds since pygame.init() was called.
  126. # Before pygame is initialized this will always be 0.
  127. #
  128. self.fail()
  129. def todo_test_set_timer(self):
  130. # __doc__ (as of 2008-08-02) for pygame.time.set_timer:
  131. # pygame.time.set_timer(eventid, milliseconds): return None
  132. # repeatedly create an event on the event queue
  133. #
  134. # Set an event type to appear on the event queue every given number of
  135. # milliseconds. The first event will not appear until the amount of
  136. # time has passed.
  137. #
  138. # Every event type can have a separate timer attached to it. It is
  139. # best to use the value between pygame.USEREVENT and pygame.NUMEVENTS.
  140. #
  141. # To disable the timer for an event, set the milliseconds argument to 0.
  142. self.fail()
  143. def todo_test_wait(self):
  144. # __doc__ (as of 2008-08-02) for pygame.time.wait:
  145. # pygame.time.wait(milliseconds): return time
  146. # pause the program for an amount of time
  147. #
  148. # Will pause for a given number of milliseconds. This function sleeps
  149. # the process to share the processor with other programs. A program
  150. # that waits for even a few milliseconds will consume very little
  151. # processor time. It is slightly less accurate than the
  152. # pygame.time.delay() function.
  153. #
  154. # This returns the actual number of milliseconds used.
  155. self.fail()
  156. ################################################################################
  157. if __name__ == '__main__':
  158. unittest.main()