Skip to content

Commit

Permalink
Add test for a package
Browse files Browse the repository at this point in the history
  • Loading branch information
Smit-create committed Mar 23, 2023
1 parent a49f18f commit 124f014
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ RUN(NAME test_str_comparison LABELS cpython llvm c)
RUN(NAME test_bit_length LABELS cpython llvm c)
RUN(NAME str_to_list_cast LABELS cpython llvm c)

RUN(NAME test_package_01 LABELS cpython llvm)

RUN(NAME generics_01 LABELS cpython llvm c)
RUN(NAME generics_02 LABELS cpython llvm c)
RUN(NAME generics_array_01 LABELS cpython llvm c)
Expand Down
1 change: 1 addition & 0 deletions integration_tests/nrp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .nr import newton_raphson
20 changes: 20 additions & 0 deletions integration_tests/nrp/nr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ltypes import f64, i32


def func(x: f64, c: f64) -> f64:
return x**2.0 - c**2.0


def func_prime(x: f64, c: f64) -> f64:
return 2.0*x


def newton_raphson(x: f64, c: f64, maxiter: i32) -> f64:
h: f64 = func(x, c) / func_prime(x, c)
err: f64 = 1e-5
i: i32 = 0
while abs(func(x, c)) > err and i < maxiter:
h = func(x, c) / func_prime(x, c)
x = x - h
i += 1
return x
13 changes: 13 additions & 0 deletions integration_tests/test_package_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from nrp import newton_raphson
from ltypes import f64, i32


def check():
x0: f64 = 20.0
c: f64 = 3.0
maxiter: i32 = 20
x: f64
x = newton_raphson(x0, c, maxiter)
assert abs(x - 3.0) < 1e-5

check()

0 comments on commit 124f014

Please sign in to comment.