From df50cf621b4cbab40094de2a438cdd45f7684c08 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Tue, 19 Mar 2024 22:10:33 +0100 Subject: [PATCH] simplify projection tests: remove unnecessary unwrap --- src/projection/list2seq.rs | 32 ++++++++++++++++++-------------- src/projection/vec2list.rs | 33 +++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/projection/list2seq.rs b/src/projection/list2seq.rs index 93c1924..69588ed 100644 --- a/src/projection/list2seq.rs +++ b/src/projection/list2seq.rs @@ -119,40 +119,44 @@ where #[cfg(test)] mod tests { use crate::buffer::vec::VecBuffer; - use crate::view::port::UpdateTask; + use crate::view::{ + port::UpdateTask, + list::ListView, + sequence::* + }; #[test] - fn list_to_seq() { + fn vec_to_list_to_seq() { let mut buf = VecBuffer::::new(); let seq_view = buf.get_port().to_list().to_sequence(); - assert_eq!(seq_view.get_view().unwrap().len(), Some(0)); + assert_eq!(seq_view.get_view().len(), Some(0)); buf.push('a'); seq_view.0.update(); - assert_eq!(seq_view.get_view().unwrap().len(), Some(1)); - assert_eq!(seq_view.get_view().unwrap().get(&0), Some('a')); - assert_eq!(seq_view.get_view().unwrap().get(&1), None); + assert_eq!(seq_view.get_view().len(), Some(1)); + assert_eq!(seq_view.get_view().get(&0), Some('a')); + assert_eq!(seq_view.get_view().get(&1), None); buf.push('b'); seq_view.0.update(); - assert_eq!(seq_view.get_view().unwrap().len(), Some(2)); - assert_eq!(seq_view.get_view().unwrap().get(&0), Some('a')); - assert_eq!(seq_view.get_view().unwrap().get(&1), Some('b')); - assert_eq!(seq_view.get_view().unwrap().get(&2), None); + assert_eq!(seq_view.get_view().len(), Some(2)); + assert_eq!(seq_view.get_view().get(&0), Some('a')); + assert_eq!(seq_view.get_view().get(&1), Some('b')); + assert_eq!(seq_view.get_view().get(&2), None); buf.push('c'); buf.remove(0); seq_view.0.update(); - assert_eq!(seq_view.get_view().unwrap().len(), Some(2)); - assert_eq!(seq_view.get_view().unwrap().get(&0), Some('b')); - assert_eq!(seq_view.get_view().unwrap().get(&1), Some('c')); - assert_eq!(seq_view.get_view().unwrap().get(&2), None); + assert_eq!(seq_view.get_view().len(), Some(2)); + assert_eq!(seq_view.get_view().get(&0), Some('b')); + assert_eq!(seq_view.get_view().get(&1), Some('c')); + assert_eq!(seq_view.get_view().get(&2), None); } } diff --git a/src/projection/vec2list.rs b/src/projection/vec2list.rs index 817f428..0548bc2 100644 --- a/src/projection/vec2list.rs +++ b/src/projection/vec2list.rs @@ -131,39 +131,44 @@ where #[cfg(test)] mod tests { use crate::buffer::vec::VecBuffer; - use crate::view::port::UpdateTask; + use crate::view::{ + port::UpdateTask, + list::ListView, + }; #[test] fn vec_to_list() { let mut buf = VecBuffer::::new(); let list_view = buf.get_port().to_list(); - assert_eq!(list_view.get_view().unwrap().len(), Some(0)); + assert_eq!(list_view.get_view().len(), Some(0)); buf.push('a'); list_view.0.update(); - assert_eq!(list_view.get_view().unwrap().len(), Some(1)); - assert_eq!(list_view.get_view().unwrap().get(&0), Some('a')); - assert_eq!(list_view.get_view().unwrap().get(&1), None); - + assert_eq!(list_view.get_view().len(), Some(1)); + assert_eq!(list_view.get_view().get(&0), Some('a')); + assert_eq!(list_view.get_view().get(&1), None); + buf.push('b'); list_view.0.update(); - assert_eq!(list_view.get_view().unwrap().len(), Some(2)); - assert_eq!(list_view.get_view().unwrap().get(&0), Some('a')); - assert_eq!(list_view.get_view().unwrap().get(&1), Some('b')); - assert_eq!(list_view.get_view().unwrap().get(&2), None); + assert_eq!(list_view.get_view().len(), Some(2)); + assert_eq!(list_view.get_view().get(&0), Some('a')); + assert_eq!(list_view.get_view().get(&1), Some('b')); + assert_eq!(list_view.get_view().get(&2), None); buf.push('c'); buf.remove(0); list_view.0.update(); - assert_eq!(list_view.get_view().unwrap().len(), Some(2)); - assert_eq!(list_view.get_view().unwrap().get(&0), Some('b')); - assert_eq!(list_view.get_view().unwrap().get(&1), Some('c')); - assert_eq!(list_view.get_view().unwrap().get(&2), None); + assert_eq!(list_view.get_view().len(), Some(2)); + assert_eq!(list_view.get_view().get(&0), Some('b')); + assert_eq!(list_view.get_view().get(&1), Some('c')); + assert_eq!(list_view.get_view().get(&2), None); } } + +