New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update unit tests draw.ellipse, add unit tests draw.(aa)line(s) #510
Conversation
The unit test now includes a test that checks if at least two sides of an ellipse, that has a width and height that is 1 pixel smaller than the surface, is touching the surface's border. It also cleans up the code slightly, including a better way of retrieving the border's values and adds reusability. See: #233
Adds unit tests for draw.aaline, draw.line, draw.aalines and draw.lines. For draw.aaline and draw.line it now draws a line of differing colours on all types of surfaces and checks if the colour stays the same at position (0, 0). The same is done for draw.aalines and draw.lines, except they draw a line around the border of the given surface and check if all pixels are of the given colour. See: #395
test/draw_test.py
Outdated
from pygame.tests import test_utils | ||
#################################### IMPORTS ################################### | ||
|
||
if __name__ == '__main__': |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Personnally, I have some issues about line_is_color ,line_has_gaps and lines_have_gaps :
So , for me, these helper functions contain a bit too much logic / factorisation ? |
test/draw_test.py
Outdated
# if true, a line will be draw between the first and last points. The | ||
# boolean blend argument set to true will blend the shades with | ||
# existing shades instead of overwriting them. This function accepts | ||
# floating point values for the end points. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@e1000 some good suggestions. Thank you.
These two changes would reduce the amount of repeated code (DRY) https://en.wikipedia.org/wiki/Don%27t_repeat_yourself And I think it would bring related test code closer together in the file, making it easier to understand.
|
On Travis CI tests I see this error come up:
So maybe we need to specify the bit depth for when the tests run like this. This error is raised when the depth is 8, but it works for depth 16, and depth 32. >>> pygame.Surface((10,10), pygame.SRCALPHA, 8)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: no standard masks exist for given bitdepth with alpha |
Merges some of the unit tests into one unit test and moves some of the functions closer to the relevant tests for better readability. Also improves the way the surfaces are created for testing as it now includes the depth. See: #512
test/draw_test.py
Outdated
|
||
draw_line(surface, color, (0, 0), (width - 1, 0)) | ||
|
||
colors = [surface.get_at((width, 0)) for width in range(width)] |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/draw_test.py
Outdated
draw_lines(surface, color, True, points) | ||
|
||
borders = get_border_values(surface, width, height) | ||
return [color in border for border in borders] |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/draw_test.py
Outdated
draw_lines(surface, color, True, points) | ||
|
||
borders = get_border_values(surface, width, height) | ||
return [len(border) == border.count(color) for border in borders] |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Wonderful! 🎈 🎉 |
This pull request contains the following:
Ellipse
I updated the draw.ellipse unit test so that it now also includes a test that checks if at least two sides of an ellipse, that has a width and height that is 1 pixel smaller than the surface, is touching the surface's border.
It also cleans up the code slightly, including a better way of retrieving the border's values and adds reusability in the form of additional functions.
See: #233
Lines
It also adds unit tests for draw.aaline, draw.line, draw.aalines and draw.lines.
For draw.aaline and draw.line it now draws a line of differing colours on all types of surfaces and checks if the colour stays the same at position (0, 0). There is also a test that checks if the line contains any gaps, as I noticed aaline(s) sometimes does (or is not drawn at all when close to a surface's border).
The same is done for draw.aalines and draw.lines, except these tests draw a line around the border of the given surface then check if all pixels are of the given colour, or if they contain gaps.
See: #395