@@ -160,6 +160,23 @@ class ComplexArithmeticTests: XCTestCase {
160160 testMultiplication ( Complex < Float80 > ( real: 3.0 , imaginary: 4.0 ) , 2.0 )
161161 }
162162
163+ func testComponentwiseMultiplication( ) {
164+ testComponentwiseMultiplication ( Complex < Int8 > ( real: 3 , imaginary: 4 ) , Complex < Int8 > ( real: 1 , imaginary: 2 ) )
165+ testComponentwiseMultiplication ( Complex < Int16 > ( real: 3 , imaginary: 4 ) , Complex < Int16 > ( real: 1 , imaginary: 2 ) )
166+ testComponentwiseMultiplication ( Complex < Int32 > ( real: 3 , imaginary: 4 ) , Complex < Int32 > ( real: 1 , imaginary: 2 ) )
167+ testComponentwiseMultiplication ( Complex < Int64 > ( real: 3 , imaginary: 4 ) , Complex < Int64 > ( real: 1 , imaginary: 2 ) )
168+ testComponentwiseMultiplication ( Complex < Int > ( real: 3 , imaginary: 4 ) , Complex < Int > ( real: 1 , imaginary: 2 ) )
169+ testComponentwiseMultiplication ( Complex < UInt8 > ( real: 3 , imaginary: 4 ) , Complex < UInt8 > ( real: 1 , imaginary: 2 ) )
170+ testComponentwiseMultiplication ( Complex < UInt16 > ( real: 3 , imaginary: 4 ) , Complex < UInt16 > ( real: 1 , imaginary: 2 ) )
171+ testComponentwiseMultiplication ( Complex < UInt32 > ( real: 3 , imaginary: 4 ) , Complex < UInt32 > ( real: 1 , imaginary: 2 ) )
172+ testComponentwiseMultiplication ( Complex < UInt64 > ( real: 3 , imaginary: 4 ) , Complex < UInt64 > ( real: 1 , imaginary: 2 ) )
173+ testComponentwiseMultiplication ( Complex < UInt > ( real: 3 , imaginary: 4 ) , Complex < UInt > ( real: 1 , imaginary: 2 ) )
174+ testComponentwiseMultiplication ( Complex < Half > ( real: 3.0 , imaginary: 4.0 ) , Complex < Half > ( real: 1.0 , imaginary: 2.0 ) )
175+ testComponentwiseMultiplication ( Complex < Float > ( real: 3.0 , imaginary: 4.0 ) , Complex < Float > ( real: 1.0 , imaginary: 2.0 ) )
176+ testComponentwiseMultiplication ( Complex < Double > ( real: 3.0 , imaginary: 4.0 ) , Complex < Double > ( real: 1.0 , imaginary: 2.0 ) )
177+ testComponentwiseMultiplication ( Complex < Float80 > ( real: 3.0 , imaginary: 4.0 ) , Complex < Float80 > ( real: 1.0 , imaginary: 2.0 ) )
178+ }
179+
163180 func testDivision( ) {
164181 testDivision ( Complex < Int8 > ( real: 3 , imaginary: 4 ) , Complex < Int8 > ( real: 2 , imaginary: 1 ) , Complex < Int8 > ( real: 2 , imaginary: 1 ) )
165182 testDivision ( Complex < Int16 > ( real: 3 , imaginary: 4 ) , Complex < Int16 > ( real: 2 , imaginary: 1 ) , Complex < Int16 > ( real: 2 , imaginary: 1 ) )
@@ -192,10 +209,28 @@ class ComplexArithmeticTests: XCTestCase {
192209 testDivision ( Complex < Float80 > ( real: 3.0 , imaginary: 4.0 ) , 2.0 )
193210 }
194211
212+ func testComponentwiseDivision( ) {
213+ testComponentwiseDivision ( Complex < Int8 > ( real: 3 , imaginary: 4 ) , Complex < Int8 > ( real: 1 , imaginary: 2 ) )
214+ testComponentwiseDivision ( Complex < Int16 > ( real: 3 , imaginary: 4 ) , Complex < Int16 > ( real: 1 , imaginary: 2 ) )
215+ testComponentwiseDivision ( Complex < Int32 > ( real: 3 , imaginary: 4 ) , Complex < Int32 > ( real: 1 , imaginary: 2 ) )
216+ testComponentwiseDivision ( Complex < Int64 > ( real: 3 , imaginary: 4 ) , Complex < Int64 > ( real: 1 , imaginary: 2 ) )
217+ testComponentwiseDivision ( Complex < Int > ( real: 3 , imaginary: 4 ) , Complex < Int > ( real: 1 , imaginary: 2 ) )
218+ testComponentwiseDivision ( Complex < UInt8 > ( real: 3 , imaginary: 4 ) , Complex < UInt8 > ( real: 1 , imaginary: 2 ) )
219+ testComponentwiseDivision ( Complex < UInt16 > ( real: 3 , imaginary: 4 ) , Complex < UInt16 > ( real: 1 , imaginary: 2 ) )
220+ testComponentwiseDivision ( Complex < UInt32 > ( real: 3 , imaginary: 4 ) , Complex < UInt32 > ( real: 1 , imaginary: 2 ) )
221+ testComponentwiseDivision ( Complex < UInt64 > ( real: 3 , imaginary: 4 ) , Complex < UInt64 > ( real: 1 , imaginary: 2 ) )
222+ testComponentwiseDivision ( Complex < UInt > ( real: 3 , imaginary: 4 ) , Complex < UInt > ( real: 1 , imaginary: 2 ) )
223+ testComponentwiseDivision ( Complex < Half > ( real: 3.0 , imaginary: 4.0 ) , Complex < Half > ( real: 1.0 , imaginary: 2.0 ) )
224+ testComponentwiseDivision ( Complex < Float > ( real: 3.0 , imaginary: 4.0 ) , Complex < Float > ( real: 1.0 , imaginary: 2.0 ) )
225+ testComponentwiseDivision ( Complex < Double > ( real: 3.0 , imaginary: 4.0 ) , Complex < Double > ( real: 1.0 , imaginary: 2.0 ) )
226+ testComponentwiseDivision ( Complex < Float80 > ( real: 3.0 , imaginary: 4.0 ) , Complex < Float80 > ( real: 1.0 , imaginary: 2.0 ) )
227+ }
228+
195229 // MARK: Private Methods
196230
197231 private func testAdditionWithZero< Scalar> ( _ complex: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
198232 XCTAssertEqual ( complex, complex + . zero, file: file, line: line)
233+ XCTAssertEqual ( complex, complex .+ . zero, file: file, line: line)
199234 XCTAssertEqual ( complex, complex + Scalar. zero, file: file, line: line)
200235 XCTAssertEqual ( complex, Scalar . zero + complex, file: file, line: line)
201236
@@ -204,6 +239,7 @@ class ComplexArithmeticTests: XCTestCase {
204239 XCTAssertEqual ( result, complex, file: file, line: line)
205240
206241 result = complex
242+ result .+= . zero
207243 XCTAssertEqual ( result, complex, file: file, line: line)
208244
209245 result = complex
@@ -213,26 +249,36 @@ class ComplexArithmeticTests: XCTestCase {
213249
214250 private func testSubtractionWithZero< Scalar> ( _ complex: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
215251 XCTAssertEqual ( complex, complex - . zero, file: file, line: line)
252+ XCTAssertEqual ( complex, complex .- . zero, file: file, line: line)
216253 XCTAssertEqual ( complex, complex - Scalar. zero, file: file, line: line)
217254
218255 var result = complex
219256 result -= . zero
220257 XCTAssertEqual ( result, complex, file: file, line: line)
221258
259+ result = complex
260+ result .-= . zero
261+ XCTAssertEqual ( result, complex, file: file, line: line)
262+
222263 result = complex
223264 result -= Scalar . zero
224265 XCTAssertEqual ( result, complex, file: file, line: line)
225266 }
226267
227268 private func testMultiplicationWithZero< Scalar> ( _ complex: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
228269 XCTAssertEqual ( . zero, complex * . zero, file: file, line: line)
270+ XCTAssertEqual ( . zero, complex .* . zero, file: file, line: line)
229271 XCTAssertEqual ( . zero, complex * Scalar. zero, file: file, line: line)
230272 XCTAssertEqual ( . zero, Scalar . zero * complex, file: file, line: line)
231273
232274 var result = complex
233275 result *= . zero
234276 XCTAssertEqual ( result, . zero, file: file, line: line)
235277
278+ result = complex
279+ result .*= . zero
280+ XCTAssertEqual ( result, . zero, file: file, line: line)
281+
236282 result = complex
237283 result *= Scalar . zero
238284 XCTAssertEqual ( result, . zero, file: file, line: line)
@@ -241,6 +287,8 @@ class ComplexArithmeticTests: XCTestCase {
241287 private func testAddition< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , _ result: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
242288 XCTAssertEqual ( lhs + rhs, result, file: file, line: line)
243289 XCTAssertEqual ( rhs + lhs, result, file: file, line: line)
290+ XCTAssertEqual ( lhs .+ rhs, result, file: file, line: line)
291+ XCTAssertEqual ( rhs .+ lhs, result, file: file, line: line)
244292
245293 var complex = lhs
246294 complex += rhs
@@ -249,6 +297,14 @@ class ComplexArithmeticTests: XCTestCase {
249297 complex = rhs
250298 complex += lhs
251299 XCTAssertEqual ( complex, result, file: file, line: line)
300+
301+ complex = lhs
302+ complex .+= rhs
303+ XCTAssertEqual ( complex, result, file: file, line: line)
304+
305+ complex = rhs
306+ complex .+= lhs
307+ XCTAssertEqual ( complex, result, file: file, line: line)
252308 }
253309
254310 private func testAddition< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Scalar , _ result: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
@@ -266,11 +322,17 @@ class ComplexArithmeticTests: XCTestCase {
266322 var complex = lhs
267323 complex -= rhs
268324 XCTAssertEqual ( complex, result, file: file, line: line)
325+
326+ complex = lhs
327+ complex .-= rhs
328+ XCTAssertEqual ( complex, result, file: file, line: line)
269329 }
270330
271331 private func testSubtraction< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , _ result: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) where Scalar: SignedNumeric {
272332 XCTAssertEqual ( lhs - rhs, result, file: file, line: line)
273333 XCTAssertEqual ( rhs - lhs, - result, file: file, line: line)
334+ XCTAssertEqual ( lhs .- rhs, result, file: file, line: line)
335+ XCTAssertEqual ( rhs .- lhs, - result, file: file, line: line)
274336
275337 var complex = lhs
276338 complex -= rhs
@@ -279,6 +341,14 @@ class ComplexArithmeticTests: XCTestCase {
279341 complex = rhs
280342 complex -= lhs
281343 XCTAssertEqual ( complex, - result, file: file, line: line)
344+
345+ complex = lhs
346+ complex .-= rhs
347+ XCTAssertEqual ( complex, result, file: file, line: line)
348+
349+ complex = rhs
350+ complex .-= lhs
351+ XCTAssertEqual ( complex, - result, file: file, line: line)
282352 }
283353
284354 private func testSubtraction< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Scalar , _ result: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
@@ -321,6 +391,17 @@ class ComplexArithmeticTests: XCTestCase {
321391 XCTAssertEqual ( complex, result, file: file, line: line)
322392 }
323393
394+ private func testComponentwiseMultiplication< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) {
395+ var result = lhs .* rhs
396+ XCTAssertEqual ( result. real, lhs. real * rhs. real, file: file, line: line)
397+ XCTAssertEqual ( result. imaginary, lhs. imaginary * rhs. imaginary, file: file, line: line)
398+
399+ result = lhs
400+ result .*= rhs
401+ XCTAssertEqual ( result. real, lhs. real * rhs. real, file: file, line: line)
402+ XCTAssertEqual ( result. imaginary, lhs. imaginary * rhs. imaginary, file: file, line: line)
403+ }
404+
324405 private func testDivision< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , _ result: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) where Scalar: BinaryInteger {
325406 XCTAssertEqual ( lhs / rhs, result, file: file, line: line)
326407
@@ -362,4 +443,26 @@ class ComplexArithmeticTests: XCTestCase {
362443 complex /= rhs
363444 XCTAssertEqual ( complex, Complex ( real: lhs. real / rhs, imaginary: lhs. imaginary / rhs) , file: file, line: line)
364445 }
446+
447+ private func testComponentwiseDivision< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) where Scalar: BinaryInteger {
448+ var result = lhs ./ rhs
449+ XCTAssertEqual ( result. real, lhs. real / rhs. real, file: file, line: line)
450+ XCTAssertEqual ( result. imaginary, lhs. imaginary / rhs. imaginary, file: file, line: line)
451+
452+ result = lhs
453+ result ./= rhs
454+ XCTAssertEqual ( result. real, lhs. real / rhs. real, file: file, line: line)
455+ XCTAssertEqual ( result. imaginary, lhs. imaginary / rhs. imaginary, file: file, line: line)
456+ }
457+
458+ private func testComponentwiseDivision< Scalar> ( _ lhs: Complex < Scalar > , _ rhs: Complex < Scalar > , file: StaticString = #file, line: UInt = #line) where Scalar: FloatingPoint {
459+ var result = lhs ./ rhs
460+ XCTAssertEqual ( result. real, lhs. real / rhs. real, file: file, line: line)
461+ XCTAssertEqual ( result. imaginary, lhs. imaginary / rhs. imaginary, file: file, line: line)
462+
463+ result = lhs
464+ result ./= rhs
465+ XCTAssertEqual ( result. real, lhs. real / rhs. real, file: file, line: line)
466+ XCTAssertEqual ( result. imaginary, lhs. imaginary / rhs. imaginary, file: file, line: line)
467+ }
365468}
0 commit comments