Skip to content

Commit e3e36f7

Browse files
committed
[test] Increase DoubleWidth bit shifting test coverage
1 parent 47d050e commit e3e36f7

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/stdlib/Integers.swift.gyb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -751,22 +751,30 @@ dwTests.test("TwoWords") {
751751
}
752752

753753
dwTests.test("Bitshifts") {
754-
typealias DWU16 = DoubleWidth<UInt8>
755-
typealias DWU32 = DoubleWidth<DWU16>
756-
typealias DWU64 = DoubleWidth<DWU32>
754+
typealias DWU64 = DoubleWidth<DoubleWidth<DoubleWidth<UInt8>>>
755+
typealias DWI64 = DoubleWidth<DoubleWidth<DoubleWidth<Int8>>>
757756

758-
func f(_ x: UInt64) {
759-
let y = DWU64(x)
760-
for i in -65...65 {
757+
func f<T: FixedWidthInteger, U: FixedWidthInteger>(_ x: T, type: U.Type) {
758+
let y = U(x)
759+
expectEqual(T.bitWidth, U.bitWidth)
760+
for i in -(T.bitWidth + 1)...(T.bitWidth + 1) {
761761
expectTrue(x << i == y << i)
762762
expectTrue(x >> i == y >> i)
763+
764+
expectTrue(x &<< i == y &<< i)
765+
expectTrue(x &>> i == y &>> i)
763766
}
764767
}
765768

766-
f(1)
767-
f(~(~0 >> 1))
768-
f(.max)
769-
f(0b11110000_10100101_11110000_10100101_11110000_10100101_11110000_10100101)
769+
f(1 as UInt64, type: DWU64.self)
770+
f(~(~0 as UInt64 >> 1), type: DWU64.self)
771+
f(UInt64.max, type: DWU64.self)
772+
f(0b11110000_10100101_11110000_10100101_11110000_10100101_11110000_10100101 as UInt64, type: DWU64.self)
773+
774+
f(1 as Int64, type: DWI64.self)
775+
f(Int64.min, type: DWI64.self)
776+
f(Int64.max, type: DWI64.self)
777+
f(0b01010101_10100101_11110000_10100101_11110000_10100101_11110000_10100101 as Int64, type: DWI64.self)
770778
}
771779

772780
dwTests.test("Remainder/DividingBy0") {

0 commit comments

Comments
 (0)