-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some init(clamping:) infinity fixes (#21).
- Loading branch information
Showing
8 changed files
with
130 additions
and
18 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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,42 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Ultimathnum 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. | ||
//=----------------------------------------------------------------------------= | ||
|
||
import CoreKit | ||
import DoubleIntKit | ||
import InfiniIntKit | ||
import TestKit | ||
|
||
//*============================================================================* | ||
// MARK: * Binary Integer x Validation | ||
//*============================================================================* | ||
//=----------------------------------------------------------------------------= | ||
// MARK: + Edge Cases | ||
//=----------------------------------------------------------------------------= | ||
|
||
extension BinaryIntegerTests { | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Tests | ||
//=------------------------------------------------------------------------= | ||
|
||
/// 2024-06-20: Signed systems integers should successfully clamp `∞`. | ||
func testSystemsIntegersCanClampInfiniteValues() { | ||
func whereIs<A, B>(_ source: A.Type, _ destinaiton: B.Type) where A: UnsignedInteger, B: SystemsInteger { | ||
precondition(A.size.isInfinite) | ||
Test().same(B(clamping: A.max ), B.max) | ||
Test().same(B(clamping: A.max - 1), B.max) | ||
} | ||
|
||
for source in Self.arbitraryIntegersWhereIsUnsigned { | ||
for destinaiton in Self.systemsIntegers { | ||
whereIs(source, destinaiton) | ||
} | ||
} | ||
} | ||
} |
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,66 @@ | ||
//=----------------------------------------------------------------------------= | ||
// This source file is part of the Ultimathnum 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. | ||
//=----------------------------------------------------------------------------= | ||
|
||
import CoreKit | ||
import DoubleIntKit | ||
import InfiniIntKit | ||
import TestKit | ||
|
||
//*============================================================================* | ||
// MARK: * Binary Integer | ||
//*============================================================================* | ||
|
||
final class BinaryIntegerTests: XCTestCase { | ||
|
||
//=------------------------------------------------------------------------= | ||
// MARK: Metadata | ||
//=------------------------------------------------------------------------= | ||
|
||
static let types: [any BinaryInteger.Type] = { | ||
typesWhereIsSigned + | ||
typesWhereIsUnsigned | ||
}() | ||
|
||
static let typesWhereIsSigned: [any SignedInteger.Type] = { | ||
systemsIntegersWhereIsSigned + | ||
arbitraryIntegersWhereIsSigned | ||
}() | ||
|
||
static let typesWhereIsUnsigned: [any UnsignedInteger.Type] = { | ||
systemsIntegersWhereIsUnsigned + | ||
arbitraryIntegersWhereIsUnsigned | ||
}() | ||
|
||
static let arbitraryIntegersWhereIsSigned: [any SignedInteger.Type] = [ | ||
InfiniInt<I8>.self, | ||
InfiniInt<IX>.self, | ||
] | ||
|
||
static let arbitraryIntegersWhereIsUnsigned: [any UnsignedInteger.Type] = [ | ||
InfiniInt<U8>.self, | ||
InfiniInt<UX>.self, | ||
] | ||
|
||
static var systemsIntegers: [any SystemsInteger.Type] = { | ||
systemsIntegersWhereIsSigned + | ||
systemsIntegersWhereIsUnsigned | ||
}() | ||
|
||
static var systemsIntegersWhereIsSigned: [any (SystemsInteger & SignedInteger).Type] = [ | ||
IX.self, I8 .self, I16.self, I32.self, I64 .self, | ||
DoubleInt<I8>.self, DoubleInt<DoubleInt<I8>>.self, | ||
DoubleInt<IX>.self, DoubleInt<DoubleInt<IX>>.self, | ||
] | ||
|
||
static var systemsIntegersWhereIsUnsigned: [any (SystemsInteger & UnsignedInteger).Type] = [ | ||
UX.self, U8 .self, U16.self, U32.self, U64 .self, | ||
DoubleInt<U8>.self, DoubleInt<DoubleInt<U8>>.self, | ||
DoubleInt<UX>.self, DoubleInt<DoubleInt<UX>>.self, | ||
] | ||
} |