From 0aa3d25c1fadab583bb04a54fea13344c2b04170 Mon Sep 17 00:00:00 2001 From: Ryo Aoyama Date: Mon, 20 Aug 2018 23:57:54 +0900 Subject: [PATCH 1/3] Set the target to data of the last stage --- Sources/Algorithm.swift | 12 ++++++++++++ Tests/AlgorithmTest.swift | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Sources/Algorithm.swift b/Sources/Algorithm.swift index b0af10e..5a1c411 100644 --- a/Sources/Algorithm.swift +++ b/Sources/Algorithm.swift @@ -95,6 +95,12 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C ) } + // Set the target to `data` of the last stage. + if !changesets.isEmpty { + let index = changesets.index(before: changesets.endIndex) + changesets[index].data = target + } + self.init(changesets) } } @@ -363,6 +369,12 @@ public extension StagedChangeset where Collection: RangeReplaceableCollection, C ) } + // Set the target to `data` of the last stage. + if !changesets.isEmpty { + let index = changesets.index(before: changesets.endIndex) + changesets[index].data = target + } + self.init(changesets) } } diff --git a/Tests/AlgorithmTest.swift b/Tests/AlgorithmTest.swift index 69a7d3f..518ce6e 100644 --- a/Tests/AlgorithmTest.swift +++ b/Tests/AlgorithmTest.swift @@ -5,6 +5,18 @@ final class AlgorithmTestCase: XCTestCase {} /// Test algorithm for linear collection. extension AlgorithmTestCase { + func testEmptyChangesets() { + let source = [Int]() + let target = [Int]() + + XCTAssertExactDifferences( + source: source, + target: target, + section: 0, + expected: [] + ) + } + func testDeleted() { let section = 1 @@ -227,6 +239,17 @@ extension AlgorithmTestCase { /// Test algorithm for sectioned collection. extension AlgorithmTestCase { + func testSectionedEmptyChangesets() { + let source = [Section]() + let target = [Section]() + + XCTAssertExactDifferences( + source: source, + target: target, + expected: [] + ) + } + func testSectionInserted() { let source1 = [ Section(model: D.a, elements: [0]) From ada60c60dc2e2ab4f0aaba9353132bf3c738c957 Mon Sep 17 00:00:00 2001 From: Ryo Aoyama Date: Tue, 21 Aug 2018 00:00:10 +0900 Subject: [PATCH 2/3] Update podspec --- DifferenceKit.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DifferenceKit.podspec b/DifferenceKit.podspec index b9bd3ba..e255092 100644 --- a/DifferenceKit.podspec +++ b/DifferenceKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'DifferenceKit' - spec.version = '0.4.0' + spec.version = '0.4.1' spec.author = { 'ra1028' => 'r.fe51028.r@gmail.com' } spec.homepage = 'https://github.com/ra1028/DifferenceKit' spec.documentation_url = 'https://ra1028.github.io/DifferenceKit' From 4fd99b9928bf541c7fc86d04a1214475d0967219 Mon Sep 17 00:00:00 2001 From: Ryo Aoyama Date: Tue, 21 Aug 2018 00:39:45 +0900 Subject: [PATCH 3/3] Add released version badge --- README.md | 9 +++++---- docs/Extensions.html | 2 +- docs/Extensions/UICollectionView.html | 2 +- docs/Extensions/UITableView.html | 2 +- docs/Protocols.html | 2 +- docs/Protocols/Differentiable.html | 2 +- docs/Protocols/DifferentiableSection.html | 2 +- docs/Structs.html | 2 +- docs/Structs/AnyDifferentiable.html | 2 +- docs/Structs/Changeset.html | 2 +- docs/Structs/ElementPath.html | 2 +- docs/Structs/Section.html | 2 +- docs/Structs/StagedChangeset.html | 2 +- docs/index.html | 11 ++++++----- 14 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index b094dd8..66806b0 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,14 @@ The algorithm is optimized based on the Paul Heckel's algorithm.

-Swift4 +Swift4 +Release CocoaPods -Carthage +Carthage
Build Status -Platform -Lincense +Platform +Lincense

--- diff --git a/docs/Extensions.html b/docs/Extensions.html index 39fb4b0..52cbdb9 100644 --- a/docs/Extensions.html +++ b/docs/Extensions.html @@ -141,7 +141,7 @@

Declaration

diff --git a/docs/Extensions/UICollectionView.html b/docs/Extensions/UICollectionView.html index b961a6c..a3a761b 100644 --- a/docs/Extensions/UICollectionView.html +++ b/docs/Extensions/UICollectionView.html @@ -175,7 +175,7 @@

Parameters

diff --git a/docs/Extensions/UITableView.html b/docs/Extensions/UITableView.html index cb3be29..5f3a837 100644 --- a/docs/Extensions/UITableView.html +++ b/docs/Extensions/UITableView.html @@ -349,7 +349,7 @@

Parameters

diff --git a/docs/Protocols.html b/docs/Protocols.html index 26300d8..d1b74a0 100644 --- a/docs/Protocols.html +++ b/docs/Protocols.html @@ -147,7 +147,7 @@

Declaration

diff --git a/docs/Protocols/Differentiable.html b/docs/Protocols/Differentiable.html index 5d55ca7..22e6b37 100644 --- a/docs/Protocols/Differentiable.html +++ b/docs/Protocols/Differentiable.html @@ -216,7 +216,7 @@

Return Value

diff --git a/docs/Protocols/DifferentiableSection.html b/docs/Protocols/DifferentiableSection.html index 5f47823..ea21c7f 100644 --- a/docs/Protocols/DifferentiableSection.html +++ b/docs/Protocols/DifferentiableSection.html @@ -259,7 +259,7 @@

Parameters

diff --git a/docs/Structs.html b/docs/Structs.html index 1baff81..f95d4db 100644 --- a/docs/Structs.html +++ b/docs/Structs.html @@ -309,7 +309,7 @@

Declaration

diff --git a/docs/Structs/AnyDifferentiable.html b/docs/Structs/AnyDifferentiable.html index 0c33ede..e668f2f 100644 --- a/docs/Structs/AnyDifferentiable.html +++ b/docs/Structs/AnyDifferentiable.html @@ -297,7 +297,7 @@

Declaration

diff --git a/docs/Structs/Changeset.html b/docs/Structs/Changeset.html index 2b6c802..e6292ae 100644 --- a/docs/Structs/Changeset.html +++ b/docs/Structs/Changeset.html @@ -607,7 +607,7 @@

Declaration

diff --git a/docs/Structs/ElementPath.html b/docs/Structs/ElementPath.html index 261e39d..b2f0c84 100644 --- a/docs/Structs/ElementPath.html +++ b/docs/Structs/ElementPath.html @@ -240,7 +240,7 @@

Declaration

diff --git a/docs/Structs/Section.html b/docs/Structs/Section.html index 3f0844d..1c15515 100644 --- a/docs/Structs/Section.html +++ b/docs/Structs/Section.html @@ -268,7 +268,7 @@

Declaration

diff --git a/docs/Structs/StagedChangeset.html b/docs/Structs/StagedChangeset.html index 8350234..9ad7d93 100644 --- a/docs/Structs/StagedChangeset.html +++ b/docs/Structs/StagedChangeset.html @@ -673,7 +673,7 @@

Declaration

diff --git a/docs/index.html b/docs/index.html index 6d93d52..b120acc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -83,13 +83,14 @@

-Swift4 +Swift4 +Release CocoaPods -Carthage +Carthage
Build Status -Platform -Lincense +Platform +Lincense


@@ -632,7 +633,7 @@

License