Skip to content

Commit

Permalink
Fixes after renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
wokalski committed Nov 21, 2016
1 parent 8c71c2e commit 6e217b8
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 38 deletions.
14 changes: 7 additions & 7 deletions DiffTests/DiffTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class DiffTests: XCTestCase {
func testDiffOutputs() {
for expectation in expectations {
XCTAssertEqual(
_test(expectation.0, to: expectation.1),
_test(from: expectation.0, to: expectation.1),
expectation.2)
}
}

func testExtendedDiffOutputs() {
for expectation in extendedExpectations {
XCTAssertEqual(
_testExtended(expectation.0, to: expectation.1),
_testExtended(from: expectation.0, to: expectation.1),
expectation.2)
}
}
Expand All @@ -74,36 +74,36 @@ class DiffTests: XCTestCase {

func testDuplicateTraces() {
for expectation in expectations {
XCTAssertFalse(duplicateTraces(expectation.0, to: expectation.1))
XCTAssertFalse(duplicateTraces(from: expectation.0, to: expectation.1))
}
}

func testTracesOutOfBounds() {
for expectation in expectations {
if tracesOutOfBounds(expectation.0, to: expectation.1) != [] {
if tracesOutOfBounds(from: expectation.0, to: expectation.1) != [] {
XCTFail("traces out of bounds for \(expectation.0) -> \(expectation.1)")
}
}
}

func duplicateTraces(from: String, to: String) -> Bool {
let traces = from.characters.diffTraces(to.characters)
let traces = from.characters.diffTraces(to: to.characters)
let tracesSet = Set(traces)
return !(traces.count == tracesSet.count)
}

func tracesOutOfBounds(from: String, to: String) -> [Trace] {
let ac = from.characters
let bc = to.characters
return ac.diffTraces(bc)
return ac.diffTraces(to: bc)
.filter { $0.to.y > bc.count || $0.to.x > ac.count }
}

func _test(
from: String,
to: String) -> String {
return from
.diff(to)
.diff(to: to)
.reduce("") { $0 + $1.debugDescription }
}

Expand Down
20 changes: 8 additions & 12 deletions DiffTests/ExtendedPatchSortTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExtendedPatchSortTests: XCTestCase {

for expectation in expectations {
XCTAssertEqual(
_extendedTest(expectation.0, to: expectation.1),
_extendedTest(from: expectation.0, to: expectation.1),
expectation.2)
}
}
Expand All @@ -42,7 +42,7 @@ class ExtendedPatchSortTests: XCTestCase {
for expectation in expectations {
XCTAssertEqual(
_extendedTest(
expectation.0,
from: expectation.0,
to: expectation.1,
sortingFunction: sort),
expectation.2)
Expand Down Expand Up @@ -71,7 +71,7 @@ class ExtendedPatchSortTests: XCTestCase {
for expectation in expectations {
XCTAssertEqual(
_extendedTest(
expectation.0,
from: expectation.0,
to: expectation.1,
sortingFunction: sort),
expectation.2)
Expand All @@ -86,7 +86,7 @@ class ExtendedPatchSortTests: XCTestCase {
let string1 = "eakjnrsignambmcbdcdhdkmhkolpdgfedcpgabtldjkaqkoobomuhpepirdcrdrgmrmaefesoiildmtnbronpmmbuuplnfnjgdhadkbmprensshiekknhskognpbknpbepmlakducnfktjeookncjpcnpklfedrebstisalskigsuojkookhbmkdafiaftrkrccupgjapqrigbanfbboapmicabeclhentlabourhtqmlboqctgorajirchesaorsgnigattkdrenquffcutffopbjrebegbfmkeikstqsut"
let string2 = "mdjqtbchphncsjdkjtutagahmdtfcnjliipmqgrhgajsgotcdgidlghithdgrcmfuausmjnbtjghqblaiuldirulhllidbpcpglfbnfbkbddhdskdplsgjjsusractdplajrctgrcebhesbeneidsititlalsqkhliontgpesglkoorjqeniqaetatamneonhbhunqlfkbmfsjallnejhkcfaeapdnacqdtukcuiheiabqpudmgosssabisrrlmhcmpkgerhesqihdnfjmqgfnmulnfkmpqrsghutfsckurr"
let patch = string1.extendedDiff(string2).patch(
string1.characters,
from: string1.characters,
to: string2.characters,
sort:sort)
let result = string1.apply(patch)
Expand All @@ -102,17 +102,13 @@ func _extendedTest(
to: String,
sortingFunction: ExtendedSortingFunction? = nil) -> String {
guard let sort = sortingFunction else {
return from
.extendedDiff(to)
.patch(
from.characters,
return extendedPatch(
from: from.characters,
to: to.characters)
.reduce("") { $0 + $1.debugDescription }
}
return from
.extendedDiff(to)
.patch(
from.characters,
return extendedPatch(
from: from.characters,
to: to.characters,
sort: sort)
.reduce("") { $0 + $1.debugDescription }
Expand Down
20 changes: 8 additions & 12 deletions DiffTests/PatchSortTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PatchTests: XCTestCase {

for expectation in defaultOrder {
XCTAssertEqual(
_test(expectation.0, to: expectation.1),
_test(from: expectation.0, to: expectation.1),
expectation.2)
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ class PatchTests: XCTestCase {
for expectation in insertionsFirst {
XCTAssertEqual(
_test(
expectation.0,
from: expectation.0,
to: expectation.1,
sortingFunction: insertionsFirstSort),
expectation.2)
Expand Down Expand Up @@ -106,7 +106,7 @@ class PatchTests: XCTestCase {
for expectation in deletionsFirst {
XCTAssertEqual(
_test(
expectation.0,
from: expectation.0,
to: expectation.1,
sortingFunction: deletionsFirstSort),
expectation.2)
Expand All @@ -121,7 +121,7 @@ class PatchTests: XCTestCase {
for _ in 0..<200 {
let randomString = randomAlphaNumericString(length: 30)
let permutation = randomAlphaNumericString(length: 30)
let patch = randomString.diff(permutation).patch(randomString.characters, to: permutation.characters, sort:sort)
let patch = randomString.diff(to: permutation).patch(from: randomString.characters, to: permutation.characters, sort:sort)
let result = randomString.apply(patch)
XCTAssertEqual(result, permutation)
}
Expand Down Expand Up @@ -151,18 +151,14 @@ func _test(
to: String,
sortingFunction: SortingFunction? = nil) -> String {
if let sort = sortingFunction {
return from
.diff(to)
.patch(
from.characters,
return patch(
from: from.characters,
to: to.characters,
sort: sort)
.reduce("") { $0 + $1.debugDescription }
}
return from
.diff(to)
.patch(
from.characters,
return patch(
from: from.characters,
to: to.characters)
.reduce("") { $0 + $1.debugDescription }
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ExtendedPatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public func extendedPatch<T: Collection>(
from: T,
to: T,
sort: ExtendedDiff.OrderedBefore? = nil
) -> [Patch<T.Iterator.Element>] where T.Iterator.Element : Equatable {
) -> [ExtendedPatch<T.Iterator.Element>] where T.Iterator.Element : Equatable {
return from.extendedDiff(to).patch(from: from, to: to, sort: sort)
}

Expand Down
8 changes: 2 additions & 6 deletions Sources/GenericPatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ func shiftPatchElement<T>(from: DoublyLinkedList<SortedPatchElement<T>>, to: Dou
case .neighbor(let direction), .jump(let direction):
if case .left = direction {
switch (from.value.value, to.value.value) {
case (.insertion, .insertion):
case (.insertion, _):
to.value = to.value.decremented()
case (.deletion, .deletion):
to.value = to.value.incremented()
case (.insertion, .deletion):
to.value = to.value.decremented()
case (.deletion, .insertion):
case (.deletion, _):
to.value = to.value.incremented()
}
}
Expand Down

0 comments on commit 6e217b8

Please sign in to comment.