1- // Copyright 2024 Apple Inc. and the Swift Homomorphic Encryption project authors
1+ // Copyright 2024-2025 Apple Inc. and the Swift Homomorphic Encryption project authors
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
1313// limitations under the License.
1414
1515@testable import HomomorphicEncryption
16- import XCTest
16+ import Testing
1717
18- class Array2dTests : XCTestCase {
18+ @Suite
19+ struct Array2dTests {
20+ @Test
1921 func testInit( ) {
2022 func runTest< T: FixedWidthInteger & Sendable > ( _: T . Type ) {
2123 let data = [ T] ( 1 ... 6 )
2224 let array = Array2d ( data: data, rowCount: 3 , columnCount: 2 )
2325
2426 let data2d : [ [ T ] ] = [ [ 1 , 2 ] , [ 3 , 4 ] , [ 5 , 6 ] ]
25- XCTAssertEqual ( array, Array2d ( data: data2d) )
27+ #expect ( array == Array2d ( data: data2d) )
2628
27- XCTAssert ( Array2d < T > ( data: [ ] ) . shape == ( rowCount: 0 , columnCount: 0 ) )
28- XCTAssert ( Array2d < T > ( data: [ [ ] ] ) . shape == ( rowCount: 0 , columnCount: 0 ) )
29+ #expect ( Array2d< T> ( data: [ ] ) . shape == ( rowCount: 0 , columnCount: 0 ) )
30+ #expect ( Array2d< T> ( data: [ [ ] ] ) . shape == ( rowCount: 0 , columnCount: 0 ) )
2931 }
3032
3133 runTest ( Int . self)
@@ -36,7 +38,8 @@ class Array2dTests: XCTestCase {
3638 runTest ( UInt128 . self)
3739 }
3840
39- func testZeroAndZeroize( ) {
41+ @Test
42+ func zeroAndZeroize( ) {
4043 func runTest< T: FixedWidthInteger & Sendable > ( _: T . Type ) {
4144 let data = [ T] ( 1 ... 16 )
4245 var array = Array2d ( data: data, rowCount: 2 , columnCount: 8 )
@@ -46,8 +49,8 @@ class Array2dTests: XCTestCase {
4649 data: [ T] ( repeating: 0 , count: 16 ) ,
4750 rowCount: 2 ,
4851 columnCount: 8 )
49- XCTAssertEqual ( array, zero)
50- XCTAssertEqual ( array, Array2d . zero ( rowCount: 2 , columnCount: 8 ) )
52+ #expect ( array == zero)
53+ #expect ( array == Array2d . zero ( rowCount: 2 , columnCount: 8 ) )
5154 }
5255 runTest ( Int . self)
5356 runTest ( Int32 . self)
@@ -57,92 +60,100 @@ class Array2dTests: XCTestCase {
5760 runTest ( UInt128 . self)
5861 }
5962
60- func testShape( ) {
63+ @Test
64+ func shape( ) {
6165 let data = [ Int] ( 0 ..< 16 )
6266 let array = Array2d ( data: data, rowCount: 2 , columnCount: 8 )
63- XCTAssert ( array. shape == ( rowCount: 2 , columnCount: 8 ) )
67+ #expect ( array. shape == ( rowCount: 2 , columnCount: 8 ) )
6468 }
6569
66- func testIndices4x4( ) {
70+ @Test
71+ func indices4x4( ) {
6772 let data = [ Int] ( 0 ..< 16 )
6873 let array = Array2d ( data: data, rowCount: 4 , columnCount: 4 )
6974
70- XCTAssertEqual ( array. collectValues ( indices: array. rowIndices ( row: 0 ) ) , [ 0 , 1 , 2 , 3 ] )
71- XCTAssertEqual ( array. collectValues ( indices: array. columnIndices ( column: 0 ) ) , [ 0 , 4 , 8 , 12 ] )
75+ #expect ( array. collectValues ( indices: array. rowIndices ( row: 0 ) ) == [ 0 , 1 , 2 , 3 ] )
76+ #expect ( array. collectValues ( indices: array. columnIndices ( column: 0 ) ) == [ 0 , 4 , 8 , 12 ] )
7277 }
7378
74- func testIndices2x8( ) {
79+ @Test
80+ func indices2x8( ) {
7581 let data = [ Int] ( 0 ..< 16 )
7682 let array = Array2d ( data: data, rowCount: 2 , columnCount: 8 )
7783
78- XCTAssertEqual ( array. collectValues ( indices: array. rowIndices ( row: 0 ) ) , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] )
79- XCTAssertEqual ( array. collectValues ( indices: array. columnIndices ( column: 0 ) ) , [ 0 , 8 ] )
80- XCTAssertEqual ( array. collectValues ( indices: array. columnIndices ( column: 7 ) ) , [ 7 , 15 ] )
84+ #expect ( array. collectValues ( indices: array. rowIndices ( row: 0 ) ) == [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] )
85+ #expect ( array. collectValues ( indices: array. columnIndices ( column: 0 ) ) == [ 0 , 8 ] )
86+ #expect ( array. collectValues ( indices: array. columnIndices ( column: 7 ) ) == [ 7 , 15 ] )
8187 }
8288
83- func testTransposed( ) {
89+ @Test
90+ func transposed( ) {
8491 let data = [ Int] ( 0 ..< 16 )
8592 let array = Array2d ( data: data, rowCount: 2 , columnCount: 8 )
8693 let transposed = array. transposed ( )
8794
88- XCTAssert ( array. shape == ( 2 , 8 ) )
89- XCTAssert ( transposed. shape == ( 8 , 2 ) )
95+ #expect ( array. shape == ( 2 , 8 ) )
96+ #expect ( transposed. shape == ( 8 , 2 ) )
9097
91- XCTAssertEqual ( transposed. collectValues ( indices: transposed. rowIndices ( row: 0 ) ) , [ 0 , 8 ] )
92- XCTAssertEqual ( transposed. collectValues ( indices: transposed. rowIndices ( row: 7 ) ) , [ 7 , 15 ] )
93- XCTAssertEqual ( transposed. collectValues ( indices: transposed. columnIndices ( column: 0 ) ) , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] )
94- XCTAssertEqual (
95- transposed. collectValues ( indices: transposed. columnIndices ( column: 1 ) ) ,
96- [ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] )
98+ #expect ( transposed. collectValues ( indices: transposed. rowIndices ( row: 0 ) ) == [ 0 , 8 ] )
99+ #expect ( transposed. collectValues ( indices: transposed. rowIndices ( row: 7 ) ) == [ 7 , 15 ] )
100+ #expect ( transposed. collectValues ( indices: transposed. columnIndices ( column: 0 ) ) == [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] )
101+ #expect (
102+ transposed. collectValues ( indices: transposed. columnIndices ( column: 1 ) ) ==
103+ [ 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] )
97104 }
98105
99- func testResizeColumn( ) {
106+ @Test
107+ func resizeColumn( ) {
100108 var array = Array2d ( data: [ Int] ( 0 ..< 6 ) , rowCount: 2 , columnCount: 3 )
101109
102110 array. resizeColumn ( newColumnCount: 5 , defaultValue: 99 )
103111 let newData : [ Int ] = [ 0 , 1 , 2 , 99 , 99 , 3 , 4 , 5 , 99 , 99 ]
104- XCTAssertEqual ( array, Array2d ( data: newData, rowCount: 2 , columnCount: 5 ) )
112+ #expect ( array == Array2d ( data: newData, rowCount: 2 , columnCount: 5 ) )
105113
106114 array. resizeColumn ( newColumnCount: 3 )
107- XCTAssertEqual ( array, Array2d ( data: [ Int] ( 0 ..< 6 ) , rowCount: 2 , columnCount: 3 ) )
115+ #expect ( array == Array2d ( data: [ Int] ( 0 ..< 6 ) , rowCount: 2 , columnCount: 3 ) )
108116 }
109117
110- func testRemoveLastRows( ) {
118+ @Test
119+ func removeLastRows( ) {
111120 let data = [ Int] ( 0 ..< 32 )
112121 var array = Array2d ( data: data, rowCount: 4 , columnCount: 8 )
113122
114123 array. removeLastRows ( 2 )
115- XCTAssertEqual ( array, Array2d ( data: [ Int] ( 0 ..< 16 ) , rowCount: 2 , columnCount: 8 ) )
124+ #expect ( array == Array2d ( data: [ Int] ( 0 ..< 16 ) , rowCount: 2 , columnCount: 8 ) )
116125
117126 array. removeLastRows ( 1 )
118- XCTAssertEqual ( array, Array2d ( data: [ Int] ( 0 ..< 8 ) , rowCount: 1 , columnCount: 8 ) )
127+ #expect ( array == Array2d ( data: [ Int] ( 0 ..< 8 ) , rowCount: 1 , columnCount: 8 ) )
119128
120129 array. removeLastRows ( 1 )
121- XCTAssertEqual ( array, Array2d ( data: [ ] , rowCount: 0 , columnCount: 8 ) )
130+ #expect ( array == Array2d ( data: [ ] , rowCount: 0 , columnCount: 8 ) )
122131 }
123132
124- func testAppendRows( ) {
133+ @Test
134+ func appendRows( ) {
125135 let data = [ Int] ( 0 ..< 32 )
126136 var array = Array2d ( data: data, rowCount: 4 , columnCount: 8 )
127137 array. append ( rows: [ ] )
128- XCTAssertEqual ( array, Array2d ( data: data, rowCount: 4 , columnCount: 8 ) )
138+ #expect ( array == Array2d ( data: data, rowCount: 4 , columnCount: 8 ) )
129139
130140 array. append ( rows: [ 32 , 33 , 34 , 35 , 36 , 37 , 38 , 39 ] )
131- XCTAssertEqual ( array, Array2d ( data: [ Int] ( 0 ..< 40 ) , rowCount: 5 , columnCount: 8 ) )
141+ #expect ( array == Array2d ( data: [ Int] ( 0 ..< 40 ) , rowCount: 5 , columnCount: 8 ) )
132142
133143 array. append ( rows: Array ( 40 ..< 56 ) )
134- XCTAssertEqual ( array, Array2d ( data: [ Int] ( 0 ..< 56 ) , rowCount: 7 , columnCount: 8 ) )
144+ #expect ( array == Array2d ( data: [ Int] ( 0 ..< 56 ) , rowCount: 7 , columnCount: 8 ) )
135145 }
136146
137- func testMap( ) {
147+ @Test
148+ func map( ) {
138149 let data = [ Int] ( 0 ..< 32 )
139150 let array = Array2d ( data: data, rowCount: 4 , columnCount: 8 )
140151
141152 let arrayPlus1 = array. map { UInt ( $0) + 1 }
142153 let expected = Array2d ( data: [ UInt] ( 1 ..< 33 ) , rowCount: 4 , columnCount: 8 )
143- XCTAssertEqual ( arrayPlus1, expected)
154+ #expect ( arrayPlus1 == expected)
144155
145156 let roundtripArray = arrayPlus1. map { Int ( $0 - 1 ) }
146- XCTAssertEqual ( roundtripArray, array)
157+ #expect ( roundtripArray == array)
147158 }
148159}
0 commit comments