Initial test rearrangement. Pushing engine-independent logic to math-scala. Some renames.