Skip to content

Commit

Permalink
Created functional test (test_polygon_large_coords in draw_test.py)
Browse files Browse the repository at this point in the history
  • Loading branch information
u7156704 committed Oct 17, 2023
1 parent 2dd3691 commit 4e063c1
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions test/draw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3691,7 +3691,7 @@ class to add any draw.aalines specific tests to.
[0, 2],
[2, 2],
)


class DrawPolygonMixin:
"""Mixin tests for drawing polygons.
Expand Down Expand Up @@ -4279,25 +4279,44 @@ def test_polygon__surface_clip(self):

surface.unlock()
def test_polygon_large_coords(self):
""" Test polygon creation with larger coordinates.
Ensures it works with solid shapes and non-solid shapes
""" Ensures draw polygon works correctly with large points
Testing the drawings of filled polygons
"""
pointA = (600, 50)
pointB = (50, 600)
pointC = (58000,-100000) # problem line (extreme coords)
extreme_points = (58000,100000)
extreme_negative_points = (-58000,-100000)
extreme_negative_x = (-58000,100000)
extreme_negative_y = (58000,-100000)

surfw = surfh = 650
surface = pygame.Surface((surfw, surfh))

green = (0, 255, 0)
red = (255,0,0)
thickness = 2
white = (0, 0, 0, 255)

# Checks the surface point to ensure the polygon has been drawn correctly

# Extreme points case
self.draw_polygon(surface, green, (pointA,pointB,extreme_points))
self.assertEqual(surface.get_at((640,50)), white)
self.assertEqual(surface.get_at((50,640)), white)

# Extreme negative points case
self.draw_polygon(surface, green, (pointA,pointB,extreme_negative_points))
self.assertEqual(surface.get_at((600,25)), white)
self.assertEqual(surface.get_at((0,0)), green)

self.draw_polygon(surface, green, (pointA,pointB,pointC))
self.assertEqual(surface.get_at(pointA), green)
self.assertEqual(surface.get_at(pointB), green)
# Extreme negative x case
self.draw_polygon(surface, green, (pointA,pointB,extreme_negative_x))
self.assertEqual(surface.get_at((600,600)), white)
self.assertEqual(surface.get_at((300,640)), green)

self.draw_polygon(surface, red, (pointA,pointB,pointC),thickness)
self.assertEqual(surface.get_at(pointA), red)
self.assertEqual(surface.get_at(pointB), red)
# Extreme negative y case
self.draw_polygon(surface, green, (pointA,pointB,extreme_negative_y))
self.assertEqual(surface.get_at((600,600)), white)
self.assertEqual(surface.get_at((300,300)), green)



Expand Down

0 comments on commit 4e063c1

Please sign in to comment.