File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -87,10 +87,38 @@ def test_bitxor():
87
87
assert (r == - 1 )
88
88
assert (s == - 2147483643 )
89
89
90
+ def test_left_shift ():
91
+ a : i32 = 4
92
+ shift_amount : i32 = 2
93
+ b : i32 = a << shift_amount
94
+ print (b )
95
+ assert b == 16
96
+
97
+ a = - 16
98
+ shift_amount = 2
99
+ b = a << shift_amount
100
+ print (b )
101
+ assert b == - 64
102
+
103
+ def test_right_shift ():
104
+ a : i32 = 16
105
+ shift_amount : i32 = 2
106
+ b : i32 = a >> shift_amount
107
+ print (b )
108
+ assert b == 4
109
+
110
+ a = - 16
111
+ shift_amount = 2
112
+ b = a >> shift_amount
113
+ print (b )
114
+ assert b == - 4
115
+
90
116
def main0 ():
91
117
test_bitnot ()
92
118
test_bitand ()
93
119
test_bitor ()
94
120
test_bitxor ()
121
+ test_left_shift ()
122
+ test_right_shift ()
95
123
96
124
main0 ()
Original file line number Diff line number Diff line change @@ -84,10 +84,38 @@ def test_bitxor():
84
84
assert (r == i64 (- 1 ))
85
85
assert (s == i64 (- 115292150461418 ))
86
86
87
+ def test_left_shift ():
88
+ a : i64 = i64 (4294967296 )
89
+ shift_amount : i64 = i64 (2 )
90
+ b : i64 = a << shift_amount
91
+ print (b )
92
+ assert b == i64 (17179869184 )
93
+
94
+ a = i64 (- 4294967296 )
95
+ shift_amount = i64 (2 )
96
+ b = a << shift_amount
97
+ print (b )
98
+ assert b == i64 (- 17179869184 )
99
+
100
+ def test_right_shift ():
101
+ a : i64 = i64 (4294967296 )
102
+ shift_amount : i64 = i64 (2 )
103
+ b : i64 = a >> shift_amount
104
+ print (b )
105
+ assert b == i64 (1073741824 )
106
+
107
+ a = i64 (- 4294967296 )
108
+ shift_amount = i64 (2 )
109
+ b = a >> shift_amount
110
+ print (b )
111
+ assert b == i64 (- 1073741824 )
112
+
87
113
def main0 ():
88
114
test_bitnot ()
89
115
test_bitand ()
90
116
test_bitor ()
91
117
test_bitxor ()
118
+ test_left_shift ()
119
+ test_right_shift ()
92
120
93
121
main0 ()
You can’t perform that action at this time.
0 commit comments