mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
All operators finished
This commit is contained in:
@@ -92,6 +92,25 @@ describe("basic cases", function () {
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while unrolled", async () => {
|
||||
await doTest(
|
||||
"whileunrolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: [0,1,2]}],
|
||||
[{in: 10}, {out: [10, 11, 12]}],
|
||||
[{in: __P__.minus(2)}, {out: [__P__.minus(2), __P__.minus(1), 0]}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("while rolled", async () => {
|
||||
await doTest(
|
||||
"whilerolled.circom",
|
||||
[
|
||||
[{in: 0}, {out: 0}],
|
||||
[{in: 10}, {out: 10}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("function1", async () => {
|
||||
await doTest(
|
||||
"function1.circom",
|
||||
@@ -246,4 +265,26 @@ describe("basic cases", function () {
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Conditional Ternary operator", async () => {
|
||||
await doTest(
|
||||
"condternary.circom",
|
||||
[
|
||||
[{in: 0}, {out: 21}],
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 23}],
|
||||
[{in:-1}, {out: 20}],
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Compute block", async () => {
|
||||
await doTest(
|
||||
"compute.circom",
|
||||
[
|
||||
[{x: 1}, {y: 7}],
|
||||
[{x: 2}, {y: 7}],
|
||||
[{x: 3}, {y: 11}],
|
||||
[{x:-1}, {y: -5}],
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
15
test/circuits/condternary.circom
Normal file
15
test/circuits/condternary.circom
Normal file
@@ -0,0 +1,15 @@
|
||||
template CondTernary() {
|
||||
signal input in;
|
||||
signal output out;
|
||||
|
||||
var a = 3;
|
||||
var b = a==3 ? 1 : 2; // b is 1
|
||||
var c = a!=3 ? 10 : 20; // c is 20
|
||||
var d = b+c; // d is 21
|
||||
|
||||
|
||||
out <-- ((in & 1) != 1) ? in + d : in; // Add 21 if in is pair
|
||||
|
||||
}
|
||||
|
||||
component main = CondTernary()
|
||||
16
test/circuits/whilerolled.circom
Normal file
16
test/circuits/whilerolled.circom
Normal file
@@ -0,0 +1,16 @@
|
||||
template WhileRolled() {
|
||||
signal input in;
|
||||
signal output out;
|
||||
|
||||
var acc = 0;
|
||||
|
||||
var i=0;
|
||||
while (i<in) {
|
||||
acc = acc + 1;
|
||||
i++
|
||||
}
|
||||
|
||||
out <== acc;
|
||||
}
|
||||
|
||||
component main = WhileRolled();
|
||||
12
test/circuits/whileunrolled.circom
Normal file
12
test/circuits/whileunrolled.circom
Normal file
@@ -0,0 +1,12 @@
|
||||
template WhileUnrolled(n) {
|
||||
signal input in;
|
||||
signal output out[n];
|
||||
|
||||
var i=0;
|
||||
while (i<n) {
|
||||
out[i] <== in + i;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
component main = WhileUnrolled(3);
|
||||
Reference in New Issue
Block a user