Skip to content

Commit

Permalink
Adding vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
codingnirvana committed Aug 16, 2023
1 parent d262350 commit 70321d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Nargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "noir_basics"
entry = "hash.nr"
entry = "vectors.nr"
type = "bin"
authors = [""]
compiler_version = "0.9.0"
Expand Down
4 changes: 0 additions & 4 deletions crypto_primitives/src/hash.nr

This file was deleted.

37 changes: 37 additions & 0 deletions vectors.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use dep::std::collections::vec::Vec;

fn main(x: Field, y: pub Field) {
let mut vector = Vec::new();

assert(vector.len() == 0);
for i in 0..5 {
vector.push(i);
}
assert(vector.len() == 5);
for i in 0..5 {
assert(i == vector.get(i));
}

let last_elem = vector.pop();
assert(last_elem == 4);
assert(vector.len() == 4);

vector.insert(2, 100);
assert(vector.get(2) == 100);
assert(vector.get(4) == 3);
assert(vector.len() == 5);

let removed_elem = vector.remove(3);
assert(removed_elem == 2);
assert(vector.get(3) == 3);
assert(vector.len() == 4);

let mut inputs_vector = Vec::from_slice([x, y]);
assert(inputs_vector.get(0) == x);
assert(inputs_vector.get(1) == y);
}

#[test]
fn test_vectors() {
main(5, 10);
}

0 comments on commit 70321d4

Please sign in to comment.