I am writing some tests for my sympy code, and naturally I need to compare two sympy matrices. Each matrix contains objects of type Poly
as its entries (actually, it contains objects of a class that I created which extends the Poly
class, but that shouldn't make a difference).
The problem is that when I try to compare these objects in the tests, the even though the expressions are the same, generators are different, yielding a failing test even though they are the same.
For example:
from sympy.matrices import Matrix
expected_matrix = Matrix([[Poly(1.0*y1 + 2.0*x2 + 1.0*x1, y1, x2, x1, domain='RR')]])
actual_matrix = Matrix([[Poly(1.0*y1 + 1.0*x2, y2, y1, x2, x1, domain='RR') + Poly(1.0*x2 + 1.0*x1, y2, y1, x2, x1, domain='RR')]])
# however, when these get compared, they don't agree because notice that the `y2` generator does not appear in the `expected_matrix`.
My question is how to make the generators equal. How do I add generators to the actual output? Or, take the generators away from the expected output?
Since the gens
attribute is a tuple, it makes this difficult, because I cannot just add an element to the gens
attribute:
actual_matrix.gens = expected_matrix.gens
Perhaps I could compare the expressions alone, but that seems risky to me (unless someone with more experience with this can convince me otherwise).
How do I compare these two things?