Documentation

mod third_test {
  use rt_lists::third::List;

  #[derive(PartialEq, Debug)]
  struct People {
    name: String,
    age: i32,
  }

  #[test]
  fn basics() {
    let mut list: List<String> = List::new();

    assert_eq!(list.pop(), None);
  }

  #[test]
  fn basic_push_pop_peek() {

    let mut list: List<People> = List::new();
    let p1 = People {
      name: "john".to_string(),
      age: 20,
    };
    list.push(p1);

    assert_eq!(list.peek().unwrap().age, 20);
    
    assert_eq!(list.pop().unwrap().age, 20);
    assert_eq!(list.pop(), None);
  }

  #[test]
  fn peek() {
    let list: List<String> = List::new();

    assert_eq!(list.peek(), None);
  }

  #[test]
  fn peek_mut() {
    let mut list: List<People> = List::new();
    let p1 = People {
      name: "john".to_string(),
      age: 20,
    };
    list.push(p1);

    let  cur = list.peek_mut().unwrap();
    cur.name = "124".to_string();
    assert_eq!(list.peek_mut().unwrap().name, "124".to_string());
  }

  #[test]
  fn into_iter() {
    let mut list: List<i32> = List::new();
    list.push(1);
    list.push(2);
    list.push(3);

    let mut iter = list.into_iter();
    assert_eq!(iter.next(), Some(3));
    assert_eq!(iter.next(), Some(2));
    assert_eq!(iter.next(), Some(1));
    assert_eq!(iter.next(), None);
  }

  #[test]
  fn iter() {
    let mut list: List<String> = List::new();
    list.push("1".to_string());
    list.push("2".to_string());
    list.push("3".to_string());

    let mut iter = list.iter();
    assert_eq!(iter.next(), Some(&"3".to_string()));
    assert_eq!(iter.next(), Some(&"2".to_string()));
    assert_eq!(iter.next(), Some(&"1".to_string()));
  }

  #[test]
  fn iter_mut() {
    let mut list: List<String> = List::new();

    list.push(String::from("h"));
    list.push(String::from("l"));
    list.push(String::from("o"));

    let mut iter_mut = list.iter_mut();
    *iter_mut.next().unwrap() = "w".to_string();

    assert_eq!(list.pop().unwrap(), "w".to_string());
  }


  
}