Skip to content

Commit

Permalink
Merge pull request #27 from wokalski/14-NestedDiff
Browse files Browse the repository at this point in the history
NestedDiff
  • Loading branch information
wokalski authored Jan 2, 2017
2 parents 6cc7c09 + bd9b283 commit addbbb0
Show file tree
Hide file tree
Showing 15 changed files with 1,511 additions and 119 deletions.
19 changes: 19 additions & 0 deletions Diff.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
900E03A41DE7C6C60033A799 /* Diff.h in Headers */ = {isa = PBXBuildFile; fileRef = C92178BB1CD0023E004642C7 /* Diff.h */; settings = {ATTRIBUTES = (Public, ); }; };
900E03A51DE7C6D60033A799 /* Diff.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C9EE87161CCFCA83006BD90E /* Diff.framework */; };
C90CD7171DFB368200BE9114 /* NestedDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90CD7161DFB368200BE9114 /* NestedDiff.swift */; };
C90CD7191DFB43C600BE9114 /* NestedDiffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90CD7181DFB43C600BE9114 /* NestedDiffTests.swift */; };
C921BF711E15448300747566 /* NestedExtendedDiffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C921BF701E15448300747566 /* NestedExtendedDiffTests.swift */; };
C9278ADE1DE32B88009CE846 /* Diff+UIKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9278ADD1DE32B88009CE846 /* Diff+UIKit.swift */; };
C96F41941DE0EEC500B8E135 /* ExtendedPatch+Apply.swift in Sources */ = {isa = PBXBuildFile; fileRef = C96F41931DE0EEC500B8E135 /* ExtendedPatch+Apply.swift */; };
C9838FF41D29571000691BE8 /* DiffTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9838FF31D29571000691BE8 /* DiffTests.swift */; };
Expand All @@ -21,6 +24,7 @@
C99118B81DE062BE00067A60 /* GenericPatch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C99118B51DE0629000067A60 /* GenericPatch.swift */; };
C9B03FC01DE1CA7500BC6F2A /* ExtendedDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9B03FBF1DE1CA7500BC6F2A /* ExtendedDiff.swift */; };
C9C9247A1DBB97130006ACC4 /* PatchSortTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9C924791DBB97130006ACC4 /* PatchSortTests.swift */; };
C9D4BC961E1124CE00C79537 /* NestedExtendedDiff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D4BC951E1124CE00C79537 /* NestedExtendedDiff.swift */; };
C9EE87841CCFFB68006BD90E /* Diff.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EE87821CCFFB68006BD90E /* Diff.swift */; };
C9EE87861CCFFB68006BD90E /* Patch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9EE87831CCFFB68006BD90E /* Patch.swift */; };
/* End PBXBuildFile section */
Expand All @@ -29,8 +33,11 @@
900E039F1DE7C3370033A799 /* Universal-Framework-Target.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Universal-Framework-Target.xcconfig"; sourceTree = "<group>"; };
900E03A01DE7C3370033A799 /* Universal-Target-Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Universal-Target-Base.xcconfig"; sourceTree = "<group>"; };
900E03AF1DE7F1E80033A799 /* Deployment-Targets.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Deployment-Targets.xcconfig"; sourceTree = "<group>"; };
C90CD7161DFB368200BE9114 /* NestedDiff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedDiff.swift; sourceTree = "<group>"; };
C90CD7181DFB43C600BE9114 /* NestedDiffTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedDiffTests.swift; sourceTree = "<group>"; };
C92178BB1CD0023E004642C7 /* Diff.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Diff.h; path = Framework/Diff.h; sourceTree = "<group>"; };
C92178BD1CD0023E004642C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Framework/Info.plist; sourceTree = "<group>"; };
C921BF701E15448300747566 /* NestedExtendedDiffTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedExtendedDiffTests.swift; sourceTree = "<group>"; };
C9278ADD1DE32B88009CE846 /* Diff+UIKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Diff+UIKit.swift"; sourceTree = "<group>"; };
C96F41931DE0EEC500B8E135 /* ExtendedPatch+Apply.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ExtendedPatch+Apply.swift"; sourceTree = "<group>"; };
C9838FF11D29571000691BE8 /* DiffTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DiffTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -45,6 +52,7 @@
C99118B51DE0629000067A60 /* GenericPatch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GenericPatch.swift; sourceTree = "<group>"; };
C9B03FBF1DE1CA7500BC6F2A /* ExtendedDiff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = ExtendedDiff.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C9C924791DBB97130006ACC4 /* PatchSortTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = PatchSortTests.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C9D4BC951E1124CE00C79537 /* NestedExtendedDiff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedExtendedDiff.swift; sourceTree = "<group>"; };
C9EE87161CCFCA83006BD90E /* Diff.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Diff.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C9EE87821CCFFB68006BD90E /* Diff.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Diff.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
C9EE87831CCFFB68006BD90E /* Patch.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = Patch.swift; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
Expand Down Expand Up @@ -86,6 +94,8 @@
C991189D1DDB4F1100067A60 /* PatchApplyTests.swift */,
C99118AB1DDDAD6E00067A60 /* ExtendedPatchSortTests.swift */,
C9838FF31D29571000691BE8 /* DiffTests.swift */,
C90CD7181DFB43C600BE9114 /* NestedDiffTests.swift */,
C921BF701E15448300747566 /* NestedExtendedDiffTests.swift */,
C9838FF51D29571000691BE8 /* Info.plist */,
);
path = DiffTests;
Expand Down Expand Up @@ -116,6 +126,8 @@
children = (
C9EE87821CCFFB68006BD90E /* Diff.swift */,
C9B03FBF1DE1CA7500BC6F2A /* ExtendedDiff.swift */,
C90CD7161DFB368200BE9114 /* NestedDiff.swift */,
C9D4BC951E1124CE00C79537 /* NestedExtendedDiff.swift */,
C9278ADD1DE32B88009CE846 /* Diff+UIKit.swift */,
C9EE87831CCFFB68006BD90E /* Patch.swift */,
C99118971DDB4C3000067A60 /* Patch+Sort.swift */,
Expand Down Expand Up @@ -231,6 +243,8 @@
C9C9247A1DBB97130006ACC4 /* PatchSortTests.swift in Sources */,
C9838FF41D29571000691BE8 /* DiffTests.swift in Sources */,
C99118AC1DDDAD6E00067A60 /* ExtendedPatchSortTests.swift in Sources */,
C921BF711E15448300747566 /* NestedExtendedDiffTests.swift in Sources */,
C90CD7191DFB43C600BE9114 /* NestedDiffTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -242,12 +256,14 @@
C99118951DDB1BA800067A60 /* LinkedList.swift in Sources */,
C99118B81DE062BE00067A60 /* GenericPatch.swift in Sources */,
C9EE87861CCFFB68006BD90E /* Patch.swift in Sources */,
C9D4BC961E1124CE00C79537 /* NestedExtendedDiff.swift in Sources */,
C99118981DDB4C3000067A60 /* Patch+Sort.swift in Sources */,
C9278ADE1DE32B88009CE846 /* Diff+UIKit.swift in Sources */,
C991189B1DDB4EAB00067A60 /* Patch+Apply.swift in Sources */,
C96F41941DE0EEC500B8E135 /* ExtendedPatch+Apply.swift in Sources */,
C9EE87841CCFFB68006BD90E /* Diff.swift in Sources */,
C99118B01DDDB02D00067A60 /* ExtendedPatch.swift in Sources */,
C90CD7171DFB368200BE9114 /* NestedDiff.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -380,6 +396,7 @@
INFOPLIST_FILE = "$(SRCROOT)/Framework/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
Expand All @@ -391,9 +408,11 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_OPTIMIZATION_LEVEL = 0;
INFOPLIST_FILE = "$(SRCROOT)/Framework/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down
210 changes: 210 additions & 0 deletions DiffTests/NestedDiffTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@

import XCTest
@testable import Diff

struct KeyedIntArray: Equatable {
let elements: [Int]
let key: Int

public static func ==(fst: KeyedIntArray, snd: KeyedIntArray) -> Bool {
return fst.key == snd.key
}
}

extension Array: Equatable {
public static func ==<T>(fst: Array<T>, snd: Array<T>) -> Bool {
return fst.count == snd.count
}
}

extension KeyedIntArray: Collection {
public func index(after i: Int) -> Int {
return i + 1
}

public typealias IndexType = Array<Int>.Index

public var startIndex: IndexType {
return elements.startIndex
}

public var endIndex: IndexType {
return elements.endIndex
}

public subscript(i: IndexType) -> Int {
return elements[i]
}
}

class NestedDiffTests: XCTestCase {

func testDiffOutputs() {

let keyedExpectations = [
(
[],
[
KeyedIntArray(elements: [1, 2], key: 0),
KeyedIntArray(elements: [1], key: 1),
],
"IS(0)IS(1)"
),
(
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [1], key: 1),
],
[
KeyedIntArray(elements: [1], key: 0),
KeyedIntArray(elements: [], key: 1),
],
"DE(0,0)IE(0,0)DE(0,1)"
),
(
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [0], key: 5),
KeyedIntArray(elements: [1], key: 1),
],
[
KeyedIntArray(elements: [1], key: 0),
KeyedIntArray(elements: [], key: 1),
],
"DS(1)DE(0,0)IE(0,0)DE(0,2)"
),
(
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [0], key: 5),
KeyedIntArray(elements: [1], key: 1),
],
[
KeyedIntArray(elements: [1], key: 0),
KeyedIntArray(elements: [], key: 1),
],
"DS(1)DE(0,0)IE(0,0)DE(0,2)"
),
(
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [1, 2, 3], key: -1),
KeyedIntArray(elements: [1], key: 1),
],
[
KeyedIntArray(elements: [2, 3], key: 0),
KeyedIntArray(elements: [1, 2], key: 1),
],
"DS(1)IE(1,0)IE(1,1)"
),
(
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [1], key: 1),
],
[
KeyedIntArray(elements: [2, 1], key: 0),
KeyedIntArray(elements: [], key: 1),
],
"IE(1,0)DE(0,1)"
),
(
[
KeyedIntArray(elements: [], key: 0),
KeyedIntArray(elements: [1, 2], key: 1),
],
[
KeyedIntArray(elements: [2], key: 0),
KeyedIntArray(elements: [], key: 1),
],
"IE(0,0)DE(0,1)DE(1,1)"
),
(
[
KeyedIntArray(elements: [1, 2], key: 0),
KeyedIntArray(elements: [], key: 1),
],
[
KeyedIntArray(elements: [], key: 0),
KeyedIntArray(elements: [1], key: 1),
],
"DE(0,0)DE(1,0)IE(0,1)"
),
(
[
KeyedIntArray(elements: [], key: 0),
KeyedIntArray(elements: [1], key: 1),
KeyedIntArray(elements: [2], key: 2),
],
[
KeyedIntArray(elements: [1, 2], key: 0),
KeyedIntArray(elements: [], key: 1),
KeyedIntArray(elements: [], key: 2),
],
"IE(0,0)IE(1,0)DE(0,1)DE(0,2)"
),
]

let expectations: [([[Int]], [[Int]], String)] = [
(
[],
[
[1, 2],
[1],
],
"IS(0)IS(1)"
),
(
[
[1, 2],
[],
],
[],
"DS(0)DS(1)"
),
(
[[1, 2], [], [1]],
[[1, 2], [], [1]],
""
),
(
[[1, 2], [1, 4]],
[[5, 2], [10, 4, 8]],
"DS(1)IS(1)DE(0,0)IE(0,0)"
),
(
[[1]],
[[], [1, 2]],
"DS(0)IS(0)IS(1)"
),
(
[[1]],
[[], [2]],
"IS(0)DE(0,0)IE(0,1)"
),
]

for expectation in expectations {
XCTAssertEqual(
_test(from: expectation.0, to: expectation.1),
expectation.2)
}

for expectation in keyedExpectations {
XCTAssertEqual(
_test(from: expectation.0, to: expectation.1),
expectation.2)
}
}

func _test<T: Collection>(
from: [T],
to: [T]) -> String
where
T: Equatable,
T.Iterator.Element: Equatable {
return from
.nestedDiff(to: to)
.reduce("") { $0 + $1.debugDescription }
}
}
Loading

0 comments on commit addbbb0

Please sign in to comment.