|
1 | 1 | 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) |
3 | 3 |
|
4 | 4 | def test_Integer():
|
5 | 5 | i = Integer(5)
|
6 | 6 | assert isinstance(i, Integer)
|
7 | 7 | assert isinstance(i, Rational)
|
| 8 | + assert isinstance(i, Number) |
8 | 9 | assert isinstance(i, Basic)
|
9 | 10 | assert i.p == 5
|
10 | 11 | assert i.q == 1
|
11 | 12 |
|
12 | 13 | def test_Rational():
|
13 | 14 | i = S(1)/2
|
14 | 15 | assert isinstance(i, Rational)
|
| 16 | + assert isinstance(i, Number) |
15 | 17 | assert isinstance(i, Basic)
|
16 | 18 | assert i.p == 1
|
17 | 19 | assert i.q == 2
|
| 20 | + x = symbols("x") |
| 21 | + assert not isinstance(x, Rational) |
| 22 | + assert not isinstance(x, Number) |
18 | 23 |
|
19 | 24 | def test_Add():
|
20 | 25 | x, y = symbols("x y")
|
@@ -67,3 +72,21 @@ def test_zeros():
|
67 | 72 | def test_has_functions_module():
|
68 | 73 | import symengine.sympy_compat as sp
|
69 | 74 | 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