Add complete unit tests for matrix module