3 ms·
The test is right because it tests for the fact that lower case letters have a smaller representation as an ASCII character position. There is probably a ton of
by tharkun__ 5y ago
The test is right because it tests for the fact that lower case letters have a smaller representation as an ASCII character position. There is probably a ton of scripting and other software out there that assumes that this is how things are sorted. You also want a stable sort meaning sorting the same sequence twice you want it to be sorted the exact same way again. So you need this sort of definition of how things are supposed to be sorted.
So while I agree that without historical context and compatibility for human consumption your way of sorting is probably fine, you could wreak major havoc when trying your sort as a drop in replacement. If you only have a few users change management for something like this is relatively easy. The user base of coreutils? Think twice if you want to try that change management.
- tannhaeuser 5y ago> The test is right because it tests for the fact that lower case letters have a smaller representation as an ASCII character position. It's the other way around, though.
- tharkun__ 5y agoSee why having tests is great to define how a system is supposed to work? Much better than memory.
- tialaramex 5y agoIf the test is actually the specification then, sure I guess, but in most cases it isn't. Notice that the "failed" example exhibits stability which you claimed was desirable, while neither exhibits sorting by case, this is after all a case-insensitive sort, the "successful" example is just swapping some of the list items for whatever reason, maybe it was how their chosen algorithm worked, maybe it's a bug, they wrote the test so they get to fill out a "correct" answer that matches their behaviour. Now, striving to pass such tests gets you bug-for-bug compatibility which is what you want if you're an emulator, but the GNU project started out deliberately not doing bug-for-bug because it means people accuse you of copying, and so I don't see why this project should be different.