Skip to content

Commit f84b49a

Browse files
authored
Stricter tests in int.jl (#44522)
* Stricter tests in int.jl * More tests for coverage.
1 parent 5dfd6c9 commit f84b49a

File tree

1 file changed

+61
-53
lines changed

1 file changed

+61
-53
lines changed

test/int.jl

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -55,37 +55,37 @@ using Random
5555
end
5656
end
5757
@testset "signed and unsigned" begin
58-
@test signed(3) == 3
59-
@test signed(UInt(3)) == 3
58+
@test signed(3) === 3
59+
@test signed(UInt(3)) === 3
6060
@test isa(signed(UInt(3)), Int)
61-
@test signed(UInt(0) - 1) == -1
61+
@test signed(UInt(0) - 1) === -1
6262
@test_throws InexactError signed(UInt(-3))
63-
@test signed(true) == 1
63+
@test signed(true) === 1
6464
@test unsigned(true) isa Unsigned
65-
@test unsigned(true) == unsigned(1)
65+
@test unsigned(true) === unsigned(1)
6666

67-
@test signed(Bool) == Int
68-
@test signed(Bool) == typeof(signed(true))
69-
@test unsigned(Bool) == UInt
70-
@test unsigned(Bool) == typeof(unsigned(true))
67+
@test signed(Bool) === Int
68+
@test signed(Bool) === typeof(signed(true))
69+
@test unsigned(Bool) === UInt
70+
@test unsigned(Bool) === typeof(unsigned(true))
7171
end
7272
@testset "bswap" begin
7373
@test bswap(Int8(3)) == 3
74-
@test bswap(UInt8(3)) == 3
74+
@test bswap(UInt8(3)) === 0x3
7575
@test bswap(Int16(3)) == 256*3
7676
@test bswap(Int16(256)) == 1
7777
@test bswap(Int16(257)) == 257
7878
@test bswap(Int32(1)) == 2^(3*8)
7979
@test bswap(Int32(2)^(3*8)) == 1
80-
@test bswap(Int64(1)) == Int64(2)^(7*8)
80+
@test bswap(Int64(1)) === Int64(2)^(7*8)
8181
@test bswap(Int64(2)^(7*8)) == 1
82-
@test bswap(Int128(1)) == Int128(2)^(15*8)
83-
@test bswap(Int128(2)^(15*8)) == Int128(1)
84-
@test bswap(UInt128(2)^(15*8)) == UInt128(1)
82+
@test bswap(Int128(1)) === Int128(2)^(15*8)
83+
@test bswap(Int128(2)^(15*8)) === Int128(1)
84+
@test bswap(UInt128(2)^(15*8)) === UInt128(1)
8585
end
8686
@testset "count_zeros" begin
87-
@test count_zeros(10) == Sys.WORD_SIZE - 2
88-
@test count_zeros(UInt8(10)) == 6
87+
@test count_zeros(10) === Sys.WORD_SIZE - 2
88+
@test count_zeros(UInt8(10)) === 6
8989
end
9090
@testset "Conversions" begin
9191
@test convert(Signed, UInt128(3)) === Int128(3)
@@ -104,11 +104,11 @@ end
104104
end
105105

106106
@testset "trunc, floor, ceil" begin
107-
@test trunc(3) == 3
108-
@test trunc(Integer, 3) == 3
107+
@test trunc(3) === 3
108+
@test trunc(Integer, 3) === 3
109109

110-
@test floor(3) == 3
111-
@test ceil(3) == 3
110+
@test floor(3) === 3
111+
@test ceil(3) === 3
112112
end
113113

114114
@testset "big" begin
@@ -120,10 +120,11 @@ end
120120
end
121121

122122
@test round(UInt8, 123) == 123
123-
@test mod(123, UInt8) == 0x7b
123+
@test mod(123, UInt8) === 0x7b
124124

125-
primitive type MyBitsType <: Integer 8 end
125+
primitive type MyBitsType <: Signed 8 end
126126
@test_throws MethodError ~reinterpret(MyBitsType, 0x7b)
127+
@test signed(MyBitsType) === MyBitsType
127128

128129
UItypes = Base.BitUnsigned_types
129130
SItypes = Base.BitSigned_types
@@ -211,8 +212,8 @@ end
211212
end
212213

213214
val2 = 0xabcd
214-
@test 0x5e6d == bitrotate(val2, 3)
215-
@test 0xb579 == bitrotate(val2, -3)
215+
@test 0x5e6d === bitrotate(val2, 3)
216+
@test 0xb579 === bitrotate(val2, -3)
216217
end
217218

218219
@testset "widen/widemul" begin
@@ -240,12 +241,12 @@ end
240241
@test typeof(widen(Int64(-3))) == Int128
241242
@test typeof(widen(Int128(-3))) == BigInt
242243

243-
@test widemul(false, false) == false
244-
@test widemul(false, 3) == 0
245-
@test widemul(3, true) == widemul(true, 3) == 3
244+
@test widemul(false, false) === false
245+
@test widemul(false, 3) === 0
246+
@test widemul(3, true) === widemul(true, 3) === 3
246247

247248
let i=Int64(2)^63-1, k=widemul(i,i)
248-
@test widemul(i,i)==85070591730234615847396907784232501249
249+
@test widemul(i,i)===85070591730234615847396907784232501249
249250
j=div(k,2)
250251
@test div(k,j)==2
251252
j=div(k,5)
@@ -367,17 +368,17 @@ end
367368
(5, -3, -2, -2, -2))
368369
for sign in (+1, -1)
369370
(a, b) = (a*sign, b*sign)
370-
@test div(a, b, RoundNearest) == nearest
371-
@test div(a, b, RoundNearestTiesAway) == away
372-
@test div(a, b, RoundNearestTiesUp) == up
371+
@test div(a, b, RoundNearest) === nearest
372+
@test div(a, b, RoundNearestTiesAway) === away
373+
@test div(a, b, RoundNearestTiesUp) === up
373374
end
374375
end
375376

376377
@test div(typemax(Int64), typemax(Int64)-1, RoundNearest) == 1
377378
@test div(-typemax(Int64), typemax(Int64)-1, RoundNearest) == -1
378379
@test div(typemax(Int64), 2, RoundNearest) == 4611686018427387904
379380
@test div(-typemax(Int64), 2, RoundNearestTiesUp) == -4611686018427387903
380-
@test div(typemax(Int)-2, typemax(Int), RoundNearest) == 1
381+
@test div(typemax(Int)-2, typemax(Int), RoundNearest) === 1
381382

382383
# Exhaustively test (U)Int8 to catch any overflow-style issues
383384
for r in (RoundNearest, RoundNearestTiesAway, RoundNearestTiesUp)
@@ -407,25 +408,32 @@ end
407408
end
408409

409410
@testset "min/max of datatype" begin
410-
@test typemin(Int8) == Int8(-128)
411-
@test typemin(UInt8) == UInt8(0)
412-
@test typemin(Int16) == Int16(-32768)
413-
@test typemin(UInt16) == UInt16(0)
414-
@test typemin(Int32) == Int32(-2147483648)
415-
@test typemin(UInt32) == UInt32(0)
416-
@test typemin(Int64) == Int64(-9223372036854775808)
417-
@test typemin(UInt64) == UInt64(0)
418-
@test typemin(Int128) == Int128(-170141183460469231731687303715884105728)
419-
@test typemin(UInt128) == UInt128(0)
420-
421-
@test typemax(Int8) == Int8(127)
422-
@test typemax(UInt8) == UInt8(255)
423-
@test typemax(Int16) == Int16(32767)
424-
@test typemax(UInt16) == UInt16(65535)
425-
@test typemax(Int32) == Int32(2147483647)
426-
@test typemax(UInt32) == UInt32(4294967295)
427-
@test typemax(Int64) == Int64(9223372036854775807)
428-
@test typemax(UInt64) == UInt64(0xffffffffffffffff)
429-
@test typemax(Int128) == Int128(170141183460469231731687303715884105727)
430-
@test typemax(UInt128) == UInt128(0xffffffffffffffffffffffffffffffff)
411+
@test typemin(Int8) === Int8(-128)
412+
@test typemin(UInt8) === UInt8(0)
413+
@test typemin(Int16) === Int16(-32768)
414+
@test typemin(UInt16) === UInt16(0)
415+
@test typemin(Int32) === Int32(-2147483648)
416+
@test typemin(UInt32) === UInt32(0)
417+
@test typemin(Int64) === Int64(-9223372036854775808)
418+
@test typemin(UInt64) === UInt64(0)
419+
@test typemin(Int128) === Int128(-170141183460469231731687303715884105728)
420+
@test typemin(UInt128) === UInt128(0)
421+
422+
@test typemax(Int8) === Int8(127)
423+
@test typemax(UInt8) === UInt8(255)
424+
@test typemax(Int16) === Int16(32767)
425+
@test typemax(UInt16) === UInt16(65535)
426+
@test typemax(Int32) === Int32(2147483647)
427+
@test typemax(UInt32) === UInt32(4294967295)
428+
@test typemax(Int64) === Int64(9223372036854775807)
429+
@test typemax(UInt64) === UInt64(0xffffffffffffffff)
430+
@test typemax(Int128) === Int128(170141183460469231731687303715884105727)
431+
@test typemax(UInt128) === UInt128(0xffffffffffffffffffffffffffffffff)
432+
end
433+
434+
@testset "BitIntegerType" begin
435+
@test Int isa Base.BitIntegerType
436+
@test Base.BitIntegerType === Union{
437+
Type{ Int8}, Type{ Int16}, Type{ Int32}, Type{ Int64}, Type{ Int128},
438+
Type{UInt8}, Type{UInt16}, Type{UInt32}, Type{UInt64}, Type{UInt128}}
431439
end

0 commit comments

Comments
 (0)