vec.rs 855 B

12345678910111213141516171819202122232425262728293031323334353637
  1. extern crate ralloc;
  2. #[global_allocator]
  3. static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
  4. mod util;
  5. #[test]
  6. fn simple_vec() {
  7. util::multiply(|| {
  8. let mut vec = Vec::new();
  9. for i in 0..0xFFFF {
  10. // We're going to annoy the allocator by allocating a small chunk,
  11. // after which we push.
  12. let _bx = Box::new(4);
  13. vec.push(i);
  14. }
  15. assert_eq!(vec[0xDEAD], 0xDEAD);
  16. assert_eq!(vec[0xBEAF], 0xBEAF);
  17. assert_eq!(vec[0xABCD], 0xABCD);
  18. assert_eq!(vec[0xFFAB], 0xFFAB);
  19. assert_eq!(vec[0xAAAA], 0xAAAA);
  20. for i in 0xFFF..0 {
  21. util::acid(|| {
  22. assert_eq!(vec.pop(), Some(i));
  23. });
  24. }
  25. for i in 0..0xFFF {
  26. vec[i] = 0;
  27. assert_eq!(vec[i], 0);
  28. }
  29. });
  30. }