Skip to content

Commit 7292259

Browse files
committed
wrote unit tests for u128/i128 in tests/lib.rs
1 parent afe7ba2 commit 7292259

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

z3/tests/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,3 +1987,32 @@ fn test_model_iter() {
19871987
vec![ast::Dynamic::new_const(&ctx, "a", &Sort::int(&ctx))]
19881988
);
19891989
}
1990+
1991+
#[test]
1992+
fn test_int_i128_u128() {
1993+
let cfg = Config::new();
1994+
let ctx = Context::new(&cfg);
1995+
1996+
let cases_i128: [i128; 4] = [0, 42, -1234567890123456789, i128::MAX];
1997+
let cases_u128: [u128; 3] = [0, 42, u128::MAX];
1998+
1999+
// Check i128
2000+
for &val in &cases_i128 {
2001+
let int_ast = Int::from_i128(&ctx, val);
2002+
let back = int_ast.as_i128().unwrap();
2003+
assert_eq!(back, val, "i128 failed for {}", val);
2004+
}
2005+
2006+
// Check u128
2007+
for &val in &cases_u128 {
2008+
let int_ast = Int::from_u128(&ctx, val);
2009+
let back = int_ast.as_u128().unwrap();
2010+
assert_eq!(back, val, "u128 failed for {}", val);
2011+
}
2012+
2013+
let val: i128 = 12345;
2014+
let int_i = Int::from_i128(&ctx, val);
2015+
let int_u = Int::from_u128(&ctx, val as u128);
2016+
// Both should print the same SMT-LIB numeral string
2017+
assert_eq!(int_i.to_string(), int_u.to_string());
2018+
}

0 commit comments

Comments
 (0)