-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(brillig): added tests for brillig integer operations (#1590)
- Loading branch information
1 parent
3c9f106
commit 9a9c461
Showing
4 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
...s/nargo_cli/tests/test_data_ssa_refactor/brillig_field_binary_operations/target/test.json
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_integer_binary_operations/Nargo.toml
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,5 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
|
||
[dependencies] |
Empty file.
80 changes: 80 additions & 0 deletions
80
crates/nargo_cli/tests/test_data_ssa_refactor/brillig_integer_binary_operations/src/main.nr
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,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 | ||
} | ||
|