partition_copy algorithm and tests