forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TEST: BitOperations: Add and enable tests
- Loading branch information
1 parent
aff81f5
commit 725a580
Showing
3 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from ltypes import i32 | ||
|
||
def test_bitnot(): | ||
x: i32 = 5 | ||
y: i32 = 0 | ||
z: i32 = 2147483647 | ||
w: i32 = -2147483648 | ||
|
||
p: i32 = ~x | ||
q: i32 = ~y | ||
r: i32 = ~z | ||
s: i32 = ~w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == -6) | ||
assert(q == -1) | ||
assert(r == -2147483648) | ||
assert(s == 2147483647) | ||
|
||
def test_bitand(): | ||
x: i32 = 5 | ||
y: i32 = 3 | ||
z: i32 = 2147483647 | ||
w: i32 = -2147483648 | ||
|
||
|
||
p: i32 = x & y | ||
q: i32 = y & z | ||
r: i32 = z & w | ||
s: i32 = x & w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == 1) | ||
assert(q == 3) | ||
assert(r == 0) | ||
assert(s == 0) | ||
|
||
def test_bitor(): | ||
x: i32 = 5 | ||
y: i32 = 3 | ||
z: i32 = 2147483647 | ||
w: i32 = -2147483648 | ||
|
||
|
||
p: i32 = x | y | ||
q: i32 = y | z | ||
r: i32 = z | w | ||
s: i32 = x | w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == 7) | ||
assert(q == 2147483647) | ||
assert(r == -1) | ||
assert(s == -2147483643) | ||
|
||
def test_bitxor(): | ||
x: i32 = 5 | ||
y: i32 = 3 | ||
z: i32 = 2147483647 | ||
w: i32 = -2147483648 | ||
|
||
|
||
p: i32 = x ^ y | ||
q: i32 = y ^ z | ||
r: i32 = z ^ w | ||
s: i32 = x ^ w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == 6) | ||
assert(q == 2147483644) | ||
assert(r == -1) | ||
assert(s == -2147483643) | ||
|
||
def main0(): | ||
test_bitnot() | ||
test_bitand() | ||
test_bitor() | ||
test_bitxor() | ||
|
||
main0() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from ltypes import i64 | ||
|
||
def test_bitnot(): | ||
x: i64 = i64(123) | ||
y: i64 = i64(456) | ||
z: i64 = i64(115292150460684) | ||
w: i64 = i64(-115292150460685) | ||
|
||
p: i64 = ~x | ||
q: i64 = ~y | ||
r: i64 = ~z | ||
s: i64 = ~w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == i64(-124)) | ||
assert(q == i64(-457)) | ||
assert(r == i64(-115292150460685)) | ||
assert(s == i64(115292150460684)) | ||
|
||
def test_bitand(): | ||
x: i64 = i64(741) | ||
y: i64 = i64(982) | ||
z: i64 = i64(115292150460684) | ||
w: i64 = i64(-115292150460685) | ||
|
||
p: i64 = x & y | ||
q: i64 = y & z | ||
r: i64 = z & w | ||
s: i64 = x & w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == i64(708)) | ||
assert(q == i64(260)) | ||
assert(r == i64(0)) | ||
assert(s == i64(737)) | ||
|
||
def test_bitor(): | ||
x: i64 = i64(741) | ||
y: i64 = i64(982) | ||
z: i64 = i64(115292150460684) | ||
w: i64 = i64(-115292150460685) | ||
|
||
p: i64 = x | y | ||
q: i64 = y | z | ||
r: i64 = z | w | ||
s: i64 = x | w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == i64(1015)) | ||
assert(q == i64(115292150461406)) | ||
assert(r == i64(-1)) | ||
assert(s == i64(-115292150460681)) | ||
|
||
def test_bitxor(): | ||
x: i64 = i64(741) | ||
y: i64 = i64(982) | ||
z: i64 = i64(115292150460684) | ||
w: i64 = i64(-115292150460685) | ||
|
||
p: i64 = x ^ y | ||
q: i64 = y ^ z | ||
r: i64 = z ^ w | ||
s: i64 = x ^ w | ||
|
||
print(p) | ||
print(q) | ||
print(r) | ||
print(s) | ||
|
||
assert(p == i64(307)) | ||
assert(q == i64(115292150461146)) | ||
assert(r == i64(-1)) | ||
assert(s == i64(-115292150461418)) | ||
|
||
def main0(): | ||
test_bitnot() | ||
test_bitand() | ||
test_bitor() | ||
test_bitxor() | ||
|
||
main0() |