Skip to content

Commit fe0e7bf

Browse files
committed
TEST: Add test for lpconvexhull pkg
1 parent f726048 commit fe0e7bf

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

integration_tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ RUN(NAME test_package_01 LABELS cpython llvm)
529529
RUN(NAME test_pkg_lpdraw LABELS cpython llvm wasm)
530530
RUN(NAME test_pkg_lnn_01 LABELS cpython llvm)
531531
RUN(NAME test_pkg_lnn_02 LABELS cpython llvm)
532+
RUN(NAME test_pkg_lpconvexhull LABELS cpython c)
532533

533534
RUN(NAME generics_01 LABELS cpython llvm c)
534535
RUN(NAME generics_02 LABELS cpython llvm c)
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from lpython import Const, i32, f64
2+
3+
from lpdraw import Line, Circle, Clear, Display
4+
from lpconvexhull import convex_hull
5+
from numpy import empty, int32
6+
7+
def plot_graph(polygon: list[tuple[i32, i32]], points: list[tuple[i32, i32]]):
8+
Width: Const[i32] = 500 # x-axis limits [0, 499]
9+
Height: Const[i32] = 500 # y-axis limits [0, 499]
10+
Screen: i32[Height, Width] = empty((Height, Width), dtype=int32)
11+
Clear(Height, Width, Screen)
12+
13+
i: i32
14+
n: i32 = len(polygon)
15+
for i in range(n):
16+
Line(Height, Width, Screen, polygon[i][0], polygon[i][1], polygon[(i + 1) % n][0], polygon[(i + 1) % n][1])
17+
18+
point_size: i32 = 5
19+
for i in range(len(points)):
20+
Circle(Height, Width, Screen, points[i][0], points[i][1], f64(point_size))
21+
22+
Display(Height, Width, Screen)
23+
24+
def main0():
25+
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)]
26+
convex_hull_points: list[tuple[i32, i32]] = convex_hull(points)
27+
# print(convex_hull_points)
28+
plot_graph(convex_hull_points, points)
29+
30+
assert convex_hull_points == [(29, 404), (138, 28), (494, 1), (435, 325), (338, 492), (62, 438)]
31+
32+
main0()

0 commit comments

Comments
 (0)