5
5
import Base: checked_abs, checked_neg, checked_add, checked_sub, checked_mul,
6
6
checked_div, checked_rem, checked_fld, checked_mod, checked_cld
7
7
8
- # Test return types
9
- for T in (Int8,Int16,Int32,Int64,Int128, UInt8,UInt16,UInt32,UInt64,UInt128)
10
- z, o = T (0 ), T (1 )
11
- @test typeof (checked_neg (z)) === T
12
- @test typeof (checked_abs (z)) === T
13
- @test typeof (checked_add (z)) === T
14
- @test typeof (checked_mul (z)) === T
15
- @test typeof (checked_add (z,z)) === T
16
- @test typeof (checked_sub (z,z)) === T
17
- @test typeof (checked_mul (z,z)) === T
18
- @test typeof (checked_div (z,o)) === T
19
- @test typeof (checked_rem (z,o)) === T
20
- @test typeof (checked_fld (z,o)) === T
21
- @test typeof (checked_mod (z,o)) === T
22
- @test typeof (checked_cld (z,o)) === T
23
- end
24
-
25
8
# checked operations
26
9
27
10
for T in (Int8, Int16, Int32, Int64, Int128)
28
11
# regular cases
12
+ @test checked_abs (T (0 )) === T (0 )
13
+ @test checked_neg (T (0 )) === T (0 )
14
+ @test checked_add (T (0 )) === T (0 )
15
+ @test checked_mul (T (0 )) === T (0 )
16
+
29
17
for s in (- 1 , + 1 )
30
- @test checked_abs (T (0 s)) === T (abs (0 s))
31
- @test checked_neg (T (0 s)) === T (- (0 s))
32
- @test checked_add (T (0 s)) === T (0 s)
33
- @test checked_mul (T (0 s)) === T (0 s)
34
18
@test checked_abs (T (3 s)) === T (abs (3 s))
35
- @test checked_neg (T (3 s)) === T (- ( 3 s) )
19
+ @test checked_neg (T (3 s)) === T (- 3 s )
36
20
@test checked_add (T (3 s)) === T (3 s)
37
21
@test checked_mul (T (3 s)) === T (3 s)
38
22
@test checked_abs (T (s* typemax (T))) === typemax (T)
@@ -46,7 +30,7 @@ for T in (Int8, Int16, Int32, Int64, Int128)
46
30
@test_throws OverflowError checked_neg (typemin (T))
47
31
48
32
# regular cases
49
- for s1 in (- 1 , + 1 ), s2 in (- 1 ,+ 1 )
33
+ for s1 in (- 1 , + 1 ), s2 in (- 1 , + 1 )
50
34
@test checked_add (T (4 s1), T (3 s2)) === T (4 s1 + 3 s2)
51
35
@test checked_sub (T (4 s1), T (3 s2)) === T (4 s1 - 3 s2)
52
36
@test checked_mul (T (4 s1), T (3 s2)) === T (4 s1 * 3 s2)
@@ -144,8 +128,13 @@ for T in (UInt8, UInt16, UInt32, UInt64, UInt128)
144
128
# regular cases
145
129
@test checked_abs (T (0 )) === T (0 )
146
130
@test checked_neg (T (0 )) === T (0 )
131
+ @test checked_add (T (0 )) === T (0 )
132
+ @test checked_mul (T (0 )) === T (0 )
133
+
147
134
@test checked_abs (T (3 )) === T (3 )
148
135
@test_throws OverflowError checked_neg (T (3 ))
136
+ @test checked_add (T (3 )) === T (3 )
137
+ @test checked_mul (T (3 )) === T (3 )
149
138
150
139
# regular cases
151
140
@test checked_add (T (4 ), T (3 )) === T (7 )
0 commit comments