(first: u64, second: u64, st: ScalarType)
| 342 | use crate::graphs::util::simple_context; |
| 343 | |
| 344 | fn test_helper(first: u64, second: u64, st: ScalarType) -> Result<()> { |
| 345 | let bits = st.size_in_bits(); |
| 346 | let mask = (1u128 << bits) - 1; |
| 347 | let first = (first as u128) & mask; |
| 348 | let second = (second as u128) & mask; |
| 349 | |
| 350 | let c = simple_context(|g| { |
| 351 | let i1 = g.input(array_type(vec![bits], BIT))?; |
| 352 | let i2 = g.input(array_type(vec![bits], BIT))?; |
| 353 | let o = g.custom_op( |
| 354 | CustomOperation::new(BinaryAdd { |
| 355 | overflow_bit: false, |
| 356 | }), |
| 357 | vec![i1, i2], |
| 358 | )?; |
| 359 | assert_eq!( |
| 360 | o.get_type()?.get_dimensions(), |
| 361 | vec![bits], |
| 362 | "{first} + {second} with {bits} bits" |
| 363 | ); |
| 364 | Ok(o) |
| 365 | })?; |
| 366 | let mapped_c = run_instantiation_pass(c)?; |
| 367 | let input0 = Value::from_scalar(first, st)?; |
| 368 | let input1 = Value::from_scalar(second, st)?; |
| 369 | let result_v = random_evaluate( |
| 370 | mapped_c.get_context().get_main_graph()?, |
| 371 | vec![input0, input1], |
| 372 | )? |
| 373 | .to_u128(st)?; |
| 374 | |
| 375 | let expected_result = first.wrapping_add(second) & mask; |
| 376 | assert_eq!( |
| 377 | result_v, expected_result, |
| 378 | "{first} + {second} with {bits} bits" |
| 379 | ); |
| 380 | Ok(()) |
| 381 | } |
| 382 | |
| 383 | #[test] |
| 384 | fn test_random_inputs() -> Result<()> { |
no test coverage detected