-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathANKCoreInteger+Bits.swift
76 lines (60 loc) · 2.49 KB
/
ANKCoreInteger+Bits.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
76
//=----------------------------------------------------------------------------=
// 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 Bits
//*============================================================================*
final class ANKCoreIntegerTestsOnBits: XCTestCase {
typealias T = any ANKCoreInteger.Type
//=------------------------------------------------------------------------=
// MARK: State
//=------------------------------------------------------------------------=
let types: [T] = ANKCoreIntegerTests.types
//=------------------------------------------------------------------------=
// MARK: Tests
//=------------------------------------------------------------------------=
func testFromBit() {
func whereIs<T>(_ type: T.Type) where T: ANKCoreInteger {
XCTAssertEqual(T(bit: false), T( ))
XCTAssertEqual(T(bit: true ), T(1))
}
for type in types {
whereIs(type)
}
}
func testFromRepeatingBit() {
func whereIs<T>(_ type: T.Type) where T: ANKCoreInteger {
XCTAssertEqual(T(repeating: false), T( ))
XCTAssertEqual(T(repeating: true ), ~T( ))
}
for type in types {
whereIs(type)
}
}
//=------------------------------------------------------------------------=
// MARK: Tests x Accessors
//=------------------------------------------------------------------------=
func testMostSignificantBit() {
for type: T in types {
XCTAssertEqual(type.min .mostSignificantBit, type.isSigned)
XCTAssertEqual(type.zero.mostSignificantBit, false)
XCTAssertEqual(type.max .mostSignificantBit, !type.isSigned)
}
}
func testLeastSignificantBit() {
for type: T in types {
XCTAssertEqual(type.min .leastSignificantBit, false)
XCTAssertEqual(type.zero.leastSignificantBit, false)
XCTAssertEqual(type.max .leastSignificantBit, true )
}
}
}
#endif