@@ -16,19 +16,19 @@ import SQLite3
1616class CustomAggregationTests : SQLiteTestCase {
1717 override func setUp( ) {
1818 super. setUp ( )
19- CreateUsersTable ( )
20- try ! InsertUser ( " Alice " , age: 30 , admin: true )
21- try ! InsertUser ( " Bob " , age: 25 , admin: true )
22- try ! InsertUser ( " Eve " , age: 28 , admin: false )
19+ createUsersTable ( )
20+ try ! insertUser ( " Alice " , age: 30 , admin: true )
21+ try ! insertUser ( " Bob " , age: 25 , admin: true )
22+ try ! insertUser ( " Eve " , age: 28 , admin: false )
2323 }
24-
24+
2525 func testUnsafeCustomSum( ) {
2626 let step = { ( bindings: [ Binding ? ] , state: UnsafeMutablePointer < Int64 > ) in
2727 if let v = bindings [ 0 ] as? Int64 {
2828 state. pointee += v
2929 }
3030 }
31-
31+
3232 let final = { ( state: UnsafeMutablePointer < Int64 > ) -> Binding ? in
3333 let v = state. pointee
3434 let p = UnsafeMutableBufferPointer ( start: state, count: 1 )
@@ -41,13 +41,13 @@ class CustomAggregationTests : SQLiteTestCase {
4141 return v. baseAddress!
4242 }
4343 let result = try ! db. prepare ( " SELECT mySUM1(age) AS s FROM users " )
44- let i = result. columnNames. index ( of: " s " ) !
44+ let i = result. columnNames. firstIndex ( of: " s " ) !
4545 for row in result {
4646 let value = row [ i] as? Int64
4747 XCTAssertEqual ( 83 , value)
4848 }
4949 }
50-
50+
5151 func testUnsafeCustomSumGrouping( ) {
5252 let step = { ( bindings: [ Binding ? ] , state: UnsafeMutablePointer < Int64 > ) in
5353 if let v = bindings [ 0 ] as? Int64 {
@@ -66,19 +66,19 @@ class CustomAggregationTests : SQLiteTestCase {
6666 return v. baseAddress!
6767 }
6868 let result = try ! db. prepare ( " SELECT mySUM2(age) AS s FROM users GROUP BY admin ORDER BY s " )
69- let i = result. columnNames. index ( of: " s " ) !
69+ let i = result. columnNames. firstIndex ( of: " s " ) !
7070 let values = result. compactMap { $0 [ i] as? Int64 }
7171 XCTAssertTrue ( values. elementsEqual ( [ 28 , 55 ] ) )
7272 }
73-
73+
7474 func testCustomSum( ) {
7575 let reduce : ( Int64 , [ Binding ? ] ) -> Int64 = { ( last, bindings) in
7676 let v = ( bindings [ 0 ] as? Int64 ) ?? 0
7777 return last + v
7878 }
7979 let _ = db. createAggregation ( " myReduceSUM1 " , initialValue: Int64 ( 2000 ) , reduce: reduce, result: { $0 } )
8080 let result = try ! db. prepare ( " SELECT myReduceSUM1(age) AS s FROM users " )
81- let i = result. columnNames. index ( of: " s " ) !
81+ let i = result. columnNames. firstIndex ( of: " s " ) !
8282 for row in result {
8383 let value = row [ i] as? Int64
8484 XCTAssertEqual ( 2083 , value)
@@ -92,11 +92,11 @@ class CustomAggregationTests : SQLiteTestCase {
9292 }
9393 let _ = db. createAggregation ( " myReduceSUM2 " , initialValue: Int64 ( 3000 ) , reduce: reduce, result: { $0 } )
9494 let result = try ! db. prepare ( " SELECT myReduceSUM2(age) AS s FROM users GROUP BY admin ORDER BY s " )
95- let i = result. columnNames. index ( of: " s " ) !
95+ let i = result. columnNames. firstIndex ( of: " s " ) !
9696 let values = result. compactMap { $0 [ i] as? Int64 }
9797 XCTAssertTrue ( values. elementsEqual ( [ 3028 , 3055 ] ) )
9898 }
99-
99+
100100 func testCustomStringAgg( ) {
101101 let initial = String ( repeating: " " , count: 64 )
102102 let reduce : ( String , [ Binding ? ] ) -> String = { ( last, bindings) in
@@ -105,13 +105,13 @@ class CustomAggregationTests : SQLiteTestCase {
105105 }
106106 let _ = db. createAggregation ( " myReduceSUM3 " , initialValue: initial, reduce: reduce, result: { $0 } )
107107 let result = try ! db. prepare ( " SELECT myReduceSUM3(email) AS s FROM users " )
108- let i = result. columnNames. index ( of: " s " ) !
108+ let i = result. columnNames. firstIndex ( of: " s " ) !
109109 for row in result {
110110 let value = row [ i] as? String
111111 XCTAssertEqual ( " \( initial) Alice@example.comBob@example.comEve@example.com " , value)
112112 }
113113 }
114-
114+
115115 func testCustomObjectSum( ) {
116116 {
117117 let initial = TestObject ( value: 1000 )
@@ -126,7 +126,7 @@ class CustomAggregationTests : SQLiteTestCase {
126126 {
127127 XCTAssertEqual ( TestObject . inits, 1 )
128128 let result = try ! db. prepare ( " SELECT myReduceSUMX(age) AS s FROM users " )
129- let i = result. columnNames. index ( of: " s " ) !
129+ let i = result. columnNames. firstIndex ( of: " s " ) !
130130 for row in result {
131131 let value = row [ i] as? Int64
132132 XCTAssertEqual ( 1083 , value)
@@ -143,7 +143,7 @@ class CustomAggregationTests : SQLiteTestCase {
143143class TestObject {
144144 static var inits = 0
145145 static var deinits = 0
146-
146+
147147 var value : Int64
148148 init ( value: Int64 ) {
149149 self . value = value
0 commit comments