Added tests for invalid dm construction.
Added tests for view-casting (and sanity checks).

There's some duplicate sanity-checking code- this needs to be refactored.