Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(brillig): added tests for brillig integer operations #1590

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
authors = [""]
compiler_version = "0.1"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Tests arithmetic operations on integers
fn main() {
let x: u32 = 6;
let y: u32 = 2;

assert((x + y) == add(x, y));

assert((x - y) == sub(x, y));

assert((x * y) == mul(x, y));

assert((x / y) == div(x, y));

// TODO SSA => ACIR has some issues with i32 ops
assert(check_signed_div(6, 2, 3));

assert(eq(1, 2) == false);
assert(eq(1, 1));

assert(lt(x, y) == false);
assert(lt(y, x));

assert((x & y) == and(x, y));
assert((x | y) == or(x, y));

// TODO SSA => ACIR has some issues with xor ops

assert(check_xor(x, y, 4));
assert((x >> y) == shr(x, y));
assert((x << y) == shl(x, y));
}

unconstrained fn add(x : u32, y : u32) -> u32 {
x + y
}

unconstrained fn sub(x : u32, y : u32) -> u32 {
x - y
}

unconstrained fn mul(x : u32, y : u32) -> u32 {
x * y
}

unconstrained fn div(x : u32, y : u32) -> u32 {
x / y
}

unconstrained fn check_signed_div(x: i32, y: i32, result: i32) -> bool {
(x / y) == result
}

unconstrained fn eq(x : u32, y : u32) -> bool {
x == y
}

unconstrained fn lt(x : u32, y : u32) -> bool {
x < y
}

unconstrained fn and(x : u32, y : u32) -> u32 {
x & y
}

unconstrained fn or(x : u32, y : u32) -> u32 {
x | y
}

unconstrained fn check_xor(x : u32, y : u32, result: u32) -> bool {
(x ^ y) == result
}

unconstrained fn shr(x : u32, y : u32) -> u32 {
x >> y
}

unconstrained fn shl(x : u32, y : u32) -> u32 {
x << y
}