graaf/op/
is_regular.rs

1//! Check whether a digraph is regular.
2//!
3//! A digraph is regular if all vertices have the same indegree and
4//! outdegree.
5//!
6//! # Examples
7//!
8//! ```
9//! use graaf::{
10//!     AdjacencyList,
11//!     Circuit,
12//!     IsRegular,
13//!     RemoveArc,
14//! };
15//!
16//! let mut digraph = AdjacencyList::circuit(7);
17//!
18//! assert!(digraph.is_regular());
19//!
20//! digraph.remove_arc(6, 0);
21//!
22//! assert!(!digraph.is_regular());
23//! ```
24
25/// Check whether a digraph is regular.
26pub trait IsRegular {
27    /// Check whether the digraph is regular.
28    ///
29    /// # Examples
30    ///
31    /// ```
32    /// use graaf::{
33    ///     AdjacencyList,
34    ///     Circuit,
35    ///     IsRegular,
36    ///     RemoveArc,
37    /// };
38    ///
39    /// let mut digraph = AdjacencyList::circuit(7);
40    ///
41    /// assert!(digraph.is_regular());
42    ///
43    /// digraph.remove_arc(6, 0);
44    ///
45    /// assert!(!digraph.is_regular());
46    /// ```
47    #[must_use]
48    fn is_regular(&self) -> bool;
49}
50
51/// `IsRegular` tests
52#[macro_export]
53macro_rules! test_is_regular {
54    ($fixture:path) => {
55        use $fixture::{
56            bang_jensen_196,
57            bang_jensen_34,
58            bang_jensen_94,
59            kattis_builddeps,
60            kattis_cantinaofbabel_1,
61            kattis_cantinaofbabel_2,
62            kattis_escapewallmaria_1,
63            kattis_escapewallmaria_2,
64            kattis_escapewallmaria_3,
65        };
66
67        #[test]
68        fn is_regular_bang_jensen_196() {
69            assert!(!bang_jensen_196().is_regular());
70        }
71
72        #[test]
73        fn is_regular_bang_jensen_34() {
74            assert!(!bang_jensen_34().is_regular());
75        }
76
77        #[test]
78        fn is_regular_bang_jensen_94() {
79            assert!(!bang_jensen_94().is_regular());
80        }
81
82        #[test]
83        fn is_regular_kattis_builddeps() {
84            assert!(!kattis_builddeps().is_regular());
85        }
86
87        #[test]
88        fn is_regular_kattis_cantinaofbabel_1() {
89            assert!(!kattis_cantinaofbabel_1().is_regular());
90        }
91
92        #[test]
93        fn is_regular_kattis_cantinaofbabel_2() {
94            assert!(!kattis_cantinaofbabel_2().is_regular());
95        }
96
97        #[test]
98        fn is_regular_kattis_escapewallmaria_1() {
99            assert!(!kattis_escapewallmaria_1().is_regular());
100        }
101
102        #[test]
103        fn is_regular_kattis_escapewallmaria_2() {
104            assert!(!kattis_escapewallmaria_2().is_regular());
105        }
106
107        #[test]
108        fn is_regular_kattis_escapewallmaria_3() {
109            assert!(!kattis_escapewallmaria_3().is_regular());
110        }
111    };
112}