#[derive(Debug)]
#[cfg_attr(test, derive(PartialEq))]
pub(crate) struct VecStorage<V> {
    values: Vec<V>,
}

impl<V> VecStorage<V> {
    pub fn new() -> Self {
        return VecStorage { values: Vec::new() };
    }

    pub fn iter(&self) -> core::slice::Iter<'_, V> {
        return self.values.iter();
    }

    pub fn push(&mut self, value: V) {
        self.values.push(value);
    }

    #[cfg(test)]
    pub fn len(&self) -> usize {
        return self.values.len();
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use rstest::rstest;

    #[rstest]
    fn test_new() {
        // arrange
        let s: VecStorage<i32> = VecStorage::new();
        // act-assert
        assert_eq!(0, s.len());
        assert_eq!(None, s.iter().next());
    }

    #[rstest]
    fn test_push_one_item() {
        // arrange
        let mut s: VecStorage<i32> = VecStorage::new();
        // act
        s.push(123);
        // assert
        assert_eq!(1, s.len());
        let mut iter = s.iter();
        assert_eq!(Some(&123), iter.next());
        assert_eq!(None, iter.next());
    }

    #[rstest]
    fn test_push_several_items() {
        // arrange
        let mut s: VecStorage<i32> = VecStorage::new();
        // act
        s.push(123);
        s.push(321);
        // assert
        assert_eq!(2, s.len());
        let mut iter = s.iter();
        assert_eq!(Some(&123), iter.next());
        assert_eq!(Some(&321), iter.next());
        assert_eq!(None, iter.next());
    }
}
