-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathANKCoreInteger+Negation.swift
75 lines (59 loc) · 2.64 KB
/
ANKCoreInteger+Negation.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//=----------------------------------------------------------------------------=
// This source file is part of the AwesomeNumbersKit open source project.
//
// Copyright (c) 2022 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 ANKCoreKit
import XCTest
//*============================================================================*
// MARK: * ANK x Core Integer x Negation
//*============================================================================*
final class ANKCoreIntegerTestsOnNegation: XCTestCase {
typealias T = any (ANKCoreInteger).Type
typealias S = any (ANKCoreInteger & ANKSignedInteger).Type
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
let types: [T] = ANKCoreIntegerTests.types
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=
func testNegating() {
func whereIsSigned<T>(_ type: T.Type) where T: ANKCoreInteger & ANKSignedInteger {
ANKAssertNegation( T(1), -T(1))
ANKAssertNegation( T( ), T( ))
ANKAssertNegation(-T(1), T(1))
}
for case let type as S in types {
whereIsSigned(type)
}
}
func testNegatingReportingOverflow() {
func whereIsSigned<T>(_ type: T.Type) where T: ANKCoreInteger & ANKSignedInteger {
ANKAssertNegation(T.max - T( ), T.min + T(1))
ANKAssertNegation(T.max - T(1), T.min + T(2))
ANKAssertNegation(T.min + T(1), T.max - T( ))
ANKAssertNegation(T.min + T( ), T.min, true)
}
for case let type as S in types {
whereIsSigned(type)
}
}
//=------------------------------------------------------------------------=
// MARK: Tests x Miscellaneous
//=------------------------------------------------------------------------=
func testOverloadsAreUnambiguous() {
func becauseThisCompilesSuccessfully(_ x: inout some ANKCoreInteger & ANKSignedInteger) {
XCTAssertNotNil(x.negate())
XCTAssertNotNil(x.negateReportingOverflow())
XCTAssertNotNil(-x)
XCTAssertNotNil(x.negated())
XCTAssertNotNil(x.negatedReportingOverflow())
}
}
}
#endif