3 ms·
I agree that testing getters/setters...is a waste of time, but... But it isn't necessarily. Say I have multiple implementations of a class, e.g.: trait Ti
by yummyfajitas 13y ago
I agree that testing getters/setters...is a waste of time, but...
But it isn't necessarily. Say I have multiple implementations of a class, e.g.:
trait TimeSeries {
def datapoints: Seq[DataPoint]
}
case class SequenceTimeSeries(datapoints: Seq[DataPoint]) extends TimeSeries
class ArrayTimeSeries(times: Array[Long], values: Array[Double]) extends TimeSeries
It's pretty straightforward and nearly pointless to test that `sequenceTimeSeries.datapoints` does what I expect. On the other hand, applying the same test to `arrayTimeSeries.datapoints` exposed an off by one error in my implementation.
- tel 13y agoOut of curiosity—I'm not so familiar with Scala—how does an off-by-1 arise here? Aren't you just going to zip (times, values)?
- yummyfajitas 13y agoI did this a while back, so I don't recall the exact off-by-one error. But I don't want to to times.zip(values) - that would involve constructing explicitly a List[DataPoint] which is precisely what I'm trying to avoid with the ArrayTimeSeries. Rather, I defined a custom Seq[DataPoint], which had the apply(i: Int) method construct datapoints on the fly from the arrays. (I admit that the error was entirely stupidity on my part and not the result of anything complicated. If I was as smart as Rich Hickey, I probably wouldn't need so many tests.)
- tel 13y agoOhh, I see, array-of-structures/structure-of-arrays trouble.
- puredanger 13y agoSo test that one. Please, I encourage you to engage your brain in the process of choosing what does and does not need to be tested. That is the whole point.