From 18d7dd58c9542e0db5ee712babf1f563cd7f5ed3 Mon Sep 17 00:00:00 2001 From: Samuel Pastva Date: Mon, 12 Aug 2024 22:16:54 +0200 Subject: [PATCH] Clippy suggestions. --- src/_impl_bdd/_impl_util.rs | 4 ++-- src/_impl_bdd_satisfying_valuations.rs | 18 ++++++------------ src/_impl_bdd_valuation.rs | 8 ++++---- src/_test_bdd/_test_bdd_logic_basic.rs | 8 ++++---- src/_test_bdd/_test_bdd_logic_fuzzing.rs | 20 ++++++++++---------- src/_test_bdd/_test_bdd_ops_with_limit.rs | 6 +++--- src/_test_bdd/_test_bdd_relation_ops.rs | 4 ++-- src/_test_util.rs | 6 +++--- src/tutorial/p05_bdd_valuations.rs | 10 +++++----- 9 files changed, 39 insertions(+), 45 deletions(-) diff --git a/src/_impl_bdd/_impl_util.rs b/src/_impl_bdd/_impl_util.rs index 84e6c66..121c614 100644 --- a/src/_impl_bdd/_impl_util.rs +++ b/src/_impl_bdd/_impl_util.rs @@ -712,7 +712,7 @@ mod tests { // Missing zero. assert!(Bdd::from_nodes(&nodes[1..]).is_err()); // Missing one. - assert!(Bdd::from_nodes(&vec![nodes[0].clone(), nodes[2].clone()]).is_err()); + assert!(Bdd::from_nodes(&[nodes[0], nodes[2]]).is_err()); let mut nodes = bdd.clone().to_nodes(); nodes[0].var = BddVariable(1); @@ -956,7 +956,7 @@ mod tests { bdd.rename_variable(BddVariable(2), BddVariable(0)); bdd.rename_variable(BddVariable(3), BddVariable(4)); } - let expected = HashSet::from_iter(vec![BddVariable(0), BddVariable(4)].into_iter()); + let expected = HashSet::from_iter(vec![BddVariable(0), BddVariable(4)]); assert_eq!(expected, bdd.support_set()); } diff --git a/src/_impl_bdd_satisfying_valuations.rs b/src/_impl_bdd_satisfying_valuations.rs index 3d714b6..bda7f05 100644 --- a/src/_impl_bdd_satisfying_valuations.rs +++ b/src/_impl_bdd_satisfying_valuations.rs @@ -125,12 +125,9 @@ mod tests { expected.sort(); assert_eq!(sat_valuations.len(), 16); - sat_valuations - .into_iter() - .zip(expected.into_iter()) - .for_each(|(a, b)| { - assert_eq!(a, b); - }); + sat_valuations.into_iter().zip(expected).for_each(|(a, b)| { + assert_eq!(a, b); + }); } #[test] @@ -147,12 +144,9 @@ mod tests { expected.sort(); assert_eq!(sat_valuations.len(), expected.len()); - sat_valuations - .into_iter() - .zip(expected.into_iter()) - .for_each(|(a, b)| { - assert_eq!(a, b); - }); + sat_valuations.into_iter().zip(expected).for_each(|(a, b)| { + assert_eq!(a, b); + }); } #[test] diff --git a/src/_impl_bdd_valuation.rs b/src/_impl_bdd_valuation.rs index 0d8b465..c78504b 100644 --- a/src/_impl_bdd_valuation.rs +++ b/src/_impl_bdd_valuation.rs @@ -253,10 +253,10 @@ mod tests { let v1 = universe.mk_var_by_name("x_0"); let v2 = universe.mk_var_by_name("x_1"); let bdd = bdd!(v1 & (!v2)); - assert_eq!(true, bdd.eval_in(&BddValuation::new(vec![true, false]))); - assert_eq!(false, bdd.eval_in(&BddValuation::new(vec![true, true]))); - assert_eq!(false, bdd.eval_in(&BddValuation::new(vec![false, false]))); - assert_eq!(false, bdd.eval_in(&BddValuation::new(vec![false, false]))); + assert!(bdd.eval_in(&BddValuation::new(vec![true, false]))); + assert!(!bdd.eval_in(&BddValuation::new(vec![true, true]))); + assert!(!bdd.eval_in(&BddValuation::new(vec![false, false]))); + assert!(!bdd.eval_in(&BddValuation::new(vec![false, false]))); } #[test] diff --git a/src/_test_bdd/_test_bdd_logic_basic.rs b/src/_test_bdd/_test_bdd_logic_basic.rs index d733dc0..803408d 100644 --- a/src/_test_bdd/_test_bdd_logic_basic.rs +++ b/src/_test_bdd/_test_bdd_logic_basic.rs @@ -2,16 +2,16 @@ use crate::_test_util::{mk_5_variable_set, mk_small_test_bdd}; use crate::*; fn v1() -> BddVariable { - return BddVariable(0); + BddVariable(0) } fn v2() -> BddVariable { - return BddVariable(1); + BddVariable(1) } fn v3() -> BddVariable { - return BddVariable(2); + BddVariable(2) } fn v4() -> BddVariable { - return BddVariable(3); + BddVariable(3) } #[test] diff --git a/src/_test_bdd/_test_bdd_logic_fuzzing.rs b/src/_test_bdd/_test_bdd_logic_fuzzing.rs index 3ebffe9..0b3a65c 100644 --- a/src/_test_bdd/_test_bdd_logic_fuzzing.rs +++ b/src/_test_bdd/_test_bdd_logic_fuzzing.rs @@ -73,13 +73,13 @@ impl BddOpTree { }) .collect(); levels.push(level); - level_width = level_width / 2; + level_width /= 2; } - return BddOpTree { + BddOpTree { leaves, ops: levels, - }; + } } /// Evaluate this op tree to `Bdd` using the given `BddVariableSet`. @@ -94,11 +94,11 @@ impl BddOpTree { let b = &formulas[i + 1]; let op = &level[i / 2]; let result = match op.op { - BddOp::AND => a.and(&b), - BddOp::OR => a.or(&b), - BddOp::XOR => a.xor(&b), - BddOp::IMP => a.imp(&b), - BddOp::IFF => a.iff(&b), + BddOp::AND => a.and(b), + BddOp::OR => a.or(b), + BddOp::XOR => a.xor(b), + BddOp::IMP => a.imp(b), + BddOp::IFF => a.iff(b), }; if op.negate { new_formulas.push(result.not()) @@ -110,7 +110,7 @@ impl BddOpTree { formulas = new_formulas; } - return formulas[0].clone(); + formulas[0].clone() } /// Evaluate this op tree with the specified `BddValuation`. @@ -141,7 +141,7 @@ impl BddOpTree { values = new_values; } - return values[0]; + values[0] } } diff --git a/src/_test_bdd/_test_bdd_ops_with_limit.rs b/src/_test_bdd/_test_bdd_ops_with_limit.rs index 95d0eb0..b4ce775 100644 --- a/src/_test_bdd/_test_bdd_ops_with_limit.rs +++ b/src/_test_bdd/_test_bdd_ops_with_limit.rs @@ -3,13 +3,13 @@ use crate::op_function::and; use crate::{bdd, Bdd, BddVariable}; fn v1() -> BddVariable { - return BddVariable(0); + BddVariable(0) } fn v2() -> BddVariable { - return BddVariable(1); + BddVariable(1) } fn v3() -> BddVariable { - return BddVariable(2); + BddVariable(2) } #[test] diff --git a/src/_test_bdd/_test_bdd_relation_ops.rs b/src/_test_bdd/_test_bdd_relation_ops.rs index 92f5eaf..a1afb40 100644 --- a/src/_test_bdd/_test_bdd_relation_ops.rs +++ b/src/_test_bdd/_test_bdd_relation_ops.rs @@ -10,13 +10,13 @@ fn vars() -> ( BddVariable, BddVariable, ) { - return ( + ( BddVariable(0), BddVariable(1), BddVariable(2), BddVariable(3), BddVariable(4), - ); + ) } #[test] diff --git a/src/_test_util.rs b/src/_test_util.rs index 977aa4e..afa593d 100644 --- a/src/_test_util.rs +++ b/src/_test_util.rs @@ -13,7 +13,7 @@ pub fn mk_small_test_bdd() -> Bdd { BddPointer::zero(), bdd.root_pointer(), )); - return bdd; + bdd } /// Make a new `BddVariableSet` with variables $v_1, v_2, v_3, v_4, v_5$. @@ -22,6 +22,6 @@ pub fn mk_5_variable_set() -> BddVariableSet { } pub fn load_expected_results(test_name: &str) -> String { - return std::fs::read_to_string(format!("res/test_results/{}", test_name)) - .expect("Cannot open result file."); + std::fs::read_to_string(format!("res/test_results/{}", test_name)) + .expect("Cannot open result file.") } diff --git a/src/tutorial/p05_bdd_valuations.rs b/src/tutorial/p05_bdd_valuations.rs index 2bc4299..eee9f1d 100644 --- a/src/tutorial/p05_bdd_valuations.rs +++ b/src/tutorial/p05_bdd_valuations.rs @@ -68,14 +68,14 @@ //! some of the following methods to obtain some insight into the structure of the `Bdd`: //! //! - `Bdd.first_valuation` and `Bdd.last_valuation` will give you the (lexicographically) first -//! and last valuation. +//! and last valuation. //! - Similarly, `Bdd.first_clause` and `Bdd.last_clause` will give you the first and last path -//! satisfying path. +//! satisfying path. //! - `Bdd.most_positive_valuation` and `Bdd.most_negative_valuation` return the valuations -//! with the highest amount of positive/negative literals. +//! with the highest amount of positive/negative literals. //! - `Bdd.most_fixed_clause` and `Bdd.most_free_clause` wil give you satisfying paths with -//! greatest and least amount of fixed variables respectively. +//! greatest and least amount of fixed variables respectively. //! - `Bdd.random_valuation` and `Bdd.random_clause` allow selecting valuation/clause using -//! a random number generator. +//! a random number generator. //! //!