Skip to content

Commit

Permalink
Improved tests for Trigonometric.swifs
Browse files Browse the repository at this point in the history
  • Loading branch information
regexident committed Sep 27, 2019
1 parent cdf7731 commit a2149de
Showing 1 changed file with 218 additions and 41 deletions.
259 changes: 218 additions & 41 deletions Tests/SurgeTests/TrigonometricTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,254 @@
// THE SOFTWARE.

import Foundation
import Surge
import XCTest

@testable import Surge

class TrigonometricTests: XCTestCase {
let n = 10_000

// MARK: - Sine/Cosine/Tangent
// MARK: - Sine

func test_sin() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: sin, mapped: sin, accuracy: 1e-4)
func test_sin_in_place_float() {
validate_inout_array(
of: Float.self,
actual: { Surge.sinInPlace(&$0) },
expected: { $0.map(sin) },
accuracy: 1e-4
)
}

func test_cos() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: cos, mapped: cos, accuracy: 1e-4)
func test_sin_in_place_double() {
validate_inout_array(
of: Double.self,
actual: { Surge.sinInPlace(&$0) },
expected: { $0.map(sin) },
accuracy: 1e-4
)
}

func test_tan() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: tan, mapped: tan, accuracy: 1e-4)
// 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
)
}

// MARK: - Arc Sine/Cosine/Tangent
func test_cos_in_place_double() {
validate_inout_array(
of: Double.self,
actual: { Surge.cosInPlace(&$0) },
expected: { $0.map(cos) },
accuracy: 1e-4
)
}

func test_asin() {
let values = (0...n).map { _ in drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: asin, mapped: asin, accuracy: 1e-4)
// 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
)
}

func test_acos() {
let values = (0...n).map { _ in drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: acos, mapped: acos, accuracy: 1e-4)
func test_tan_in_place_double() {
validate_inout_array(
of: Double.self,
actual: { Surge.tanInPlace(&$0) },
expected: { $0.map(tan) },
accuracy: 1e-4
)
}

func test_atan() {
let values = (0...n).map { _ in drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: atan, mapped: atan, accuracy: 1e-4)
// // 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
)
}

// MARK: - Hyperbolic Sine/Cosine/Tangent
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

func test_sinh() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: sinh, mapped: sinh, 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
)
}

func test_cosh() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: cosh, mapped: cosh, accuracy: 1e-4)
func test_acos_in_place_double() {
validate_inout_array(
of: Double.self,
actual: { Surge.acosInPlace(&$0) },
expected: { $0.map(acos) },
accuracy: 1e-4
)
}

func test_tanh() {
let values = (0...n).map { _ in drand48() * Double.pi }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: tanh, mapped: tanh, accuracy: 1e-4)
// 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
)
}

// MARK: - Inverse Hyperbolic Sine/Cosine/Tangent
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
)
}

func test_asinh() {
let values = (0...n).map { _ in drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: asinh, mapped: asinh, 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
)
}

func test_acosh() {
let values = (0...n).map { _ in 1 + drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: acosh, mapped: acosh, 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() {
let values = (0...n).map { _ in drand48() }
measureAndValidateMappedFunctionWithAccuracy(source: values, member: atanh, mapped: 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
)
}
}

0 comments on commit a2149de

Please sign in to comment.