Closed SamoylovMD closed 9 years ago
So, I understood the situation: mock classes were needed to avoid precision errors. Maybe we could rewrite equals
code in AbstractVector
to pass all tests without mocks? Current implementation is:
for (int i = 0; result && i < length; i++) {
double a = get(i);
double b = vector.get(i);
double diff = Math.abs(a - b);
result = (a == b) || (diff < Vectors.EPS || diff / Math.max(Math.abs(a), Math.abs(b)) < Vectors.EPS);
}
Bad idea: algorithms lower precision extremely. Maybe we could set custom precision when we compare vectors?
Well, everything depends on Vectors.EPS
constant. I agree, this is a good idea to pass it to a equals
method. We may have an additional method int the interface that takes eps
param. So, we can delegate the equals(Vector other)
to equals(other, Vectors.EPS)
.
Yes, but there's another problem: assertEquals(Object o1, Object o2)
calls equals(Object o)
method only, always and everywhere, so even if we write new equals(Object o, double precision)
, this won't help us.
Yeah. Why can't we just use MockMatrix
and MockVector
?
Another question: why can't we use special mock tools, i.e. mockito? We just need to change one method, sounds like work for mockito.
Hm. That's sounds like a good idea. Can you try to plug it into la4j?
Mockito and other mock tools don't allow to stub equals()
method, so I implemented equals(object, precision)
and moved tests from MockVector
and MockMatrix
engine to new equals
method, now it works. Also I marked MockVector
and MockMatrix
as deprecated.
So, new equals
requires some additional testing, but I think we can close this issue.
We can just remove them.
Why don't we have
equals()
methods inVector
andMatrix
interface?Related: I see only one reason why we need
MockVector
andMockMatrix
test classes -equals()
method. So, I think that'll be good idea to moveequals
from mocks toAbstractVector
andAbstractMatrix
.