Writing unit tests and fixing bugs

This commit fixes an unreported offset-by-1 bug. This created a TAD border at an unexpected location in a perfect toy matrix. It is hard to predict what exactly the bug may have caused, I can just say that it might have caused any kind of sub-optimal segmentation.

In this toy example the weights behave as expected, the computation of the log-likelihood is accurate and valgrind finds no memory leak.