use deinterleave::{DVec, Deinterleave}; #[derive(Debug, Deinterleave, Eq, PartialEq)] pub struct Pos { a: bool, b: usize, } impl Pos { pub fn new(a: bool, b: usize) -> Self { Self { a, b } } } #[test] fn push_remove() { let mut v: DVec = DVec::default(); assert!(v.is_empty()); assert_eq!(v.len(), 0); v.push(Pos::new(true, 42)); v.push(Pos::new(false, 0)); assert_eq!(v.len(), 2); assert_eq!(v.remove(1), Pos { a: false, b: 0 }); assert_eq!(v.len(), 1); assert_eq!(v.remove(0), Pos { a: true, b: 42 }); } #[test] fn get() { let mut v: DVec = DVec::default(); v.push(Pos::new(true, 1)); v.push(Pos::new(false, 2)); v.push(Pos::new(true, 3)); assert_eq!(v.get(0), Some(&true)); assert_eq!(v.get(0), Some(&1usize)); assert_eq!(v.get(1), Some(&false)); assert_eq!(v.get(1), Some(&2usize)); assert_eq!(v.get(2), Some(&true)); assert_eq!(v.get(2), Some(&3usize)); } #[test] fn iter() { let mut v: DVec = DVec::default(); v.push(Pos::new(true, 1)); v.push(Pos::new(false, 2)); v.push(Pos::new(true, 3)); for (i, b) in v.iter_proxy().b.enumerate() { assert_eq!(i + 1, *b); } let iter = v.iter_proxy(); let tuples: Vec<_> = iter.a.zip(iter.b).map(|(a, b)| (*a, *b)).collect(); assert_eq!(tuples, [(true, 1), (false, 2), (true, 3)]); }