summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora14m <[email protected]>2021-04-07 18:53:18 +0200
committera14m <[email protected]>2021-04-07 18:54:03 +0200
commit6cdcb8a1ce50883cc3e0af5bf89766b910931040 (patch)
tree9c280c3c961ebafefcf276d37904cbf61ae0789b
parentb087dea8fde79d48f14684f7415c493b917f5c64 (diff)
Add the len method to the plane
-rw-r--r--CLI/rust/src/game_of_life/simulation/plane.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/CLI/rust/src/game_of_life/simulation/plane.rs b/CLI/rust/src/game_of_life/simulation/plane.rs
index 21c34cf..11d7ee5 100644
--- a/CLI/rust/src/game_of_life/simulation/plane.rs
+++ b/CLI/rust/src/game_of_life/simulation/plane.rs
@@ -8,6 +8,24 @@ use std::ops::{Index, IndexMut};
#[derive(Debug, Clone, PartialEq)]
pub(crate) struct Plane<T>(pub Vec<T>);
+impl<T> Plane<T> {
+ pub fn len(&self) -> isize {
+ self.0.len() as isize
+ }
+}
+
+#[cfg(test)]
+mod len {
+ use super::*;
+
+ #[test]
+ fn get_len() {
+ assert_eq!(Plane(vec![false, false, true, false, false]).len(), 5);
+ assert_eq!(Plane(vec![false, false, true, false]).len(), 4);
+ assert_eq!(Plane(vec![false, false, true]).len(), 3);
+ }
+}
+
impl<T> Index<isize> for Plane<T> {
type Output = T;
fn index(&self, idx: isize) -> &T {