Skip to content

Commit 51db1f4

Browse files
committed
improve variable names for swiftlint
1 parent 9b71615 commit 51db1f4

2 files changed

Lines changed: 64 additions & 64 deletions

File tree

Diff/DiffArray.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,21 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
274274
var k2end = 0
275275

276276
//
277-
for d in 0..<maxD {
277+
for currentD in 0..<maxD {
278278

279279
// Walk the front path one step.
280-
var k1 = -d + k1start
281-
while k1 <= d - k1end {
280+
var k1 = -currentD + k1start
281+
while k1 <= currentD - k1end {
282282
defer {
283283
k1 += 2
284284
}
285-
let k1_offset = vOffset + k1
285+
let k1Offset = vOffset + k1
286286
var x1 = 0
287287

288-
if k1 == -d || (k1 != d && v1[k1_offset - 1] < v1[k1_offset + 1]) {
289-
x1 = v1[k1_offset + 1]
288+
if k1 == -currentD || (k1 != currentD && v1[k1Offset - 1] < v1[k1Offset + 1]) {
289+
x1 = v1[k1Offset + 1]
290290
} else {
291-
x1 = v1[k1_offset - 1] + 1
291+
x1 = v1[k1Offset - 1] + 1
292292
}
293293

294294
var y1 = x1 - k1
@@ -299,7 +299,7 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
299299
y1 += 1
300300
}
301301

302-
v1[k1_offset] = x1
302+
v1[k1Offset] = x1
303303

304304
if x1 > arrayALength {
305305
// Ran off the right of the graph.
@@ -308,11 +308,11 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
308308
// Ran off the bottom of the graph.
309309
k1start += 2
310310
} else if front {
311-
let k2_offset = vOffset + delta - k1
311+
let k2Offset = vOffset + delta - k1
312312

313-
if k2_offset >= 0 && k2_offset < vLength && v2[k2_offset] != -1 {
313+
if k2Offset >= 0 && k2Offset < vLength && v2[k2Offset] != -1 {
314314
// Mirror x2 onto top-left coordinate system.
315-
let x2 = arrayALength - v2[k2_offset]
315+
let x2 = arrayALength - v2[k2Offset]
316316
if x1 >= x2 {
317317
// diffs = diff_bisectSplitOfStrings(text1, text2, x1, y1, properties);
318318
diffs = diff_bisectSplitOfArrays(arrayA: inArrayA, arrayB: inArrayB, x: x1, y: y1)
@@ -328,19 +328,19 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
328328
}
329329

330330
// Walk the reverse path one step.
331-
var k2 = -d + k2start
332-
while k2 <= d - k2end {
331+
var k2 = -currentD + k2start
332+
while k2 <= currentD - k2end {
333333

334334
defer {
335335
k2 += 2
336336
}
337-
let k2_offset = vOffset + k2
337+
let k2Offset = vOffset + k2
338338
var x2 = 0
339339

340-
if k2 == -d || (k2 != d && v2[k2_offset - 1] < v2[k2_offset + 1]) {
341-
x2 = v2[k2_offset + 1]
340+
if k2 == -currentD || (k2 != currentD && v2[k2Offset - 1] < v2[k2Offset + 1]) {
341+
x2 = v2[k2Offset + 1]
342342
} else {
343-
x2 = v2[k2_offset - 1] + 1
343+
x2 = v2[k2Offset - 1] + 1
344344
}
345345

346346
var y2 = x2 - k2
@@ -350,7 +350,7 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
350350
y2 += 1
351351
}
352352

353-
v2[k2_offset] = x2
353+
v2[k2Offset] = x2
354354

355355
if x2 > arrayALength {
356356
// Ran off the left of the graph.
@@ -359,11 +359,11 @@ func diff_bisectOfArrays<T: Equatable>(arrayA inArrayA: [T], arrayB inArrayB: [T
359359
// Ran off the top of the graph.
360360
k2start += 2
361361
} else if !front {
362-
let k1_offset = vOffset + delta - k2
362+
let k1Offset = vOffset + delta - k2
363363

364-
if k1_offset >= 0 && k1_offset < vLength && v1[k1_offset] != -1 {
365-
let x1 = v1[k1_offset]
366-
let y1 = vOffset + x1 - k1_offset
364+
if k1Offset >= 0 && k1Offset < vLength && v1[k1Offset] != -1 {
365+
let x1 = v1[k1Offset]
366+
let y1 = vOffset + x1 - k1Offset
367367
// Mirror x2 onto top-left coordinate system.
368368
x2 = arrayALength - x2
369369

DiffTests/DiffTests.swift

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class DiffTests: XCTestCase {
129129
}
130130

131131
func test002_bisectTest() {
132-
let a = ["c", "a", "t"]
133-
let b = ["m", "a", "p"]
132+
let arrayA = ["c", "a", "t"]
133+
let arrayB = ["m", "a", "p"]
134134

135135
let shouldBe = [
136136
Diff(operation: .delete, array: ["c"]),
@@ -140,7 +140,7 @@ class DiffTests: XCTestCase {
140140
Diff(operation: .insert, array: ["p"])
141141
]
142142

143-
let isActually = diff_bisectOfArrays(arrayA: a, arrayB: b)
143+
let isActually = diff_bisectOfArrays(arrayA: arrayA, arrayB: arrayB)
144144

145145
XCTAssertEqual(shouldBe, isActually, "...")
146146
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
@@ -154,85 +154,85 @@ class DiffTests: XCTestCase {
154154
}
155155

156156
func test003_trivialDiffEmpty() {
157-
var a: [String] = []
158-
var b: [String] = []
157+
var arrayA: [String] = []
158+
var arrayB: [String] = []
159159

160160
var shouldBe: [Diff<String>] = []
161161

162-
var isActually: [Diff<String>] = diffBetweenArrays(arrayA: a, arrayB: b)
162+
var isActually: [Diff<String>] = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
163163

164164
XCTAssertEqual(shouldBe, isActually, "...")
165165
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
166166

167167
// ----
168168

169-
a = ["a"]
170-
b = []
169+
arrayA = ["a"]
170+
arrayB = []
171171
shouldBe = [Diff(operation: .delete, array: ["a"])]
172-
isActually = diffBetweenArrays(arrayA: a, arrayB: b)
172+
isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
173173

174174
XCTAssertEqual(shouldBe, isActually, "...")
175175
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
176176

177-
a = []
178-
b = ["b"]
177+
arrayA = []
178+
arrayB = ["b"]
179179
shouldBe = [Diff(operation: .insert, array: ["b"])]
180-
isActually = diffBetweenArrays(arrayA: a, arrayB: b)
180+
isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
181181

182182
XCTAssertEqual(shouldBe, isActually, "...")
183183
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
184184

185185
}
186186

187187
func test004_trivialDiffSame() {
188-
let a: [String] = ["a", "b", "c"]
189-
let b: [String] = ["a", "b", "c"]
188+
let arrayA: [String] = ["a", "b", "c"]
189+
let arrayB: [String] = ["a", "b", "c"]
190190

191191
let shouldBe = [
192192
Diff(operation: .equal, array: ["a", "b", "c"])
193193
]
194194

195-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
195+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
196196

197197
XCTAssertEqual(shouldBe, isActually, "...")
198198
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
199199
}
200200

201201
func test005_simpleInsertion() {
202-
let a: [String] = ["a", "b", "c"]
203-
let b: [String] = ["a", "b", "1", "2", "3", "c"]
202+
let arrayA: [String] = ["a", "b", "c"]
203+
let arrayB: [String] = ["a", "b", "1", "2", "3", "c"]
204204

205205
let shouldBe: [Diff<String>] = [
206206
Diff(operation: .equal, array: ["a", "b"]),
207207
Diff(operation: .insert, array: ["1", "2", "3"]),
208208
Diff(operation: .equal, array: ["c"])
209209
]
210210

211-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
211+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
212212

213213
XCTAssertEqual(shouldBe, isActually, "...")
214214
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
215215
}
216216

217217
func test006_simpleDeletion() {
218-
let a: [String] = ["a", "b", "1", "2", "3", "c"]
219-
let b: [String] = ["a", "b", "c"]
218+
let arrayA: [String] = ["a", "b", "1", "2", "3", "c"]
219+
let arrayB: [String] = ["a", "b", "c"]
220220

221221
let shouldBe: [Diff<String>] = [
222222
Diff(operation: .equal, array: ["a", "b"]),
223223
Diff(operation: .delete, array: ["1", "2", "3"]),
224224
Diff(operation: .equal, array: ["c"])
225225
]
226226

227-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
227+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
228228

229229
XCTAssertEqual(shouldBe, isActually, "...")
230230
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
231231
}
232232

233233
func test007_twoInsertions() {
234-
let a: [String] = ["a", "b", "c"]
235-
let b: [String] = ["a", "1", "2", "3", "b", "4", "5", "6", "c"]
234+
let arrayA: [String] = ["a", "b", "c"]
235+
let arrayB: [String] = ["a", "1", "2", "3", "b", "4", "5", "6", "c"]
236236

237237
let shouldBe: [Diff<String>] = [
238238
Diff(operation: .equal, array: ["a"]),
@@ -242,15 +242,15 @@ class DiffTests: XCTestCase {
242242
Diff(operation: .equal, array: ["c"])
243243
]
244244

245-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
245+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
246246

247247
XCTAssertEqual(shouldBe, isActually, "...")
248248
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
249249
}
250250

251251
func test008_twoDeletions() {
252-
let a: [String] = ["a", "1", "2", "3", "b", "4", "5", "6", "c"]
253-
let b: [String] = ["a", "b", "c"]
252+
let arrayA: [String] = ["a", "1", "2", "3", "b", "4", "5", "6", "c"]
253+
let arrayB: [String] = ["a", "b", "c"]
254254

255255
let shouldBe: [Diff<String>] = [
256256
Diff(operation: .equal, array: ["a"]),
@@ -260,52 +260,52 @@ class DiffTests: XCTestCase {
260260
Diff(operation: .equal, array: ["c"])
261261
]
262262

263-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
263+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
264264

265265
XCTAssertEqual(shouldBe, isActually, "...")
266266
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
267267
}
268268

269269
func test009_simpleCase() {
270-
let a: [String] = ["a"]
271-
let b: [String] = ["b"]
270+
let arrayA: [String] = ["a"]
271+
let arrayB: [String] = ["b"]
272272

273273
let shouldBe = [
274274
Diff(operation: .delete, array: ["a"]),
275275
Diff(operation: .insert, array: ["b"])
276276
]
277277

278-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
278+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
279279

280280
XCTAssertEqual(shouldBe, isActually, "...")
281281
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
282282
}
283283

284284
func test010_prettySimpleCase() {
285-
let a: [String] = ["h", "e", "l", "g", "e"]
286-
let b: [String] = ["a", "n", "n", "a"]
285+
let arrayA: [String] = ["h", "e", "l", "g", "e"]
286+
let arrayB: [String] = ["a", "n", "n", "a"]
287287

288288
let shouldBe = [
289289
Diff(operation: .delete, array: ["h", "e", "l", "g", "e"]),
290290
Diff(operation: .insert, array: ["a", "n", "n", "a"])
291291
]
292292

293-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
293+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
294294

295295
XCTAssertEqual(shouldBe, isActually, "...")
296296
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
297297
}
298298

299299
func test011_prettySimpleCaseWithCharacters() {
300-
let a = Array(String("helge").characters)
301-
let b = Array(String("anna").characters)
300+
let arrayA = Array(String("helge").characters)
301+
let arrayB = Array(String("anna").characters)
302302

303303
let shouldBe = [
304304
Diff(operation: .delete, array: Array(String("helge").characters)),
305305
Diff(operation: .insert, array: Array(String("anna").characters))
306306
]
307307

308-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
308+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
309309

310310
XCTAssertEqual(shouldBe, isActually, "...")
311311
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
@@ -315,21 +315,21 @@ class DiffTests: XCTestCase {
315315
let aText = "dfhgvsrktzblzbasvfkugkbfgarzkulbdzsasrzlruoiunouizubsvtzkbnuhjmluinsbrtzstbusrxdzsdztkbnsrtztinlukdbzjrthsrtubulz"
316316
let bText = "dfhgvsrkblzbasvfkugkfzbjdbfgarzkulbdzsasrzlruoiunouizubruwsvtznuhjmluinsbrtzstbusrxdzbkzwksdztkbnsrtztinlukdbzjrthsrtubulz"
317317

318-
let a = Array(aText.characters)
319-
let b = Array(bText.characters)
318+
let arrayA = Array(aText.characters)
319+
let arrayB = Array(bText.characters)
320320

321-
let isActually = diffBetweenArrays(arrayA: a, arrayB: b)
321+
let isActually = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
322322

323323
self.thenDiffsShouldNotContainRepeatedDiffTypes(array: isActually)
324324
}
325325

326326
// this test is more a code coverage test. The debug description is not a vital part
327327
// so we only make sure it doesn't crash.
328328
func test013_debugDescription() {
329-
let a: [String] = ["h", "e", "l", "l", "o"]
330-
let b: [String] = ["w", "o", "r", "l", "d"]
329+
let arrayA: [String] = ["h", "e", "l", "l", "o"]
330+
let arrayB: [String] = ["w", "o", "r", "l", "d"]
331331

332-
let diffs = diffBetweenArrays(arrayA: a, arrayB: b)
332+
let diffs = diffBetweenArrays(arrayA: arrayA, arrayB: arrayB)
333333

334334
print("debug description: \(diffs)")
335335
}

0 commit comments

Comments
 (0)