Skip to content

Commit 2f1ad95

Browse files
committed
Add tests for sympy_compat
1 parent 492e28b commit 2f1ad95

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

symengine/tests/test_sympy_compat.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
from symengine.sympy_compat import (Integer, Rational, S, Basic, Add, Mul,
2-
Pow, symbols, Symbol, log, sin, zeros, atan2)
2+
Pow, symbols, Symbol, log, sin, zeros, atan2, Number)
33

44
def test_Integer():
55
i = Integer(5)
66
assert isinstance(i, Integer)
77
assert isinstance(i, Rational)
8+
assert isinstance(i, Number)
89
assert isinstance(i, Basic)
910
assert i.p == 5
1011
assert i.q == 1
1112

1213
def test_Rational():
1314
i = S(1)/2
1415
assert isinstance(i, Rational)
16+
assert isinstance(i, Number)
1517
assert isinstance(i, Basic)
1618
assert i.p == 1
1719
assert i.q == 2
20+
x = symbols("x")
21+
assert not isinstance(x, Rational)
22+
assert not isinstance(x, Number)
1823

1924
def test_Add():
2025
x, y = symbols("x y")
@@ -67,3 +72,21 @@ def test_zeros():
6772
def test_has_functions_module():
6873
import symengine.sympy_compat as sp
6974
assert sp.functions.sin(0) == 0
75+
76+
def subclass_symbol():
77+
# Subclass of Symbol with an extra attribute
78+
class Wrapper(Symbol):
79+
def __new__(cls, name, extra_attribute):
80+
return Symbol.__new__(cls, name)
81+
82+
def __init__(self, name, extra_attribute):
83+
super(Wrapper, self).__init__(name)
84+
self.extra_attribute = extra_attribute
85+
86+
# Instantiate the subclass
87+
x = Wrapper("x", extra_attribute=3)
88+
assert x.extra_attribute == 3
89+
two_x = 2 * x
90+
# Check that after arithmetic, same subclass is returned
91+
assert two_x.args[1] is x
92+

0 commit comments

Comments
 (0)