|
| 1 | +use crate::lib::u16::{checked_add_16, safe_add_16, checked_sub_16, safe_sub_16, checked_mul_16, safe_mul_16, checked_div_16, safe_div_16}; |
| 2 | + |
| 3 | +use crate::helper::if_test_this_function; |
| 4 | + |
| 5 | +// Asserts a `checked_*` result equals the expected Option. |
| 6 | +// `None` encodes the overflow case, `Some(e)` the fitting case, so a single |
| 7 | +// witness value carries both, removing the need for a separate overflow flag. |
| 8 | +fn assert_eq_opt(result: Option<u16>, expected: Option<u16>) { |
| 9 | + match expected { |
| 10 | + None => assert!(is_none::<u16>(result)), |
| 11 | + Some(e: u16) => assert!(jet::eq_16(unwrap(result), e)), |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +fn main() { |
| 16 | + let fn_idx: u8 = witness::FUNCTION_INDEX; |
| 17 | + |
| 18 | + let a: u16 = witness::FIRST_ARG; |
| 19 | + let b: u16 = witness::SECOND_ARG; |
| 20 | + let expected: Option<u16> = witness::EXPECTED; |
| 21 | + |
| 22 | + // add |
| 23 | + match if_test_this_function(0, fn_idx) { true => { assert_eq_opt(checked_add_16(a, b), expected); }, false => (), }; |
| 24 | + match if_test_this_function(1, fn_idx) { true => { assert!(jet::eq_16(safe_add_16(a, b), unwrap(expected))); }, false => (), }; |
| 25 | + |
| 26 | + // sub |
| 27 | + match if_test_this_function(2, fn_idx) { true => { assert_eq_opt(checked_sub_16(a, b), expected); }, false => (), }; |
| 28 | + match if_test_this_function(3, fn_idx) { true => { assert!(jet::eq_16(safe_sub_16(a, b), unwrap(expected))); }, false => (), }; |
| 29 | + |
| 30 | + // mul |
| 31 | + match if_test_this_function(4, fn_idx) { true => { assert_eq_opt(checked_mul_16(a, b), expected); }, false => (), }; |
| 32 | + match if_test_this_function(5, fn_idx) { true => { assert!(jet::eq_16(safe_mul_16(a, b), unwrap(expected))); }, false => (), }; |
| 33 | + |
| 34 | + // div |
| 35 | + match if_test_this_function(6, fn_idx) { true => { assert_eq_opt(checked_div_16(a, b), expected); }, false => (), }; |
| 36 | + match if_test_this_function(7, fn_idx) { true => { assert!(jet::eq_16(safe_div_16(a, b), unwrap(expected))); }, false => (), }; |
| 37 | +} |
0 commit comments