From dcc1ef8266b6ef3a9a9db8493f2a43f2c9325a9b Mon Sep 17 00:00:00 2001 From: Maximilian 'NervousNullPtr' Schleicher Date: Mon, 26 May 2025 17:32:49 +0200 Subject: [PATCH 1/2] Fixed #7, #8, #9 --- Cargo.toml | 1 - src/error.rs | 16 ++++++++-------- src/macros/debug.rs | 31 +++++++++++++------------------ src/macros/quantify.rs | 6 +++--- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 368cc3b..94126ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,6 @@ version = "0.10.0" edition = "2021" readme = "readme.md" license = "MIT OR Apache-2.0" -include = ["src/**/*", "README.md", "LICENSE*", "Cargo.toml"] [package.metadata.docs.rs] all-features = true diff --git a/src/error.rs b/src/error.rs index 16e63a6..3e3bc20 100644 --- a/src/error.rs +++ b/src/error.rs @@ -270,15 +270,15 @@ impl QuantorError { #[must_use] pub fn kind(&self) -> QuantorKind { match self { - QuantorError::PredicateFailed { .. } => QuantorKind::Forall, + QuantorError::PredicateFailed { kind, .. } => *kind, QuantorError::EmptyInput { kind } => *kind, - QuantorError::NoMatch { .. } => QuantorKind::Exists, - QuantorError::UnexpectedMatch { .. } => QuantorKind::None, - QuantorError::NotAllEqual { .. } => QuantorKind::AllEqual, - QuantorError::PairwiseFailed { .. } => QuantorKind::Pairwise, - QuantorError::ForAllExistsFailed { .. } => QuantorKind::ForAllExists, - QuantorError::ExistsForAllFailed { .. } => QuantorKind::ExistsForAll, - QuantorError::ExactlyNFailed { .. } => QuantorKind::ExactlyN, + QuantorError::NoMatch { kind, .. } => *kind, + QuantorError::UnexpectedMatch { kind, .. } => *kind, + QuantorError::NotAllEqual { kind, .. } => *kind, + QuantorError::PairwiseFailed { kind, .. } => *kind, + QuantorError::ForAllExistsFailed { kind, .. } => *kind, + QuantorError::ExistsForAllFailed { kind, .. } => *kind, + QuantorError::ExactlyNFailed { kind, .. } => *kind, QuantorError::Custom(_) => QuantorKind::Custom, } } diff --git a/src/macros/debug.rs b/src/macros/debug.rs index 5069966..45a4907 100644 --- a/src/macros/debug.rs +++ b/src/macros/debug.rs @@ -110,18 +110,7 @@ macro_rules! debug_exactly_n { { match $crate::quantifiers::basic::exactly_n($xs, $count, $pred) { Ok(()) => {}, - Err(e) => { - if let Some(found) = e.match_count() { - println!( - "[debug_exactly_n] expected exactly {}, but found {} matching elements.", - $count, found - ); - } else { - println!( - "[debug_exactly_n] quantifier failed, but count information was not available." - ); - } - } + Err(e) => {println!("[debug_exactly_n] {}", e)}, } } }; @@ -168,9 +157,12 @@ macro_rules! debug_none { macro_rules! debug_assert_duplicates { ($xs:expr) => { #[cfg(debug_assertions)] - match $crate::quantifiers::selection::assert_duplicates($xs) { - Ok(()) => {}, - Err(e) => panic!("debug_assert_duplicates! failed: {}", e), + { + let candidates = $crate::quantifiers::selection::select_duplicates($xs); + + if candidates.is_empty() { + panic!("debug_assert_duplicates! failed: {:#?}", candidates) + } } }; } @@ -205,9 +197,12 @@ macro_rules! debug_duplicates { macro_rules! debug_assert_unique { ($xs:expr) => { #[cfg(debug_assertions)] - match $crate::quantifiers::selection::assert_unique($xs) { - Ok(()) => {}, - Err(e) => panic!("debug_assert_unique! failed: {}", e), + { + let candidates = $crate::quantifiers::selection::select_duplicates($xs); + + if !candidates.is_empty() { + panic!("debug_assert_unique! failed: {:#?}", candidates) + } } }; } diff --git a/src/macros/quantify.rs b/src/macros/quantify.rs index 342b941..5955110 100644 --- a/src/macros/quantify.rs +++ b/src/macros/quantify.rs @@ -10,7 +10,7 @@ /// - `exactly_one x in &a => predicate` /// - `exactly_n n x in &a => predicate` /// - `all_equal x in &a => predicate` -/// - `pairwise x in &a => predicate` +/// - `pairwise x,y in &a => predicate` /// - `forallexists x in &a, y in &b => predicate` /// - `existsforall x in &a, y in &b => predicate` /// @@ -60,8 +60,8 @@ macro_rules! quantify { $crate::quantifiers::basic::all_equal($xs) }; - (pairwise $x:ident in $xs:expr => $cond:expr) => { - $crate::quantifiers::basic::pairwise($xs, |$x, x_next| $cond) + (pairwise $x:ident,$y:ident in $xs:expr => $cond:expr) => { + $crate::quantifiers::structured::pairwise($xs, |$x, $y| $cond) }; // Nested From a8ae8e276a46b151ef80d5f19c19f26f99eeb8bc Mon Sep 17 00:00:00 2001 From: Maximilian 'NervousNullPtr' Schleicher Date: Mon, 26 May 2025 17:33:16 +0200 Subject: [PATCH 2/2] Cargo.toml update --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 94126ed..ee97807 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ description = "Declarative quantifiers for filtering, validation, and testing in keywords = ["logic", "validation", "math", "quantifiers"] categories = ["algorithms", "data-structures", "mathematics", "development-tools::testing"] repository = "https://github.com/nervousnullptr/quantor" -version = "0.10.0" +version = "0.10.1" edition = "2021" readme = "readme.md" license = "MIT OR Apache-2.0"