-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSwift+FloatingPointSign.swift
93 lines (73 loc) · 3.6 KB
/
Swift+FloatingPointSign.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//=----------------------------------------------------------------------------=
// 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 Swift x Floating Point Sign
//*============================================================================*
final class ANKSwiftTestsOnFloatingPointSign: XCTestCase {
typealias T = FloatingPointSign
//=------------------------------------------------------------------------=
// MARK: Tests x Initializers
//=------------------------------------------------------------------------=
func testInitBit() {
XCTAssertEqual(T(false), T.plus )
XCTAssertEqual(T(true ), T.minus)
}
//=------------------------------------------------------------------------=
// MARK: Tests x Accessors
//=------------------------------------------------------------------------=
func testBit() {
XCTAssertEqual(T.plus .bit, false)
XCTAssertEqual(T.minus.bit, true )
}
//=------------------------------------------------------------------------=
// MARK: Tests x Transformations
//=------------------------------------------------------------------------=
func testNot() {
XCTAssertEqual(~T.plus, T.minus)
XCTAssertEqual(~T.minus, T.plus )
XCTAssertEqual(T.plus .toggled(), T.minus)
XCTAssertEqual(T.minus.toggled(), T.plus )
XCTAssertEqual({ var x = T.plus; x.toggle(); return x }(), T.minus)
XCTAssertEqual({ var x = T.minus; x.toggle(); return x }(), T.plus )
}
func testAnd() {
XCTAssertEqual(T.plus & T.plus, T.plus )
XCTAssertEqual(T.plus & T.minus, T.plus )
XCTAssertEqual(T.minus & T.plus, T.plus )
XCTAssertEqual(T.minus & T.minus, T.minus)
XCTAssertEqual({ var x = T.plus; x &= T.plus; return x }(), T.plus )
XCTAssertEqual({ var x = T.plus; x &= T.minus; return x }(), T.plus )
XCTAssertEqual({ var x = T.minus; x &= T.plus; return x }(), T.plus )
XCTAssertEqual({ var x = T.minus; x &= T.minus; return x }(), T.minus)
}
func testOr() {
XCTAssertEqual(T.plus | T.plus, T.plus )
XCTAssertEqual(T.plus | T.minus, T.minus)
XCTAssertEqual(T.minus | T.plus, T.minus)
XCTAssertEqual(T.minus | T.minus, T.minus)
XCTAssertEqual({ var x = T.plus; x |= T.plus; return x }(), T.plus )
XCTAssertEqual({ var x = T.plus; x |= T.minus; return x }(), T.minus)
XCTAssertEqual({ var x = T.minus; x |= T.plus; return x }(), T.minus)
XCTAssertEqual({ var x = T.minus; x |= T.minus; return x }(), T.minus)
}
func testXor() {
XCTAssertEqual(T.plus ^ T.plus, T.plus )
XCTAssertEqual(T.plus ^ T.minus, T.minus)
XCTAssertEqual(T.minus ^ T.plus, T.minus)
XCTAssertEqual(T.minus ^ T.minus, T.plus )
XCTAssertEqual({ var x = T.plus; x ^= T.plus; return x }(), T.plus )
XCTAssertEqual({ var x = T.plus; x ^= T.minus; return x }(), T.minus)
XCTAssertEqual({ var x = T.minus; x ^= T.plus; return x }(), T.minus)
XCTAssertEqual({ var x = T.minus; x ^= T.minus; return x }(), T.plus )
}
}
#endif