Skip to content

Commit

Permalink
TEST: BitOperations: Add and enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Jan 24, 2023
1 parent aff81f5 commit 725a580
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 1 deletion.
4 changes: 3 additions & 1 deletion integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ RUN(NAME test_complex LABELS cpython llvm c)
RUN(NAME test_max_min LABELS cpython llvm c)
RUN(NAME test_global LABELS cpython llvm c)
RUN(NAME test_global_decl LABELS cpython llvm c)
RUN(NAME test_integer_bitnot LABELS cpython llvm c)
RUN(NAME test_integer_bitnot LABELS cpython llvm c wasm)
RUN(NAME test_ifexp LABELS cpython llvm c)
RUN(NAME test_unary_minus LABELS cpython llvm c)
RUN(NAME test_unary_plus LABELS cpython llvm c)
Expand Down Expand Up @@ -417,5 +417,7 @@ RUN(NAME func_dep_04 LABELS cpython llvm c)
RUN(NAME float_01 LABELS cpython llvm wasm wasm_x64)
RUN(NAME recursive_01 LABELS cpython llvm wasm wasm_x64 wasm_x86)
RUN(NAME comp_01 LABELS cpython llvm wasm wasm_x64)
RUN(NAME bit_operations_i32 LABELS cpython llvm wasm)
RUN(NAME bit_operations_i64 LABELS cpython llvm wasm)

RUN(NAME test_argv_01 LABELS llvm) # TODO: Test using CPython
96 changes: 96 additions & 0 deletions integration_tests/bit_operations_i32.py
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()
93 changes: 93 additions & 0 deletions integration_tests/bit_operations_i64.py
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()

0 comments on commit 725a580

Please sign in to comment.