Skip to content

Commit

Permalink
chore(brillig): added tests for brillig integer operations (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Jun 7, 2023
1 parent 3c9f106 commit 9a9c461
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.

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]
Empty file.
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
}

0 comments on commit 9a9c461

Please sign in to comment.