Skip to content

Commit 47c83c4

Browse files
committed
fix clippy lints in tests
1 parent 3a8045f commit 47c83c4

File tree

5 files changed

+44
-47
lines changed

5 files changed

+44
-47
lines changed

z3-sys/tests/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,13 @@ fn smoketest() {
3939
// Grab the actual constant values out of the model
4040
let mut interp_x: Z3_ast = const_x;
4141
let mut interp_y: Z3_ast = const_y;
42-
assert_eq!(
43-
Z3_model_eval(ctx, model, const_x, true, &mut interp_x),
44-
true
45-
);
46-
assert_eq!(
47-
Z3_model_eval(ctx, model, const_y, true, &mut interp_y),
48-
true
49-
);
42+
assert!(Z3_model_eval(ctx, model, const_x, true, &mut interp_x));
43+
assert!(Z3_model_eval(ctx, model, const_y, true, &mut interp_y));
5044

5145
let mut val_x: i32 = -5;
5246
let mut val_y: i32 = -5;
53-
assert_eq!(Z3_get_numeral_int(ctx, interp_x, &mut val_x), true);
54-
assert_eq!(Z3_get_numeral_int(ctx, interp_y, &mut val_y), true);
47+
assert!(Z3_get_numeral_int(ctx, interp_x, &mut val_x));
48+
assert!(Z3_get_numeral_int(ctx, interp_y, &mut val_y));
5549
assert_eq!(val_x, 0);
5650
assert_eq!(val_y, -1);
5751

z3/tests/lib.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ fn test_floating_point_bits() {
181181
assert!(sig64 == Some(53));
182182
assert!(exp128 == Some(15));
183183
assert!(sig128 == Some(113));
184-
assert!(expi == None);
185-
assert!(sigi == None);
184+
assert!(expi.is_none());
185+
assert!(sigi.is_none());
186186
}
187187

188188
#[test]
@@ -361,7 +361,7 @@ fn test_float_add() {
361361

362362
let x = ast::Float::new_const_float32(&ctx, "x");
363363
let x_plus_one = ast::Float::round_towards_zero(&ctx).add(&x, &ast::Float::from_f32(&ctx, 1.0));
364-
let y = ast::Float::from_f32(&ctx, 3.14);
364+
let y = ast::Float::from_f32(&ctx, std::f32::consts::PI);
365365

366366
solver.assert(&x_plus_one._eq(&y));
367367
assert_eq!(solver.check(), SatResult::Sat);
@@ -994,12 +994,12 @@ fn test_goal_is_inconsistent() {
994994
let false_bool = ast::Bool::from_bool(&ctx, false);
995995
let goal = Goal::new(&ctx, false, false, false);
996996
goal.assert(&false_bool);
997-
assert_eq!(goal.is_inconsistent(), true);
997+
assert!(goal.is_inconsistent());
998998

999999
let true_bool = ast::Bool::from_bool(&ctx, true);
10001000
let goal = Goal::new(&ctx, false, false, false);
10011001
goal.assert(&true_bool);
1002-
assert_eq!(goal.is_inconsistent(), false);
1002+
assert!(!goal.is_inconsistent());
10031003
}
10041004

10051005
#[test]
@@ -1010,14 +1010,14 @@ fn test_goal_is_sat() {
10101010
let false_bool = ast::Bool::from_bool(&ctx, false);
10111011
let goal = Goal::new(&ctx, false, false, false);
10121012
goal.assert(&false_bool);
1013-
assert_eq!(goal.is_decided_sat(), false);
1014-
assert_eq!(goal.is_decided_unsat(), true);
1013+
assert!(!goal.is_decided_sat());
1014+
assert!(goal.is_decided_unsat());
10151015

10161016
let true_bool = ast::Bool::from_bool(&ctx, true);
10171017
let goal = Goal::new(&ctx, false, false, false);
10181018
goal.assert(&true_bool);
1019-
assert_eq!(goal.is_decided_unsat(), false);
1020-
assert_eq!(goal.is_decided_sat(), true);
1019+
assert!(!goal.is_decided_unsat());
1020+
assert!(goal.is_decided_sat());
10211021
}
10221022

10231023
#[test]
@@ -1255,10 +1255,10 @@ fn test_goal_apply_tactic() {
12551255
after_formulas: Vec<Bool>,
12561256
) {
12571257
assert_eq!(goal.get_formulas::<Bool>(), before_formulas);
1258-
let params = Params::new(&ctx);
1258+
let params = Params::new(ctx);
12591259

1260-
let tactic = Tactic::new(&ctx, "sat-preprocess");
1261-
let repeat_tactic = Tactic::repeat(&ctx, &tactic, 100);
1260+
let tactic = Tactic::new(ctx, "sat-preprocess");
1261+
let repeat_tactic = Tactic::repeat(ctx, &tactic, 100);
12621262
let apply_results = repeat_tactic.apply(&goal, Some(&params));
12631263
let goal_results = apply_results
12641264
.unwrap()
@@ -1525,11 +1525,11 @@ fn test_ast_safe_decl() {
15251525
let x_not = x.not();
15261526
assert_eq!(x_not.safe_decl().unwrap().kind(), DeclKind::NOT);
15271527

1528-
let f = FuncDecl::new(&ctx, "f", &[&Sort::int(&ctx)], &Sort::int(ctx));
1529-
let x = ast::Int::new_const(&ctx, "x");
1528+
let f = FuncDecl::new(ctx, "f", &[&Sort::int(ctx)], &Sort::int(ctx));
1529+
let x = ast::Int::new_const(ctx, "x");
15301530
let f_x: ast::Int = f.apply(&[&x]).try_into().unwrap();
1531-
let f_x_pattern: Pattern = Pattern::new(&ctx, &[&f_x]);
1532-
let forall = ast::forall_const(&ctx, &[&x], &[&f_x_pattern], &x._eq(&f_x));
1531+
let f_x_pattern: Pattern = Pattern::new(ctx, &[&f_x]);
1532+
let forall = ast::forall_const(ctx, &[&x], &[&f_x_pattern], &x._eq(&f_x));
15331533
assert!(forall.safe_decl().is_err());
15341534
assert_eq!(
15351535
format!("{}", forall.safe_decl().err().unwrap()),
@@ -1542,16 +1542,22 @@ fn test_ast_safe_decl() {
15421542
fn test_regex_capital_foobar_intersect_az_plus_is_unsat() {
15431543
let cfg = Config::new();
15441544
let ctx = &Context::new(&cfg);
1545-
let solver = Solver::new(&ctx);
1545+
let solver = Solver::new(ctx);
15461546
let s = ast::String::new_const(ctx, "s");
15471547

1548-
let re = ast::Regexp::intersect(ctx, &[
1549-
&ast::Regexp::concat(ctx, &[
1550-
&ast::Regexp::literal(ctx, "FOO"),
1551-
&ast::Regexp::literal(ctx, "bar")
1552-
]),
1553-
&ast::Regexp::plus(&ast::Regexp::range(ctx, &'a', &'z'))
1554-
]);
1548+
let re = ast::Regexp::intersect(
1549+
ctx,
1550+
&[
1551+
&ast::Regexp::concat(
1552+
ctx,
1553+
&[
1554+
&ast::Regexp::literal(ctx, "FOO"),
1555+
&ast::Regexp::literal(ctx, "bar"),
1556+
],
1557+
),
1558+
&ast::Regexp::plus(&ast::Regexp::range(ctx, &'a', &'z')),
1559+
],
1560+
);
15551561
solver.assert(&s.regex_matches(&re));
15561562
assert!(solver.check() == SatResult::Unsat);
15571563
}

z3/tests/objectives.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ fn test_optimize_assert_soft_and_get_objectives() {
152152
}
153153

154154
assert_eq!(
155-
*&ite_children[1].as_real().unwrap().as_real().unwrap(),
155+
ite_children[1].as_real().unwrap().as_real().unwrap(),
156156
(0, 1)
157157
);
158158
assert_eq!(
159-
*&ite_children[2].as_real().unwrap().as_real().unwrap(),
159+
ite_children[2].as_real().unwrap().as_real().unwrap(),
160160
(1, 1)
161161
);
162162
}

z3/tests/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ fn test_ast_children() {
225225

226226
fn assert_ast_attributes<'c, T: Ast<'c>>(expr: &T, is_const: bool) {
227227
assert_eq!(expr.kind(), AstKind::App);
228-
assert_eq!(expr.is_app(), true);
228+
assert!(expr.is_app());
229229
assert_eq!(expr.is_const(), is_const);
230230
}
231231

z3/tests/semver_tests.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ impl Spec {
3030
type SpecMap = HashMap<String, Vec<Spec>>;
3131

3232
fn get_version(sm: &SpecMap, pkg: &str, ver: usize) -> Option<Version> {
33-
match sm.get(pkg) {
34-
None => None,
35-
Some(specs) => Some(specs[ver].vers.clone()),
36-
}
33+
sm.get(pkg).map(|specs| specs[ver].vers.clone())
3734
}
3835

3936
fn first_version_req_index(sm: &SpecMap, pkg: &str, req: &VersionReq) -> Option<usize> {
@@ -191,15 +188,15 @@ fn test_solve_simple_semver_example() {
191188
));
192189

193190
// Ensure we have a constant for every pkg _or_ dep listed
194-
for k in (&smap).keys() {
191+
for k in (smap).keys() {
195192
asts.entry(k.clone()).or_insert_with(|| {
196193
info!("new AST for {}", k);
197194
ast::Int::fresh_const(&ctx, "pkg")
198195
});
199196
}
200197
for specs in smap.values() {
201198
for spec in specs {
202-
for r in (&spec).reqs.keys() {
199+
for r in (spec).reqs.keys() {
203200
asts.entry(r.clone()).or_insert_with(|| {
204201
info!("new AST for {}", r);
205202
ast::Int::fresh_const(&ctx, "dep-pkg")
@@ -223,10 +220,10 @@ fn test_solve_simple_semver_example() {
223220
"Asserting: {} == #{} {} => {} >= #{} {}",
224221
k,
225222
n,
226-
get_version(&smap, k, n as usize).unwrap(),
223+
get_version(&smap, k, n).unwrap(),
227224
r,
228225
low,
229-
get_version(&smap, r, low as usize).unwrap()
226+
get_version(&smap, r, low).unwrap()
230227
);
231228
opt.assert(
232229
&k_ast
@@ -242,10 +239,10 @@ fn test_solve_simple_semver_example() {
242239
"Asserting: {} == #{} {} => {} <= #{} {}",
243240
k,
244241
n,
245-
get_version(&smap, k, n as usize).unwrap(),
242+
get_version(&smap, k, n).unwrap(),
246243
r,
247244
high,
248-
get_version(&smap, r, high as usize).unwrap()
245+
get_version(&smap, r, high).unwrap()
249246
);
250247
opt.assert(
251248
&k_ast

0 commit comments

Comments
 (0)