Skip to content

Commit

Permalink
TEST: Add test for lpconvexhull pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed May 23, 2023
1 parent f726048 commit fe0e7bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ RUN(NAME test_package_01 LABELS cpython llvm)
RUN(NAME test_pkg_lpdraw LABELS cpython llvm wasm)
RUN(NAME test_pkg_lnn_01 LABELS cpython llvm)
RUN(NAME test_pkg_lnn_02 LABELS cpython llvm)
RUN(NAME test_pkg_lpconvexhull LABELS cpython c)

RUN(NAME generics_01 LABELS cpython llvm c)
RUN(NAME generics_02 LABELS cpython llvm c)
Expand Down
32 changes: 32 additions & 0 deletions integration_tests/test_pkg_lpconvexhull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from lpython import Const, i32, f64

from lpdraw import Line, Circle, Clear, Display
from lpconvexhull import convex_hull
from numpy import empty, int32

def plot_graph(polygon: list[tuple[i32, i32]], points: list[tuple[i32, i32]]):
Width: Const[i32] = 500 # x-axis limits [0, 499]
Height: Const[i32] = 500 # y-axis limits [0, 499]
Screen: i32[Height, Width] = empty((Height, Width), dtype=int32)
Clear(Height, Width, Screen)

i: i32
n: i32 = len(polygon)
for i in range(n):
Line(Height, Width, Screen, polygon[i][0], polygon[i][1], polygon[(i + 1) % n][0], polygon[(i + 1) % n][1])

point_size: i32 = 5
for i in range(len(points)):
Circle(Height, Width, Screen, points[i][0], points[i][1], f64(point_size))

Display(Height, Width, Screen)

def main0():
points: list[tuple[i32, i32]] = [(445, 193), (138, 28), (418, 279), (62, 438), (168, 345), (435, 325), (293, 440), (158, 94), (403, 288), (136, 278), (141, 243), (287, 313), (338, 492), (172, 78), (29, 404), (79, 377), (184, 91), (69, 324), (408, 72), (494, 1)]
convex_hull_points: list[tuple[i32, i32]] = convex_hull(points)
# print(convex_hull_points)
plot_graph(convex_hull_points, points)

assert convex_hull_points == [(29, 404), (138, 28), (494, 1), (435, 325), (338, 492), (62, 438)]

main0()

0 comments on commit fe0e7bf

Please sign in to comment.