Fix: add special case to add typing
Some checks failed
continuous-integration/drone/push Build is failing

Sometimes, typing/add.py tried to build MOpolynomial with only one
coefficient.
This commit is contained in:
2021-10-20 15:31:14 +02:00
parent d6e3f774fa
commit 60ee751e91
3 changed files with 72 additions and 4 deletions

View File

@@ -132,7 +132,7 @@ class MOstrPower(Molecule):
class MOMonomial(Molecule):
""" Monomial math object"""
""" Monomial math object : ax^n"""
MAINOP = "*"

View File

@@ -18,7 +18,7 @@ __all__ = ["MOpolynomial"]
class MOpolynomial(Molecule):
""" MO polynomial"""
""" MO polynomial: ax^n + ... + z (can't be a monomial)"""
MAINOP = "+"
@@ -39,6 +39,14 @@ class MOpolynomial(Molecule):
<MOpolynomial 4x^3 + 1>
>>> MOpolynomial('x', {0: 1, 3: 1})
<MOpolynomial x^3 + 1>
>>> MOpolynomial('x', [0, 0, 3])
Traceback (most recent call last):
...
TypeError: A MOpolynomial can't be monomial it has to have more than one coefficient.
>>> MOpolynomial('x', {3: 1})
Traceback (most recent call last):
...
TypeError: A MOpolynomial can't be monomial it has to have more than one coefficient.
"""
_variable = MO.factory(variable)
@@ -58,6 +66,9 @@ class MOpolynomial(Molecule):
raise TypeError("Coefs needs to be a dictionnary or a list")
self._coefs = _coefs
if len(self._coefs) == 1:
raise TypeError("A MOpolynomial can't be monomial it has to have more than one coefficient.")
monomials = OrderedDict()
for deg in sorted(self._coefs.keys()):
coef = self._coefs[deg]