2019-09-25 16:21:58 +08:00
|
|
|
// Copyright © 2014-2019 the Surge contributors
|
2014-11-30 08:28:11 +08:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
@testable import Surge
|
|
|
|
|
2014-11-30 08:28:11 +08:00
|
|
|
class TrigonometricTests: XCTestCase {
|
2017-11-26 04:17:56 +08:00
|
|
|
let n = 10_000
|
2014-11-30 08:28:11 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// MARK: - Sine
|
2019-09-26 05:50:31 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_sin_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.sinInPlace(&$0) },
|
|
|
|
expected: { $0.map(sin) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2014-11-30 08:28:11 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_sin_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.sinInPlace(&$0) },
|
|
|
|
expected: { $0.map(sin) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2014-11-30 08:28:11 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// MARK: - Cosine
|
|
|
|
|
|
|
|
func test_cos_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.cosInPlace(&$0) },
|
|
|
|
expected: { $0.map(cos) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2014-11-30 08:28:11 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_cos_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.cosInPlace(&$0) },
|
|
|
|
expected: { $0.map(cos) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 05:50:31 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// MARK: - Tangent
|
|
|
|
|
|
|
|
func test_tan_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.tanInPlace(&$0) },
|
|
|
|
expected: { $0.map(tan) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2017-09-25 14:07:45 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_tan_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.tanInPlace(&$0) },
|
|
|
|
expected: { $0.map(tan) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2017-09-25 14:07:45 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// // MARK: - Arc Sine/Cosine/Tangent
|
|
|
|
|
|
|
|
func test_asin_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.asinInPlace(&$0) },
|
|
|
|
expected: { $0.map(asin) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2017-09-25 14:07:45 +08:00
|
|
|
}
|
2019-09-26 05:50:31 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_asin_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.asinInPlace(&$0) },
|
|
|
|
expected: { $0.map(asin) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Arc Cosine
|
2019-09-26 05:50:31 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_acos_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.acosInPlace(&$0) },
|
|
|
|
expected: { $0.map(acos) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_acos_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.acosInPlace(&$0) },
|
|
|
|
expected: { $0.map(acos) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// MARK: - Arc Tangent
|
|
|
|
|
|
|
|
func test_atan_in_place_float() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Float.self,
|
|
|
|
actual: { Surge.atanInPlace(&$0) },
|
|
|
|
expected: { $0.map(atan) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_atan_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
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
|
|
|
|
)
|
|
|
|
}
|
2019-09-26 05:50:31 +08:00
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_cosh_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
|
|
|
actual: { Surge.coshInPlace(&$0) },
|
|
|
|
expected: { $0.map(cosh) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
// 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,
|
2019-10-11 04:41:35 +08:00
|
|
|
lhs: Array.monotonicNormalized(to: -0.0...0.5),
|
2019-09-27 22:11:42 +08:00
|
|
|
actual: { Surge.atanhInPlace(&$0) },
|
|
|
|
expected: { $0.map(atanh) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-27 22:11:42 +08:00
|
|
|
func test_atanh_in_place_double() {
|
|
|
|
validate_inout_array(
|
|
|
|
of: Double.self,
|
2019-10-11 04:41:35 +08:00
|
|
|
lhs: Array.monotonicNormalized(to: -0.0...0.5),
|
2019-09-27 22:11:42 +08:00
|
|
|
actual: { Surge.atanhInPlace(&$0) },
|
|
|
|
expected: { $0.map(atanh) },
|
|
|
|
accuracy: 1e-4
|
|
|
|
)
|
2019-09-26 05:50:31 +08:00
|
|
|
}
|
2014-11-30 08:28:11 +08:00
|
|
|
}
|