Conversation
60adef8 to
42f14e5
Compare
|
Note that this is a duplicate of #55 so whichever of those two will be validated and finished first will invalidate the other one. PS: If you wish, it could be a nice courtesy to also credit the original author of #55 in your CHANGELOG entry too if you used #55 as inspiration and this #56 is just a continuation of their work to finish the work 😉 |
42f14e5 to
aafe853
Compare
|
You're totally right @AliSoftware ! Updated the CHANGELOG. I didn't wanna build on top of #55 since this is a slightly different approach. #55 modifies I took this road since the underlying problem is with the |
| final class CatalogEntryTests: XCTestCase { | ||
| func testGroupEntry_IsComparableAlphabetically() { | ||
| let entryA = Catalog.Entry.group(name: "A", items: []) | ||
| let entryB = Catalog.Entry.group(name: "B", items: []) |
There was a problem hiding this comment.
Could be nice to also add some tests using different letter case to check if that comparability is case-sensitive or not (but whether it is or not, that it always sorts ["A","a"].map { Catalog.Entry.group(name: $0, items: []) } in the same order
There was a problem hiding this comment.
Now that I think about it, I should also test that two groups with the same name order its items correctly.
I'll work on that 👍
| let entryA = Catalog.Entry.group(name: "A", items: []) | ||
| let entryB = Catalog.Entry.group(name: "B", items: []) | ||
|
|
||
| XCTAssertEqual(entryA < entryB, true) |
There was a problem hiding this comment.
The expected usage of XCTAssertEqual is to take 2 parameters to equate, like XCTAssertEqual(entryA, entryB).
If you want to check if an expression, like entryA < entryB, is true, prefer XCTAssert or XCTAssertTrue.
(Some even prefer using XCTAssertLessThan(entryA, entryB) but this last one being less commonly known, XCTAssert or XCTAssertTrue are generally more fitting)
| return .orderedDescending | ||
| } | ||
|
|
||
| return compare(Array(lhs.dropFirst()), Array(rhs.dropFirst())) |
There was a problem hiding this comment.
I'm not a fan of using this recursive approach as it can make the stack grow quite quickly for a group containing 100s of images…
What about:
private static func compare(_ lhs: [Catalog.Entry], _ rhs: [Catalog.Entry]) -> ComparisonResult {
for pair in zip(lhs, rhs) {
if pair.0 < pair.1 { return .orderedAscending }
if pair.0 > pair.1 { return .orderedDescending }
}
// If we arrive a this point, this means all pairs have been considered equal
// but one of the list might be longer than the other
if lhs.count < rhs.count { return .orderedAscending }
if lhs.count > rhs.count { return .orderedDescending }
return .orderedSame
}There was a problem hiding this comment.
That's a good point and a much cleaner implementation. Updating 👍
There was a problem hiding this comment.
I even wonder if the last part (last 3 lines) couldn't be reduced to return compare(lhs.count, rhs.count)?
(Don't we have a compare(Int,Int) -> ComparisonResult in the stdlib?)
f4463e2 to
bc03531
Compare
| @@ -82,7 +133,7 @@ extension AssetsCatalogParser { | |||
| func process(folder: Path, withPrefix prefix: String = "") -> [Catalog.Entry] { | |||
| return (try? folder.children().flatMap { | |||
There was a problem hiding this comment.
@fdiaz I just realised: wouldn't it be simpler instead of all the Equatable + Comparable implementations you added… to just sort the output of children() directly? i.e. apply folder.children().sorted(by: <).flatMap { … } to children, instead of using folder.children().flatMap { … }.sorted(by: <) and sort the the final, recursively-constructed structure?
Which would mean in practice removing all the code that you added above and a simpler and mode performant solution (because you don't have to traverse the recursive structure twice) in the end, right?
There was a problem hiding this comment.
Oh wow, you're right. I didn't notice that Path was already Comparable. I'll just go back with all these changes and add that little change instead. Nice catch!
The children() function uses under the hood contentsOfDirectory(atPath:) https://developer.apple.com/documentation/foundation/filemanager/1414584-contentsofdirectory This array returned by that function has an undefined order.
bc03531 to
5d1401f
Compare
djbe
left a comment
There was a problem hiding this comment.
We should probably also change our tests to run on the latest Xcode, and the latest macOS (if possible), to ensure that this is actually fixed (and remains so).
| ### Bug Fixes | ||
|
|
||
| _None_ | ||
| * Fixes an issue in High Sierra where the output of the processed Catalog Entries was not ordered alphabetically. |
There was a problem hiding this comment.
This seems to be missing the 2 spaces at the end?
|
What simplification? This PR boils down to 1 line of code 😄 |
|
Oh I missed the notification telling me that @fdiaz did in fact already commit the simplification we talked about about sorting Seems like the Circle tests are still failing though. |
|
Yeah, I partially followed it, will fix the contexts. |
cddee57 to
7128771
Compare
|
Cool 💚 |
|
Thanks for finishing this up @djbe 👍 I'm not sure why the tests were still failing though? Any context on that? I was about to take a look on High Sierra to see what was going on with that. |
|
There is a slight difference between the (built in) sort-order in Sierra, and the sorting we now apply. Nothing much to worry about. |
Closes #56