MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / test_helper

Function test_helper

ciphercore-base/src/ops/adder.rs:344–381  ·  view source on GitHub ↗
(first: u64, second: u64, st: ScalarType)

Source from the content-addressed store, hash-verified

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<()> {

Callers 1

test_random_inputsFunction · 0.70

Calls 10

simple_contextFunction · 0.85
run_instantiation_passFunction · 0.85
random_evaluateFunction · 0.85
array_typeFunction · 0.50
size_in_bitsMethod · 0.45
inputMethod · 0.45
custom_opMethod · 0.45
to_u128Method · 0.45
get_main_graphMethod · 0.45
get_contextMethod · 0.45

Tested by

no test coverage detected