diff --git a/Tests/SurgeTests/ArithmeticTests.swift b/Tests/SurgeTests/ArithmeticTests.swift index 6297b2c..f170aa4 100644 --- a/Tests/SurgeTests/ArithmeticTests.swift +++ b/Tests/SurgeTests/ArithmeticTests.swift @@ -27,6 +27,8 @@ import XCTest class ArithmeticTests: XCTestCase { let n = 100_000 + // MARK: - Addition + func test_add_array_array_float() { typealias Scalar = Float @@ -59,6 +61,12 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Addition: In Place + + // FIXME: missing tests + + // MARK: - Subtraction + func test_sub_array_array_float() { typealias Scalar = Float @@ -91,6 +99,12 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Subtraction: In Place + + // FIXME: missing tests + + // MARK: - Multiplication + func test_mul_array_array_float() { typealias Scalar = Float @@ -123,6 +137,12 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Multiplication: In Place + + // FIXME: missing tests + + // MARK: - Division + func test_div_array_array_float() { typealias Scalar = Float @@ -155,6 +175,12 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Division: In Place + + // FIXME: missing tests + + // MARK: - Modulo + func test_mod_array_array_float() { typealias Scalar = Float @@ -187,6 +213,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Remainder + func test_remainder_array_array_float() { typealias Scalar = Float @@ -219,6 +247,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Square Root + func test_sqrt_array_array_float() { typealias Scalar = Float @@ -249,6 +279,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Dot Product + func test_dot_array_array_float() { typealias Scalar = Float @@ -285,6 +317,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Summation + func test_sum() { let values = (0...n).map { _ in Double(arc4random()) / Double(UInt32.max) } var actual = 0.0 @@ -315,6 +349,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Square Root + func test_sqrt() { let values = (0...n).map { _ in Double(arc4random()) } measureAndValidateMappedFunctionWithAccuracy(source: values, member: sqrt, mapped: sqrt, accuracy: 1e-4) @@ -325,6 +361,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(sqrt(values), []) } + // MARK: - Distance + func test_dist_array_array_double() { typealias Scalar = Double @@ -357,6 +395,8 @@ class ArithmeticTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-6) } + // MARK: - Distance Squared + func test_distsq_array_array_double() { typealias Scalar = Double diff --git a/Tests/SurgeTests/MatrixTests.swift b/Tests/SurgeTests/MatrixTests.swift index cb944c0..150fc65 100644 --- a/Tests/SurgeTests/MatrixTests.swift +++ b/Tests/SurgeTests/MatrixTests.swift @@ -200,6 +200,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual_3x3, expected_3x3) } + // MARK: - Subscript + func test_subscript_row_get() { typealias Scalar = Double @@ -266,6 +268,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(matrix, expected) } + // MARK: - Addition + func test_add_matrix_matrix_float() { typealias Scalar = Float @@ -304,6 +308,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected) } + // MARK: - Subtraction + func test_sub_matrix_matrix_float() { typealias Scalar = Float @@ -379,6 +385,7 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected) } + // MARK: - Multiplication func test_mul_matrix_matrix_float() { typealias Scalar = Float @@ -460,6 +467,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected) } + // MARK: - Division + func test_div_matrix_scalar_float() { typealias Scalar = Float @@ -542,6 +551,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Power + func test_pow_matrix_scalar_float() { typealias Scalar = Float @@ -582,6 +593,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Exponential + func test_exp_matrix_float() { typealias Scalar = Float @@ -618,6 +631,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Summation + func test_sum_matrix_rows_double() { typealias Scalar = Double @@ -684,6 +699,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-5) } + // MARK: - Inverse + func test_inv_matrix_double() { typealias Scalar = Double @@ -718,6 +735,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-6) } + // MARK: - Transpose + func test_tranpose_matrix_double() { typealias Scalar = Double @@ -754,6 +773,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(actual, expected) } + // MARK: - Determinant + func test_det_matrix_double() { typealias Scalar = Double @@ -798,6 +819,8 @@ class MatrixTests: XCTestCase { XCTAssertEqual(result.columns, 0) } + // MARK: - Eigen-Decomposition + func complexVectorMatches(_ a: [(T, T)], _ b: [(T, T)], accuracy: T) -> Bool { guard a.count == b.count else { return false diff --git a/Tests/SurgeTests/VectorTests.swift b/Tests/SurgeTests/VectorTests.swift index 951ac98..eede889 100644 --- a/Tests/SurgeTests/VectorTests.swift +++ b/Tests/SurgeTests/VectorTests.swift @@ -24,11 +24,15 @@ import XCTest // swiftlint:disable nesting type_body_length class VectorTests: XCTestCase { + // MARK: - Initialization + func test_init() { let v = Vector([1.0, 2.0]) XCTAssertEqual(v.scalars, [1.0, 2.0]) } + // MARK: - Subscript + func test_subscript() { typealias Scalar = Double @@ -39,6 +43,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(vector[9], 10) } + // MARK: - Addition + func test_add_vector_vector_double() { typealias Scalar = Double @@ -97,6 +103,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Addition: In Place + func test_add_in_place_vector_vector_double() { typealias Scalar = Double @@ -175,6 +183,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Subtraction + func test_sub_vector_vector_double() { typealias Scalar = Double @@ -233,6 +243,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Subtraction: In Place + func test_sub_in_place_vector_vector_double() { typealias Scalar = Double @@ -340,6 +352,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Multiplication + func test_mul_vector_scalar_double() { typealias Scalar = Double @@ -410,6 +424,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected) } + // MARK: - Multiplication: In Place + func test_mul_in_place_vector_scalar_double() { typealias Scalar = Double @@ -450,6 +466,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Division + func test_div_vector_scalar_double() { typealias Scalar = Double @@ -480,6 +498,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-5) } + // MARK: - Division: In Place + func test_div_in_place_vector_scalar_double() { typealias Scalar = Double @@ -520,6 +540,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-5) } + // MARK: - Element-wise Multiplication + func test_elmul_double() { typealias Scalar = Double @@ -548,6 +570,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Element-wise Multiplication: In Place + func test_elmul_in_place_double() { typealias Scalar = Double @@ -586,6 +610,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-8) } + // MARK: - Element-wise Division + func test_eldiv_double() { typealias Scalar = Double @@ -614,6 +640,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-6) } + // MARK: - Element-wise Division: In Place + func test_eldiv_in_place_double() { typealias Scalar = Double @@ -652,6 +680,12 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-6) } + // MARK: - Dot Product + + // FIXME: missing tests + + // MARK: - Power + func test_pow_vector_scalar_double() { typealias Scalar = Double @@ -680,6 +714,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-5) } + // MARK: - Exponential + func test_exp_vector_double() { typealias Scalar = Double @@ -714,6 +750,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-2) } + // MARK: - Distance + func test_dist_vector_vector_double() { typealias Scalar = Double @@ -744,6 +782,8 @@ class VectorTests: XCTestCase { XCTAssertEqual(actual, expected, accuracy: 1e-6) } + // MARK: - Distance Squared + func test_distsq_vector_vector_double() { typealias Scalar = Double