Skip to content

Commit 3816233

Browse files
anutosh491certik
authored andcommitted
Added tests
1 parent 5ebde07 commit 3816233

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ RUN(NAME symbolics_02 LABELS cpython_sym c_sym)
605605
RUN(NAME symbolics_03 LABELS cpython_sym c_sym)
606606
RUN(NAME symbolics_04 LABELS cpython_sym c_sym)
607607
RUN(NAME symbolics_05 LABELS cpython_sym c_sym)
608+
RUN(NAME symbolics_06 LABELS cpython_sym c_sym)
608609

609610
RUN(NAME sizeof_01 LABELS llvm c
610611
EXTRAFILES sizeof_01b.c)

integration_tests/symbolics_06.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from sympy import Symbol, sin, cos, exp, log, Abs, pi, diff
2+
from lpython import S
3+
4+
def test_elementary_functions():
5+
6+
# test sin, cos
7+
x: S = Symbol('x')
8+
assert(sin(pi) == S(0))
9+
assert(sin(pi/S(2)) == S(1))
10+
assert(sin(S(2)*pi) == S(0))
11+
assert(cos(pi) == S(-1))
12+
assert(cos(pi/S(2)) == S(0))
13+
assert(cos(S(2)*pi) == S(1))
14+
assert(diff(sin(x), x) == cos(x))
15+
assert(diff(cos(x), x) == S(-1)*sin(x))
16+
17+
# test exp, log
18+
assert(exp(S(0)) == S(1))
19+
assert(log(S(1)) == S(0))
20+
assert(diff(exp(x), x) == exp(x))
21+
assert(diff(log(x), x) == S(1)/x)
22+
23+
# test Abs
24+
assert(Abs(S(-10)) == S(10))
25+
assert(Abs(S(10)) == S(10))
26+
assert(Abs(-x) == Abs(x))
27+
28+
# test composite functions
29+
a: S = exp(x)
30+
b: S = sin(a)
31+
c: S = cos(b)
32+
d: S = log(c)
33+
e: S = Abs(d)
34+
print(e)
35+
assert(e == Abs(log(cos(sin(exp(x))))))
36+
37+
test_elementary_functions()

0 commit comments

Comments
 (0)