Correctly translated sorting tests

The logic of the sorting tests wasn't ported fully or correctly. Now
these tests match the ones in the Java version.