forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitwiseOperationsType.swift
43 lines (30 loc) · 997 Bytes
/
BitwiseOperationsType.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
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
import StdlibUnittest
struct MyInt32 : BitwiseOperations {
var underlying: Int32
static var allZeros: MyInt32 { return MyInt32(underlying: 0) }
}
func & (lhs: MyInt32, rhs: MyInt32) -> MyInt32 {
return MyInt32(underlying: lhs.underlying & rhs.underlying)
}
func |(lhs: MyInt32, rhs: MyInt32) -> MyInt32 {
return MyInt32(underlying: lhs.underlying | rhs.underlying)
}
func ^(lhs: MyInt32, rhs: MyInt32) -> MyInt32 {
return MyInt32(underlying: lhs.underlying ^ rhs.underlying)
}
prefix func ~(x: MyInt32) -> MyInt32 {
return MyInt32(underlying: ~x.underlying)
}
let BitwiseOperationsTests = TestSuite("BitwiseOperations")
BitwiseOperationsTests.test("smoke test") {
var a = MyInt32(underlying: 0x3)
a |= MyInt32(underlying: 0x4)
expectEqual(0x7, a.underlying)
a &= MyInt32(underlying: 0x5)
expectEqual(0x5, a.underlying)
a ^= MyInt32(underlying: 0x6)
expectEqual(0x3, a.underlying)
}
runAllTests()