More bug fixes for autosort. Also added more robust unittests using
random.shuffle.