leo/tests/compiler/mutability/swap.leo
2021-05-03 16:47:33 +03:00

27 lines
517 B
Plaintext

/*
namespace: Compile
expectation: Pass
inputs:
- swap.in: |
[main]
arr: [u32; 2] = [10, 8];
[registers]
r0: bool = false;
*/
// Swap two elements of an array.
function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] {
const t = a[i];
a[i] = a[j];
a[j] = t;
return a;
}
function main(arr: [u32; 2]) -> bool {
const expected: [u32; 2] = [1, 0];
const actual = swap(arr, 0, 1);
// Do swap.
return expected[0] == actual[0] && expected[1] == actual[1];
}