Status: Accepted
Owner: smichr
Labels: Type-Defect Priority-Medium
New issue 2037 by smichr: assert a == a is (almost) never a test of anything
http://code.google.com/p/sympy/issues/detail?id=2037
I've done it and I take some comfort in knowing that I'm not the only one
that has written a test like
assert log(x*y) == log(x*y)
The intention behind such an assertion is the hope that log(x*y) hasn't
become log(x)*log(y) without warrant. But, as Aaron reminded me the other
day, the above test will always be true. If the expansion happened then
both the left and right sides would be the same, e.g.
log(x)*log(y) == log(x)*log(y)
The test will always be true. The better way to have written such a test
would be to assert what you want *not* to be true or to focus on some other
way of asserting what you want, e.g.
assert log(x*y) != log(x)*log(y) # but the error log(x/y) would pass, too
assert str(log(x*y)) == 'log(x*y)' # a string 'snapshot'
assert log(x*y).args == (x*y,) # but sin(x*y) would pass, too
So while the initial test is probably important, it is actually not testing
anything and should be re-written.
There is a case where apparently identical expressions would be different:
Symbol('x', dummy=1) != Symbol('x', dummy=1)
And one would hope (and it is tested, as I recall) that
Symbol('x') == Symbol('x')
So one must exercise some caution when assuming that a test will or will
not always be true.
When we have a 'cleaning up sympy day' the attached file of such tests (89
in 23 files) could be regenerated or used as a starting point.
Attachments:
a==a test faults.txt 5.5 KB
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-iss...@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.