Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 20d1b45

Browse files
Shashi456rxwei
authored andcommitted
Correct 'XCTAssertEqual(_:_:)' argument order. (#155)
Fixes #153.
1 parent 78e5a1d commit 20d1b45

File tree

3 files changed

+172
-171
lines changed

3 files changed

+172
-171
lines changed

Tests/TensorFlowTests/OperatorTests/BasicTests.swift

Lines changed: 95 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ final class BasicOperatorTests: XCTestCase {
4848
let array0D = element0D.array
4949

5050
/// Test shapes
51-
XCTAssertEqual([4, 5], array2D.shape)
52-
XCTAssertEqual([5], array1D.shape)
53-
XCTAssertEqual([], array0D.shape)
51+
XCTAssertEqual(array2D.shape, [4, 5])
52+
XCTAssertEqual(array1D.shape, [5])
53+
XCTAssertEqual(array0D.shape, [])
5454

5555
/// Test scalars
56-
XCTAssertEqual(Array(stride(from: 40.0, to: 60, by: 1)), array2D.scalars)
57-
XCTAssertEqual(Array(stride(from: 35.0, to: 40, by: 1)), array1D.scalars)
58-
XCTAssertEqual([43], array0D.scalars)
56+
XCTAssertEqual(array2D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
57+
XCTAssertEqual(array1D.scalars, Array(stride(from: 35.0, to: 40, by: 1)))
58+
XCTAssertEqual(array0D.scalars, [43])
5959
}
6060

6161
func testElementIndexingAssignment() {
@@ -76,14 +76,14 @@ final class BasicOperatorTests: XCTestCase {
7676
let array0D = element0D.array
7777

7878
/// Test shapes
79-
XCTAssertEqual([4, 5], array2D.shape)
80-
XCTAssertEqual([5], array1D.shape)
81-
XCTAssertEqual([], array0D.shape)
79+
XCTAssertEqual(array2D.shape, [4, 5])
80+
XCTAssertEqual(array1D.shape, [5])
81+
XCTAssertEqual(array0D.shape, [])
8282

8383
/// Test scalars
84-
XCTAssertEqual(Array(stride(from: 20.0, to: 40, by: 1)), array2D.scalars)
85-
XCTAssertEqual(Array(stride(from: 35.0, to: 40, by: 1)), array1D.scalars)
86-
XCTAssertEqual([23], array0D.scalars)
84+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 40, by: 1)))
85+
XCTAssertEqual(array1D.scalars, Array(stride(from: 35.0, to: 40, by: 1)))
86+
XCTAssertEqual(array0D.scalars, [23])
8787
}
8888

8989
func testNestedElementIndexing() {
@@ -99,12 +99,12 @@ final class BasicOperatorTests: XCTestCase {
9999
let array0D = element0D.array
100100

101101
/// Test shapes
102-
XCTAssertEqual([5], array1D.shape)
103-
XCTAssertEqual([], array0D.shape)
102+
XCTAssertEqual(array1D.shape, [5])
103+
XCTAssertEqual(array0D.shape, [])
104104

105105
/// Test scalars
106-
XCTAssertEqual(Array(stride(from: 35.0, to: 40, by: 1)), array1D.scalars)
107-
XCTAssertEqual([43], array0D.scalars)
106+
XCTAssertEqual(array1D.scalars, Array(stride(from: 35.0, to: 40, by: 1)))
107+
XCTAssertEqual(array0D.scalars, [43])
108108
}
109109

110110
func testSliceIndexing() {
@@ -123,14 +123,14 @@ final class BasicOperatorTests: XCTestCase {
123123
let array1D = slice1D.array
124124

125125
/// Test shapes
126-
XCTAssertEqual([1, 4, 5], array3D.shape)
127-
XCTAssertEqual([2, 5], array2D.shape)
128-
XCTAssertEqual([2], array1D.shape)
126+
XCTAssertEqual(array3D.shape, [1, 4, 5])
127+
XCTAssertEqual(array2D.shape, [2, 5])
128+
XCTAssertEqual(array1D.shape, [2])
129129

130130
/// Test scalars
131-
XCTAssertEqual(Array(stride(from: 40.0, to: 60, by: 1)), array3D.scalars)
132-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
133-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
131+
XCTAssertEqual(array3D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
132+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
133+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
134134
}
135135

136136
func testSliceIndexingAssignment() {
@@ -151,14 +151,14 @@ final class BasicOperatorTests: XCTestCase {
151151
let array1D = slice1D.array
152152

153153
/// Test shapes
154-
XCTAssertEqual([1, 4, 5], array3D.shape)
155-
XCTAssertEqual([2, 5], array2D.shape)
156-
XCTAssertEqual([2], array1D.shape)
154+
XCTAssertEqual(array3D.shape, [1, 4, 5])
155+
XCTAssertEqual(array2D.shape, [2, 5])
156+
XCTAssertEqual(array1D.shape, [2])
157157

158158
/// Test scalars
159-
XCTAssertEqual(Array(stride(from: 20.0, to: 40, by: 1)), array3D.scalars)
160-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
161-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
159+
XCTAssertEqual(array3D.scalars, Array(stride(from: 20.0, to: 40, by: 1)))
160+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
161+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
162162
}
163163

164164
func testEllipsisIndexing() {
@@ -179,14 +179,14 @@ final class BasicOperatorTests: XCTestCase {
179179
let array1D = slice1D.array
180180

181181
/// Test shapes
182-
XCTAssertEqual([1, 4, 5], array3D.shape)
183-
XCTAssertEqual([2, 5], array2D.shape)
184-
XCTAssertEqual([2], array1D.shape)
182+
XCTAssertEqual(array3D.shape, [1, 4, 5])
183+
XCTAssertEqual(array2D.shape, [2, 5])
184+
XCTAssertEqual(array1D.shape, [2])
185185

186186
/// Test scalars
187-
XCTAssertEqual(Array(stride(from: 20.0, to: 40, by: 1)), array3D.scalars)
188-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
189-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
187+
XCTAssertEqual(array3D.scalars, Array(stride(from: 20.0, to: 40, by: 1)))
188+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
189+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
190190
}
191191

192192
func testNewAxisIndexing() {
@@ -207,14 +207,14 @@ final class BasicOperatorTests: XCTestCase {
207207
let array1D = slice1D.array
208208

209209
/// Test shapes
210-
XCTAssertEqual([1, 1, 4, 5], array3D.shape)
211-
XCTAssertEqual([1, 2, 5], array2D.shape)
212-
XCTAssertEqual([1, 2, 1], array1D.shape)
210+
XCTAssertEqual(array3D.shape, [1, 1, 4, 5])
211+
XCTAssertEqual(array2D.shape, [1, 2, 5])
212+
XCTAssertEqual(array1D.shape, [1, 2, 1])
213213

214214
/// Test scalars
215-
XCTAssertEqual(Array(stride(from: 40.0, to: 60, by: 1)), array3D.scalars)
216-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
217-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
215+
XCTAssertEqual(array3D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
216+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
217+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
218218
}
219219

220220
func testSqueezeAxisIndexing() {
@@ -237,14 +237,14 @@ final class BasicOperatorTests: XCTestCase {
237237
let array1D = slice1D.array
238238

239239
/// Test shapes
240-
XCTAssertEqual([4, 5], array3D.shape)
241-
XCTAssertEqual([2, 5], array2D.shape)
242-
XCTAssertEqual([2], array1D.shape)
240+
XCTAssertEqual(array3D.shape, [4, 5])
241+
XCTAssertEqual(array2D.shape, [2, 5])
242+
XCTAssertEqual(array1D.shape, [2])
243243

244244
/// Test scalars
245-
XCTAssertEqual(Array(stride(from: 40.0, to: 60, by: 1)), array3D.scalars)
246-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
247-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
245+
XCTAssertEqual(array3D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
246+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
247+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
248248
}
249249

250250
func testStridedSliceIndexing() {
@@ -263,16 +263,17 @@ final class BasicOperatorTests: XCTestCase {
263263
let array1D = slice1D.array
264264

265265
/// Test shapes
266-
XCTAssertEqual([1, 4, 5], array3D.shape)
267-
XCTAssertEqual([2, 5], array2D.shape)
268-
XCTAssertEqual([2], array1D.shape)
266+
XCTAssertEqual(array3D.shape, [1, 4, 5])
267+
XCTAssertEqual(array2D.shape, [2, 5])
268+
XCTAssertEqual(array1D.shape, [2])
269269

270270
/// Test scalars
271-
XCTAssertEqual(Array(stride(from: 40.0, to: 60, by: 1)), array3D.scalars)
271+
XCTAssertEqual(array3D.scalars, Array(stride(from: 40.0, to: 60, by: 1)))
272272
XCTAssertEqual(
273+
array2D.scalars,
273274
Array(stride(from: 20.0, to: 25, by: 1)) +
274-
Array(stride(from: 30.0, to: 35, by: 1)), array2D.scalars)
275-
XCTAssertEqual(Array(stride(from: 1.0, to: 5, by: 2)), array1D.scalars)
275+
Array(stride(from: 30.0, to: 35, by: 1)))
276+
XCTAssertEqual(array1D.scalars, Array(stride(from: 1.0, to: 5, by: 2)))
276277
}
277278

278279
func testStridedSliceIndexingAssignment() {
@@ -291,28 +292,28 @@ final class BasicOperatorTests: XCTestCase {
291292
let array3D = slice3D.array
292293
let array2D = slice2D.array
293294
let array1D = slice1D.array
294-
295+
295296
/// Test shapes
296-
XCTAssertEqual([1, 4, 5], array3D.shape)
297-
XCTAssertEqual([2, 5], array2D.shape)
298-
XCTAssertEqual([2], array1D.shape)
297+
XCTAssertEqual(array3D.shape, [1, 4, 5])
298+
XCTAssertEqual(array2D.shape, [2, 5])
299+
XCTAssertEqual(array1D.shape, [2])
299300

300301
/// Test scalars
301-
XCTAssertEqual(
302-
Array(stride(from: 20.0, to: 30, by: 2)) +
303-
Array(stride(from: 45.0, to: 50, by: 1)) +
304-
Array(stride(from: 30.0, to: 40, by: 2)) +
305-
Array(stride(from: 55.0, to: 60, by: 1)), array3D.scalars)
306-
XCTAssertEqual(Array(stride(from: 20.0, to: 30, by: 1)), array2D.scalars)
307-
XCTAssertEqual(Array(stride(from: 3.0, to: 5, by: 1)), array1D.scalars)
302+
XCTAssertEqual(array3D.scalars,
303+
[Float](stride(from: 20.0, to: 30, by: 2)) +
304+
[Float](stride(from: 45.0, to: 50, by: 1)) +
305+
[Float](stride(from: 30.0, to: 40, by: 2)) +
306+
[Float](stride(from: 55.0, to: 60, by: 1)))
307+
XCTAssertEqual(array2D.scalars, Array(stride(from: 20.0, to: 30, by: 1)))
308+
XCTAssertEqual(array1D.scalars, Array(stride(from: 3.0, to: 5, by: 1)))
308309
}
309310

310311
func testWholeTensorSlicing() {
311312
let t: Tensor<Int32> = [[[1, 1, 1], [2, 2, 2]],
312313
[[3, 3, 3], [4, 4, 4]],
313314
[[5, 5, 5], [6, 6, 6]]]
314315
let slice2 = t.slice(lowerBounds: [1, 0, 0], upperBounds: [2, 1, 3])
315-
XCTAssertEqual(ShapedArray(shape: [1, 1, 3], scalars: [3, 3, 3]), slice2.array)
316+
XCTAssertEqual(slice2.array, ShapedArray(shape: [1, 1, 3], scalars: [3, 3, 3]))
316317
}
317318

318319
func testAdvancedIndexing() {
@@ -326,10 +327,10 @@ final class BasicOperatorTests: XCTestCase {
326327
let array2D = element2D.array
327328

328329
// Test shape
329-
XCTAssertEqual([2, 2], array2D.shape)
330+
XCTAssertEqual(array2D.shape, [2, 2])
330331

331332
// Test scalars
332-
XCTAssertEqual(Array([23.0, 24.0, 43.0, 44.0]), array2D.scalars)
333+
XCTAssertEqual(array2D.scalars, Array([23.0, 24.0, 43.0, 44.0]))
333334
}
334335

335336
func testConcatenation() {
@@ -340,11 +341,11 @@ final class BasicOperatorTests: XCTestCase {
340341
let concatenated = t1 ++ t2
341342
let concatenated0 = t1.concatenated(with: t2)
342343
let concatenated1 = t1.concatenated(with: t2, alongAxis: 1)
343-
XCTAssertEqual(ShapedArray(shape: [4, 3], scalars: Array(0..<12)), concatenated.array)
344-
XCTAssertEqual(ShapedArray(shape: [4, 3], scalars: Array(0..<12)), concatenated0.array)
344+
XCTAssertEqual(concatenated.array, ShapedArray(shape: [4, 3], scalars: Array(0..<12)))
345+
XCTAssertEqual(concatenated0.array, ShapedArray(shape: [4, 3], scalars: Array(0..<12)))
345346
XCTAssertEqual(
346-
ShapedArray(shape: [2, 6], scalars: [0, 1, 2, 6, 7, 8, 3, 4, 5, 9, 10, 11]),
347-
concatenated1.array)
347+
concatenated1.array,
348+
ShapedArray(shape: [2, 6], scalars: [0, 1, 2, 6, 7, 8, 3, 4, 5, 9, 10, 11]))
348349
}
349350

350351
func testVJPConcatenation() {
@@ -358,8 +359,8 @@ final class BasicOperatorTests: XCTestCase {
358359
return ((a1 * a) ++ (b1 * b)).sum()
359360
}
360361

361-
XCTAssertEqual(a1, grads.0)
362-
XCTAssertEqual(b1, grads.1)
362+
XCTAssertEqual(grads.0, a1)
363+
XCTAssertEqual(grads.1, b1)
363364
}
364365

365366
func testVJPConcatenationNegativeAxis() {
@@ -373,96 +374,96 @@ final class BasicOperatorTests: XCTestCase {
373374
return (a1 * a).concatenated(with: b1 * b, alongAxis: -1).sum()
374375
}
375376

376-
XCTAssertEqual(a1, grads.0)
377-
XCTAssertEqual(b1, grads.1)
377+
XCTAssertEqual(grads.0, a1)
378+
XCTAssertEqual(grads.1, b1)
378379
}
379380

380381
func testTranspose() {
381382
// 3 x 2 -> 2 x 3
382383
let xT = Tensor<Float>([[1, 2], [3, 4], [5, 6]]).transposed()
383384
let xTArray = xT.array
384-
XCTAssertEqual(2, xTArray.rank)
385-
XCTAssertEqual([2, 3], xTArray.shape)
386-
XCTAssertEqual([1, 3, 5, 2, 4, 6], xTArray.scalars)
385+
XCTAssertEqual(xTArray.rank, 2)
386+
XCTAssertEqual(xTArray.shape, [2, 3])
387+
XCTAssertEqual(xTArray.scalars, [1, 3, 5, 2, 4, 6])
387388
}
388389

389390
func testReshape() {
390391
// 2 x 3 -> 1 x 3 x 1 x 2 x 1
391392
let matrix = Tensor<Int32>([[0, 1, 2], [3, 4, 5]])
392393
let reshaped = matrix.reshaped(to: [1, 3, 1, 2, 1])
393394

394-
XCTAssertEqual([1, 3, 1, 2, 1], reshaped.shape)
395-
XCTAssertEqual(Array(0..<6), reshaped.scalars)
395+
XCTAssertEqual(reshaped.shape, [1, 3, 1, 2, 1])
396+
XCTAssertEqual(reshaped.scalars, Array(0..<6))
396397
}
397398

398399
func testFlatten() {
399400
// 2 x 3 -> 6
400401
let matrix = Tensor<Int32>([[0, 1, 2], [3, 4, 5]])
401402
let flattened = matrix.flattened()
402403

403-
XCTAssertEqual([6], flattened.shape)
404-
XCTAssertEqual(Array(0..<6), flattened.scalars)
404+
XCTAssertEqual(flattened.shape, [6])
405+
XCTAssertEqual(flattened.scalars, Array(0..<6))
405406
}
406407

407408
func testFlatten0D() {
408409
let scalar = Tensor<Float>(5)
409410
let flattened = scalar.flattened()
410-
XCTAssertEqual([1], flattened.shape)
411-
XCTAssertEqual([5], flattened.scalars)
411+
XCTAssertEqual(flattened.shape, [1])
412+
XCTAssertEqual(flattened.scalars, [5])
412413
}
413414

414415
func testReshapeToScalar() {
415416
// 1 x 1 -> scalar
416417
let z = Tensor<Float>([[10]]).reshaped(to: [])
417-
XCTAssertEqual([], z.shape)
418+
XCTAssertEqual(z.shape, [])
418419
}
419420

420421
func testReshapeTensor() {
421422
// 2 x 3 -> 1 x 3 x 1 x 2 x 1
422423
let x = Tensor<Float>(repeating: 0.0, shape: [2, 3])
423424
let y = Tensor<Float>(repeating: 0.0, shape: [1, 3, 1, 2, 1])
424425
let result = x.reshaped(like: y)
425-
XCTAssertEqual([1, 3, 1, 2, 1], result.shape)
426+
XCTAssertEqual(result.shape, [1, 3, 1, 2, 1])
426427
}
427428

428429
func testUnbroadcast1() {
429430
let x = Tensor<Float>(repeating: 1, shape: [2, 3, 4, 5])
430431
let y = Tensor<Float>(repeating: 1, shape: [4, 5])
431432
let z = x.unbroadcasted(like: y)
432-
XCTAssertEqual(ShapedArray<Float>(repeating: 6, shape: [4, 5]), z.array)
433+
XCTAssertEqual(z.array, ShapedArray<Float>(repeating: 6, shape: [4, 5]))
433434
}
434435

435436
func testUnbroadcast2() {
436437
let x = Tensor<Float>(repeating: 1, shape: [2, 3, 4, 5])
437438
let y = Tensor<Float>(repeating: 1, shape: [3, 1, 5])
438439
let z = x.unbroadcasted(like: y)
439-
XCTAssertEqual(ShapedArray<Float>(repeating: 8, shape: [3, 1, 5]), z.array)
440+
XCTAssertEqual(z.array, ShapedArray<Float>(repeating: 8, shape: [3, 1, 5]))
440441
}
441442

442443
func testSliceUpdate() {
443444
var t1 = Tensor<Float>([[1, 2, 3], [4, 5, 6]])
444445
t1[0] = Tensor(zeros: [3])
445-
XCTAssertEqual(ShapedArray(shape:[2, 3], scalars: [0, 0, 0, 4, 5, 6]), t1.array)
446+
XCTAssertEqual(t1.array, ShapedArray(shape:[2, 3], scalars: [0, 0, 0, 4, 5, 6]))
446447
var t2 = t1
447448
t2[0][2] = Tensor(3)
448-
XCTAssertEqual(ShapedArray(shape:[2, 3], scalars: [0, 0, 3, 4, 5, 6]), t2.array)
449+
XCTAssertEqual(t2.array, ShapedArray(shape:[2, 3], scalars: [0, 0, 3, 4, 5, 6]))
449450
var t3 = Tensor<Bool>([[true, true, true], [false, false, false]])
450451
t3[0][1] = Tensor(false)
451-
XCTAssertEqual(ShapedArray(
452-
shape:[2, 3], scalars: [true, false, true, false, false, false]), t3.array)
452+
XCTAssertEqual(t3.array, ShapedArray(
453+
shape:[2, 3], scalars: [true, false, true, false, false, false]))
453454
var t4 = Tensor<Bool>([[true, true, true], [false, false, false]])
454455
t4[0] = Tensor(repeating: false, shape: [3])
455-
XCTAssertEqual(ShapedArray(repeating: false, shape: [2, 3]), t4.array)
456+
XCTAssertEqual(t4.array, ShapedArray(repeating: false, shape: [2, 3]))
456457
}
457458

458459
func testBroadcastTensor() {
459460
// 1 -> 2 x 3 x 4
460461
let one = Tensor<Float>(1)
461462
var target = Tensor<Float>(repeating: 0.0, shape: [2, 3, 4])
462463
let broadcasted = one.broadcasted(like: target)
463-
XCTAssertEqual(Tensor(repeating: 1, shape: [2, 3, 4]), broadcasted)
464+
XCTAssertEqual(broadcasted, Tensor(repeating: 1, shape: [2, 3, 4]))
464465
target .= Tensor(repeating: 1, shape: [1, 3, 1])
465-
XCTAssertEqual(Tensor(repeating: 1, shape: [2, 3, 4]), target)
466+
XCTAssertEqual(target, Tensor(repeating: 1, shape: [2, 3, 4]))
466467
}
467468

468469
static var allTests = [

0 commit comments

Comments
 (0)