Skip to content

Commit 7c902f8

Browse files
authored
Merge pull request #38 from farzadshbfn/master
Add Transform to IndexPath's when working with UI
2 parents d4daadf + 6264a23 commit 7c902f8

File tree

5 files changed

+261
-58
lines changed

5 files changed

+261
-58
lines changed

Diff for: Diff.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
C9D4BC961E1124CE00C79537 /* NestedExtendedDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D4BC951E1124CE00C79537 /* NestedExtendedDiff.swift */; };
2828
C9EE87841CCFFB68006BD90E /* Diff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EE87821CCFFB68006BD90E /* Diff.swift */; };
2929
C9EE87861CCFFB68006BD90E /* Patch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EE87831CCFFB68006BD90E /* Patch.swift */; };
30+
E2F1C8561E3A14DF00FBE786 /* BatchUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F1C8551E3A14DF00FBE786 /* BatchUpdateTests.swift */; };
3031
/* End PBXBuildFile section */
3132

3233
/* Begin PBXFileReference section */
@@ -56,6 +57,7 @@
5657
C9EE87161CCFCA83006BD90E /* Diff.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Diff.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5758
C9EE87821CCFFB68006BD90E /* Diff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Diff.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
5859
C9EE87831CCFFB68006BD90E /* Patch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Patch.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
60+
E2F1C8551E3A14DF00FBE786 /* BatchUpdateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BatchUpdateTests.swift; path = DiffTests/BatchUpdateTests.swift; sourceTree = SOURCE_ROOT; };
5961
/* End PBXFileReference section */
6062

6163
/* Begin PBXFrameworksBuildPhase section */
@@ -97,6 +99,7 @@
9799
C90CD7181DFB43C600BE9114 /* NestedDiffTests.swift */,
98100
C921BF701E15448300747566 /* NestedExtendedDiffTests.swift */,
99101
C9838FF51D29571000691BE8 /* Info.plist */,
102+
E2F1C8551E3A14DF00FBE786 /* BatchUpdateTests.swift */,
100103
);
101104
path = DiffTests;
102105
sourceTree = "<group>";
@@ -245,6 +248,7 @@
245248
C99118AC1DDDAD6E00067A60 /* ExtendedPatchSortTests.swift in Sources */,
246249
C921BF711E15448300747566 /* NestedExtendedDiffTests.swift in Sources */,
247250
C90CD7191DFB43C600BE9114 /* NestedDiffTests.swift in Sources */,
251+
E2F1C8561E3A14DF00FBE786 /* BatchUpdateTests.swift in Sources */,
248252
);
249253
runOnlyForDeploymentPostprocessing = 0;
250254
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>classNames</key>
6+
<dict>
7+
<key>BatchUpdateTests</key>
8+
<dict>
9+
<key>testCellsPerformance()</key>
10+
<dict>
11+
<key>com.apple.XCTPerformanceMetric_WallClockTime</key>
12+
<dict>
13+
<key>baselineAverage</key>
14+
<real>0.14952</real>
15+
<key>baselineIntegrationDisplayName</key>
16+
<string>Local Baseline</string>
17+
</dict>
18+
</dict>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>runDestinationsByUUID</key>
6+
<dict>
7+
<key>5ACB3D1B-D608-4861-BD7C-4E5E202E879C</key>
8+
<dict>
9+
<key>localComputer</key>
10+
<dict>
11+
<key>busSpeedInMHz</key>
12+
<integer>100</integer>
13+
<key>cpuCount</key>
14+
<integer>1</integer>
15+
<key>cpuKind</key>
16+
<string>Intel Core i5</string>
17+
<key>cpuSpeedInMHz</key>
18+
<integer>2900</integer>
19+
<key>logicalCPUCoresPerPackage</key>
20+
<integer>4</integer>
21+
<key>modelCode</key>
22+
<string>MacBookPro12,1</string>
23+
<key>physicalCPUCoresPerPackage</key>
24+
<integer>2</integer>
25+
<key>platformIdentifier</key>
26+
<string>com.apple.platform.macosx</string>
27+
</dict>
28+
<key>targetArchitecture</key>
29+
<string>i386</string>
30+
<key>targetDevice</key>
31+
<dict>
32+
<key>modelCode</key>
33+
<string>iPhone5,1</string>
34+
<key>platformIdentifier</key>
35+
<string>com.apple.platform.iphonesimulator</string>
36+
</dict>
37+
</dict>
38+
</dict>
39+
</dict>
40+
</plist>

Diff for: DiffTests/BatchUpdateTests.swift

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#if !os(macOS) && !os(watchOS)
2+
3+
import XCTest
4+
@testable import Diff
5+
6+
func IP(_ row: Int, _ section: Int) -> IndexPath {
7+
return IndexPath(row: row, section: section)
8+
}
9+
10+
class BatchUpdateTests: XCTestCase {
11+
12+
let cellExpectations = [
13+
([1, 2, 3, 4], [1, 2, 3, 4], ([], [], [])),
14+
([1, 2, 3, 4], [4, 2, 3, 1], ([], [], [(IP(0, 0), IP(3, 0)), (IP(3, 0), IP(0, 0))])),
15+
([1, 2, 3, 4], [2, 3, 1], ([IP(3, 0)], [], [(IP(0, 0), IP(2, 0))])),
16+
([1, 2, 3, 4], [5, 2, 3, 4], ([IP(0, 0)], [IP(0, 0)], [])),
17+
([1, 2, 3, 4], [4, 1, 3, 5], ([IP(1, 0)], [IP(3, 0)], [(IP(2, 0), IP(0, 0))])),
18+
([1, 2, 3, 4], [4, 2, 3, 4], ([IP(0, 0)], [IP(0, 0)], [])),
19+
([1, 2, 3, 4], [1, 2, 4, 4], ([IP(2, 0)], [IP(3, 0)], [])),
20+
([1, 2, 3, 4], [5, 6, 7, 8], ([IP(0, 0), IP(1, 0), IP(2, 0), IP(3, 0)], [IP(0, 0), IP(1, 0), IP(2, 0), IP(3, 0)], [])),
21+
([1, 2, 3, 4], [5, 6, 7, 1], ([IP(1, 0), IP(2, 0), IP(3, 0)], [IP(0, 0), IP(1, 0), IP(2, 0)], [])),
22+
]
23+
24+
func testCells() {
25+
_testCells()
26+
}
27+
28+
func testCellsWithTransform() {
29+
_testCellsWithTransform()
30+
}
31+
32+
func _testCells() {
33+
for expectation in cellExpectations {
34+
let batch = BatchUpdate(diff: expectation.0.extendedDiff(expectation.1))
35+
XCTAssertEqual(batch.deletions, expectation.2.0)
36+
XCTAssertEqual(batch.insertions, expectation.2.1)
37+
XCTAssertEqual(batch.moves, expectation.2.2)
38+
}
39+
}
40+
41+
func _testCellsWithTransform() {
42+
let transform: (IndexPath) -> IndexPath = { IP($0.row + 1, $0.section + 2) }
43+
44+
for expectation in cellExpectations {
45+
let batch = BatchUpdate(diff: expectation.0.extendedDiff(expectation.1), indexPathTransform: transform)
46+
XCTAssertEqual(batch.deletions, expectation.2.0.map(transform))
47+
XCTAssertEqual(batch.insertions, expectation.2.1.map(transform))
48+
XCTAssertEqual(batch.moves, expectation.2.2.map { (transform($0.0), transform($0.1)) })
49+
}
50+
}
51+
52+
//
53+
// // MARK: Performance Tests
54+
// func testCellsPerformance() {
55+
// self.measure {
56+
// self._testCells()
57+
// }
58+
// }
59+
//
60+
// func testCellsWithTransformPerformance() {
61+
// self.measure {
62+
// self._testCellsWithTransform()
63+
// }
64+
// }
65+
}
66+
67+
#endif

0 commit comments

Comments
 (0)