Skip to content

Commit f7a1da6

Browse files
committed
Improve tests for single-array-as-multiple-parties case
1 parent ac57924 commit f7a1da6

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

tests/compile.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,26 @@ pub fn main(_x: i32) -> i32 {
23502350
}
23512351

23522352
#[test]
2353-
fn compile_single_array_as_multiple_parties() -> Result<(), Error> {
2353+
fn compile_single_array_as_3_parties() -> Result<(), Error> {
2354+
let prg = "
2355+
pub fn main(parties: [u32; 3]) -> u32 {
2356+
parties[0] + parties[1] + parties[2]
2357+
}";
2358+
let compiled = compile(prg).map_err(|e| pretty_print(e, prg))?;
2359+
let mut eval = compiled.evaluator();
2360+
eval.set_u32(2);
2361+
eval.set_u32(4);
2362+
eval.set_u32(6);
2363+
let output = eval.run().map_err(|e| pretty_print(e, prg))?;
2364+
assert_eq!(
2365+
u32::try_from(output).map_err(|e| pretty_print(e, prg))?,
2366+
2 + 4 + 6,
2367+
);
2368+
Ok(())
2369+
}
2370+
2371+
#[test]
2372+
fn compile_single_array_as_4_parties() -> Result<(), Error> {
23542373
let prg = "
23552374
pub fn main(parties: [u32; 4]) -> u32 {
23562375
let mut result = 0u32;
@@ -2376,31 +2395,22 @@ pub fn main(parties: [u32; 4]) -> u32 {
23762395
#[test]
23772396
fn compile_single_array_with_const_size_as_multiple_parties() -> Result<(), Error> {
23782397
let prg = "
2379-
const MY_CONST: usize = max(PARTY_0::MY_CONST, PARTY_1::MY_CONST);
2380-
pub fn main(array: [u16; MY_CONST]) -> u16 {
2398+
const PARTIES: usize = PARTIES::TOTAL;
2399+
pub fn main(array: [u16; PARTIES]) -> u16 {
23812400
let mut result = 0u16;
23822401
for elem in array {
23832402
result = result + elem;
23842403
}
23852404
result
23862405
}
23872406
";
2388-
let consts = HashMap::from_iter(vec![
2389-
(
2390-
"PARTY_0".to_string(),
2391-
HashMap::from_iter(vec![(
2392-
"MY_CONST".to_string(),
2393-
Literal::NumUnsigned(1, UnsignedNumType::Usize),
2394-
)]),
2395-
),
2396-
(
2397-
"PARTY_1".to_string(),
2398-
HashMap::from_iter(vec![(
2399-
"MY_CONST".to_string(),
2400-
Literal::NumUnsigned(3, UnsignedNumType::Usize),
2401-
)]),
2402-
),
2403-
]);
2407+
let consts = HashMap::from_iter(vec![(
2408+
"PARTIES".to_string(),
2409+
HashMap::from_iter(vec![(
2410+
"TOTAL".to_string(),
2411+
Literal::NumUnsigned(3, UnsignedNumType::Usize),
2412+
)]),
2413+
)]);
24042414
let compiled = compile_with_constants(prg, consts).map_err(|e| pretty_print(e, prg))?;
24052415
let mut eval = compiled.evaluator();
24062416
eval.set_u16(2);

0 commit comments

Comments
 (0)