-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
309 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Numberick open source project. | ||
// | ||
// Copyright (c) 2023 Oscar Byström Ericsson | ||
// Licensed under Apache License, Version 2.0 | ||
// | ||
// See http://www.apache.org/licenses/LICENSE-2.0 for license information. | ||
//=----------------------------------------------------------------------------= | ||
|
||
#if !DEBUG | ||
|
||
import NBKCoreKit | ||
import XCTest | ||
|
||
//*============================================================================* | ||
// MARK: * NBK x Sign | ||
//*============================================================================* | ||
|
||
final class NBKBenchmarksOnSign: XCTestCase { | ||
|
||
typealias T = FloatingPointSign | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests | ||
//=------------------------------------------------------------------------= | ||
|
||
func testASCII() { | ||
var abc = NBK.blackHoleIdentity(T.plus ) | ||
var xyz = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.ascii(abc)) | ||
NBK.blackHole(NBK.ascii(xyz)) | ||
|
||
NBK.blackHoleInoutIdentity(&abc) | ||
NBK.blackHoleInoutIdentity(&xyz) | ||
} | ||
} | ||
|
||
func testBit() { | ||
var abc = NBK.blackHoleIdentity(T.plus ) | ||
var xyz = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.bit(abc)) | ||
NBK.blackHole(NBK.bit(xyz)) | ||
|
||
NBK.blackHoleInoutIdentity(&abc) | ||
NBK.blackHoleInoutIdentity(&xyz) | ||
} | ||
} | ||
|
||
func testSign() { | ||
var abc = NBK.blackHoleIdentity(true ) | ||
var xyz = NBK.blackHoleIdentity(false) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.sign(abc)) | ||
NBK.blackHole(NBK.sign(xyz)) | ||
|
||
NBK.blackHoleInoutIdentity(&abc) | ||
NBK.blackHoleInoutIdentity(&xyz) | ||
} | ||
} | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests x Transformations | ||
//=------------------------------------------------------------------------= | ||
|
||
func testNot() { | ||
var abc = NBK.blackHoleIdentity(T.plus ) | ||
var xyz = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.not(abc)) | ||
NBK.blackHole(NBK.not(xyz)) | ||
|
||
NBK.blackHoleInoutIdentity(&abc) | ||
NBK.blackHoleInoutIdentity(&xyz) | ||
} | ||
} | ||
|
||
func testAnd() { | ||
var lhs = NBK.blackHoleIdentity(T.plus ) | ||
var rhs = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.and(lhs, rhs)) | ||
NBK.blackHole(NBK.and(rhs, lhs)) | ||
|
||
NBK.blackHoleInoutIdentity(&lhs) | ||
NBK.blackHoleInoutIdentity(&rhs) | ||
} | ||
} | ||
|
||
func testOr() { | ||
var lhs = NBK.blackHoleIdentity(T.plus ) | ||
var rhs = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.or(lhs, rhs)) | ||
NBK.blackHole(NBK.or(rhs, lhs)) | ||
|
||
NBK.blackHoleInoutIdentity(&lhs) | ||
NBK.blackHoleInoutIdentity(&rhs) | ||
} | ||
} | ||
|
||
func testXor() { | ||
var lhs = NBK.blackHoleIdentity(T.plus ) | ||
var rhs = NBK.blackHoleIdentity(T.minus) | ||
|
||
for _ in 0 ..< 5_000_000 { | ||
NBK.blackHole(NBK.xor(lhs, rhs)) | ||
NBK.blackHole(NBK.xor(rhs, lhs)) | ||
|
||
NBK.blackHoleInoutIdentity(&lhs) | ||
NBK.blackHoleInoutIdentity(&rhs) | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Numberick open source project. | ||
// | ||
// Copyright (c) 2023 Oscar Byström Ericsson | ||
// Licensed under Apache License, Version 2.0 | ||
// | ||
// See http://www.apache.org/licenses/LICENSE-2.0 for license information. | ||
//=----------------------------------------------------------------------------= | ||
|
||
#if DEBUG | ||
|
||
import NBKCoreKit | ||
import XCTest | ||
|
||
//*============================================================================* | ||
// MARK: * NBK x Sign | ||
//*============================================================================* | ||
|
||
final class NBKTestsOnSign: XCTestCase { | ||
|
||
typealias T = FloatingPointSign | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests | ||
//=------------------------------------------------------------------------= | ||
|
||
func testASCII() { | ||
XCTAssertEqual(NBK.ascii(T.plus ), UInt8(ascii: "+")) | ||
XCTAssertEqual(NBK.ascii(T.minus), UInt8(ascii: "-")) | ||
} | ||
|
||
func testBit() { | ||
XCTAssertEqual(NBK.bit(T.plus ), false) | ||
XCTAssertEqual(NBK.bit(T.minus), true ) | ||
} | ||
|
||
func testSign() { | ||
XCTAssertEqual(NBK.sign(false), T.plus ) | ||
XCTAssertEqual(NBK.sign(true ), T.minus) | ||
} | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests x Transformations | ||
//=------------------------------------------------------------------------= | ||
|
||
func testNot() { | ||
XCTAssertEqual(NBK.not(T.plus ), T.minus) | ||
XCTAssertEqual(NBK.not(T.minus), T.plus ) | ||
} | ||
|
||
func testAnd() { | ||
XCTAssertEqual(NBK.and(T.plus, T.plus ), T.plus ) | ||
XCTAssertEqual(NBK.and(T.plus, T.minus), T.plus ) | ||
XCTAssertEqual(NBK.and(T.minus, T.plus ), T.plus ) | ||
XCTAssertEqual(NBK.and(T.minus, T.minus), T.minus) | ||
} | ||
|
||
func testOr() { | ||
XCTAssertEqual(NBK.or (T.plus, T.plus ), T.plus ) | ||
XCTAssertEqual(NBK.or (T.plus, T.minus), T.minus) | ||
XCTAssertEqual(NBK.or (T.minus, T.plus ), T.minus) | ||
XCTAssertEqual(NBK.or (T.minus, T.minus), T.minus) | ||
} | ||
|
||
func testXor() { | ||
XCTAssertEqual(NBK.xor(T.plus, T.plus ), T.plus ) | ||
XCTAssertEqual(NBK.xor(T.plus, T.minus), T.minus) | ||
XCTAssertEqual(NBK.xor(T.minus, T.plus ), T.minus) | ||
XCTAssertEqual(NBK.xor(T.minus, T.minus), T.plus ) | ||
} | ||
} | ||
|
||
#endif |