Improved tests for `Trigonometric.swifs`
This commit is contained in:
parent
cdf7731530
commit
a2149dee03
|
@ -19,77 +19,254 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import Surge
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
|
@testable import Surge
|
||||||
|
|
||||||
class TrigonometricTests: XCTestCase {
|
class TrigonometricTests: XCTestCase {
|
||||||
let n = 10_000
|
let n = 10_000
|
||||||
|
|
||||||
// MARK: - Sine/Cosine/Tangent
|
// MARK: - Sine
|
||||||
|
|
||||||
func test_sin() {
|
func test_sin_in_place_float() {
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: sin, mapped: sin, accuracy: 1e-4)
|
of: Float.self,
|
||||||
|
actual: { Surge.sinInPlace(&$0) },
|
||||||
|
expected: { $0.map(sin) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_cos() {
|
func test_sin_in_place_double() {
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: cos, mapped: cos, accuracy: 1e-4)
|
of: Double.self,
|
||||||
|
actual: { Surge.sinInPlace(&$0) },
|
||||||
|
expected: { $0.map(sin) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_tan() {
|
// MARK: - Cosine
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: tan, mapped: tan, accuracy: 1e-4)
|
func test_cos_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.cosInPlace(&$0) },
|
||||||
|
expected: { $0.map(cos) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Arc Sine/Cosine/Tangent
|
func test_cos_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
func test_asin() {
|
of: Double.self,
|
||||||
let values = (0...n).map { _ in drand48() }
|
actual: { Surge.cosInPlace(&$0) },
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: asin, mapped: asin, accuracy: 1e-4)
|
expected: { $0.map(cos) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_acos() {
|
// MARK: - Tangent
|
||||||
let values = (0...n).map { _ in drand48() }
|
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: acos, mapped: acos, accuracy: 1e-4)
|
func test_tan_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.tanInPlace(&$0) },
|
||||||
|
expected: { $0.map(tan) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_atan() {
|
func test_tan_in_place_double() {
|
||||||
let values = (0...n).map { _ in drand48() }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: atan, mapped: atan, accuracy: 1e-4)
|
of: Double.self,
|
||||||
|
actual: { Surge.tanInPlace(&$0) },
|
||||||
|
expected: { $0.map(tan) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Hyperbolic Sine/Cosine/Tangent
|
// // MARK: - Arc Sine/Cosine/Tangent
|
||||||
|
|
||||||
func test_sinh() {
|
func test_asin_in_place_float() {
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: sinh, mapped: sinh, accuracy: 1e-4)
|
of: Float.self,
|
||||||
|
actual: { Surge.asinInPlace(&$0) },
|
||||||
|
expected: { $0.map(asin) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_cosh() {
|
func test_asin_in_place_double() {
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: cosh, mapped: cosh, accuracy: 1e-4)
|
of: Double.self,
|
||||||
|
actual: { Surge.asinInPlace(&$0) },
|
||||||
|
expected: { $0.map(asin) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_tanh() {
|
// MARK: - Arc Cosine
|
||||||
let values = (0...n).map { _ in drand48() * Double.pi }
|
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: tanh, mapped: tanh, accuracy: 1e-4)
|
func test_acos_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.acosInPlace(&$0) },
|
||||||
|
expected: { $0.map(acos) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Inverse Hyperbolic Sine/Cosine/Tangent
|
func test_acos_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
func test_asinh() {
|
of: Double.self,
|
||||||
let values = (0...n).map { _ in drand48() }
|
actual: { Surge.acosInPlace(&$0) },
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: asinh, mapped: asinh, accuracy: 1e-4)
|
expected: { $0.map(acos) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_acosh() {
|
// MARK: - Arc Tangent
|
||||||
let values = (0...n).map { _ in 1 + drand48() }
|
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: acosh, mapped: acosh, accuracy: 1e-4)
|
func test_atan_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.atanInPlace(&$0) },
|
||||||
|
expected: { $0.map(atan) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func test_atanh() {
|
func test_atan_in_place_double() {
|
||||||
let values = (0...n).map { _ in drand48() }
|
validate_inout_array(
|
||||||
measureAndValidateMappedFunctionWithAccuracy(source: values, member: atanh, mapped: atanh, accuracy: 1e-4)
|
of: Double.self,
|
||||||
|
actual: { Surge.atanInPlace(&$0) },
|
||||||
|
expected: { $0.map(atan) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Hyperbolic Sine
|
||||||
|
|
||||||
|
func test_sinh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.sinhInPlace(&$0) },
|
||||||
|
expected: { $0.map(sinh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_sinh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
actual: { Surge.sinhInPlace(&$0) },
|
||||||
|
expected: { $0.map(sinh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Hyperbolic Cosine
|
||||||
|
|
||||||
|
func test_cosh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.coshInPlace(&$0) },
|
||||||
|
expected: { $0.map(cosh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_cosh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
actual: { Surge.coshInPlace(&$0) },
|
||||||
|
expected: { $0.map(cosh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Hyperbolic Tangent
|
||||||
|
|
||||||
|
func test_tanh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.tanhInPlace(&$0) },
|
||||||
|
expected: { $0.map(tanh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_tanh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
actual: { Surge.tanhInPlace(&$0) },
|
||||||
|
expected: { $0.map(tanh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inverse Hyperbolic Sine
|
||||||
|
|
||||||
|
func test_asinh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
actual: { Surge.asinhInPlace(&$0) },
|
||||||
|
expected: { $0.map(asinh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_asinh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
actual: { Surge.asinhInPlace(&$0) },
|
||||||
|
expected: { $0.map(asinh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inverse Hyperbolic Cosine
|
||||||
|
|
||||||
|
func test_acosh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
lhs: Array.monotonicNormalized().map { $0 + 1.0 },
|
||||||
|
actual: { Surge.acoshInPlace(&$0) },
|
||||||
|
expected: { $0.map(acosh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_acosh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
lhs: Array.monotonicNormalized().map { $0 + 1.0 },
|
||||||
|
actual: { Surge.acoshInPlace(&$0) },
|
||||||
|
expected: { $0.map(acosh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inverse Hyperbolic Tangent
|
||||||
|
|
||||||
|
func test_atanh_in_place_float() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Float.self,
|
||||||
|
lhs: Array.monotonicNormalized(to: 0.5),
|
||||||
|
actual: { Surge.atanhInPlace(&$0) },
|
||||||
|
expected: { $0.map(atanh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_atanh_in_place_double() {
|
||||||
|
validate_inout_array(
|
||||||
|
of: Double.self,
|
||||||
|
lhs: Array.monotonicNormalized(to: 0.5),
|
||||||
|
actual: { Surge.atanhInPlace(&$0) },
|
||||||
|
expected: { $0.map(atanh) },
|
||||||
|
accuracy: 1e-4
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue