Skip to content

Commit 124f014

Browse files
committed
Add test for a package
1 parent a49f18f commit 124f014

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

integration_tests/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ RUN(NAME test_str_comparison LABELS cpython llvm c)
409409
RUN(NAME test_bit_length LABELS cpython llvm c)
410410
RUN(NAME str_to_list_cast LABELS cpython llvm c)
411411

412+
RUN(NAME test_package_01 LABELS cpython llvm)
413+
412414
RUN(NAME generics_01 LABELS cpython llvm c)
413415
RUN(NAME generics_02 LABELS cpython llvm c)
414416
RUN(NAME generics_array_01 LABELS cpython llvm c)

integration_tests/nrp/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .nr import newton_raphson

integration_tests/nrp/nr.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from ltypes import f64, i32
2+
3+
4+
def func(x: f64, c: f64) -> f64:
5+
return x**2.0 - c**2.0
6+
7+
8+
def func_prime(x: f64, c: f64) -> f64:
9+
return 2.0*x
10+
11+
12+
def newton_raphson(x: f64, c: f64, maxiter: i32) -> f64:
13+
h: f64 = func(x, c) / func_prime(x, c)
14+
err: f64 = 1e-5
15+
i: i32 = 0
16+
while abs(func(x, c)) > err and i < maxiter:
17+
h = func(x, c) / func_prime(x, c)
18+
x = x - h
19+
i += 1
20+
return x

integration_tests/test_package_01.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from nrp import newton_raphson
2+
from ltypes import f64, i32
3+
4+
5+
def check():
6+
x0: f64 = 20.0
7+
c: f64 = 3.0
8+
maxiter: i32 = 20
9+
x: f64
10+
x = newton_raphson(x0, c, maxiter)
11+
assert abs(x - 3.0) < 1e-5
12+
13+
check()

0 commit comments

Comments
 (0)