This is a bit dangerous since log(det(M)) may fail.

Could you rather use a fixed matrix and assert the results as above? (Solve in Matlab or whatever)?

The random case should only be done for very small  matrices - so maybe change the above and do the large one fixed