booglybob / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Improve Test Case for clock #690

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
It was pointed out in this issue: 
https://code.google.com/p/pyglet/issues/detail?id=428

that the clock tests were giving some errors in some situations.

I took a look at the problem and improved the test case for better addressing 
the situation. The changes of the attached patch are:

1. substituted expressions of the form

self.assertTrue(abs(result - 5.0) < 0.05)

to

self.assertAlmostEqual(computed_fps, expected_fps, delta=0.05)

2. Joined the TestCase "TICK" and "FPS_LIMIT" with test case "FPS" since there 
were assertions that were being repeated (namely the one to check that a new 
clock starts with fps count to 0).

3. Added a setUp to the test case for creating a new clock on each test, since 
clock is a global variable.

4. Substituted absolute values of comparison (e.g. delta=0.05), to relative 
values (e.g. delta=0.1*expected_fps) like this:

self.assertAlmostEqual(computed_fps, expected_fps, delta=0.1*expected_fps)

5. Changed values of test for limiting FPS: it was limiting at 20, I set at 60 
since 60 is normally used (i.e. vsync).

6. The relative values were set to be
    - clock measures a time difference within 1% error.
    - clock measures a frame rate within 10% for unbounded frame rates.
    - clock measures a frame rate within 1% for a frame rate bounded to be 60 frames per second.

These values are kind of arbitrary since time differences are always system 
dependent. Nevertheless, 1% seems valid for the tests I performed, and 10% for 
unbounded frame rates. These values also seem fair for Pyglet's purposes.

7. Minor refactor of code: added docstring to the test case (with above 
information); added docstring to each test, added more explicit variables to 
each test. The code is now fully compliant with PEP8.

I'm not sure, but I think that because TICK and FPS_LIMIT cease to exist with 
this patch, tests/plan.txt has to be updated in case this patch is accepted.

Original issue reported on code.google.com by jorgecar...@gmail.com on 11 Dec 2013 at 10:05

Attachments:

GoogleCodeExporter commented 8 years ago
test/plan.txt needs to be updated.

See: http://pyglet.org/doc-current/api/tests.test.html

`pyglet/tests$ PYTHONPATH=.. python test.py clock`

result: pyglet.log:

INFO Beginning test at Wed Dec 11 13:52:28 2013
INFO Capabilities are: GENERIC, X11
INFO sys.platform = linux2
INFO pyglet.version = 1.2alpha1
INFO Reading test plan from plan.txt
INFO --- test (1/7) clock.TICK
ERROR Cannot load test for clock.TICK
Traceback (most recent call last):
  File "test.py", line 265, in test
    module = self.get_module(options.test_root)
  File "test.py", line 243, in get_module
    module = __import__(name)
ImportError: No module named TICK
INFO --- test (2/7) clock.FPS
INFO Begin unit tests for clock.FPS
INFO 5 tests run
INFO --- test (3/7) clock.FPS_LIMIT
ERROR Cannot load test for clock.FPS_LIMIT
Traceback (most recent call last):
  File "test.py", line 265, in test
    module = self.get_module(options.test_root)
  File "test.py", line 243, in get_module
    module = __import__(name)
ImportError: No module named FPS_LIMIT
INFO --- test (4/7) clock.SCHEDULE
INFO Begin unit tests for clock.SCHEDULE
INFO 3 tests run
INFO --- test (5/7) clock.SCHEDULE_INTERVAL
INFO Begin unit tests for clock.SCHEDULE_INTERVAL
INFO 1 tests run
INFO --- test (6/7) clock.SCHEDULE_ONCE
INFO Begin unit tests for clock.SCHEDULE_ONCE
INFO 1 tests run

I can do it for you if you want! pyglet testing suite is hard to get right at 
first, I recommend you run the tests you're changing *before* and after, so 
you're sure you're getting the right results.

Original comment by useboxnet on 11 Dec 2013 at 1:57

GoogleCodeExporter commented 8 years ago
I attached the patch for the plan.txt. I have run the test and it works 
flawless.

Original comment by jorgecar...@gmail.com on 11 Dec 2013 at 2:08

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks Jorge!

Original comment by useboxnet on 11 Dec 2013 at 2:11

GoogleCodeExporter commented 8 years ago

Original comment by useboxnet on 11 Dec 2013 at 2:12

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 72017516a83a.

Original comment by useboxnet on 11 Dec 2013 at 7:22