diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-08-01 23:57:23 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-08-02 01:59:01 +0300 |
| commit | e118eb6c7970385fbcdd688d03975f65d88e642e (patch) | |
| tree | 52f7b93573ee2e7c0963f66f4907fc44e6c15443 /src/librustc_data_structures/tiny_list | |
| parent | ca0ef0fcf66b0fe913c19a3a00729af4494866e6 (diff) | |
librustc_data_structures: Unconfigure tests during normal build
Diffstat (limited to 'src/librustc_data_structures/tiny_list')
| -rw-r--r-- | src/librustc_data_structures/tiny_list/tests.rs | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/src/librustc_data_structures/tiny_list/tests.rs b/src/librustc_data_structures/tiny_list/tests.rs new file mode 100644 index 00000000000..8374659e1e6 --- /dev/null +++ b/src/librustc_data_structures/tiny_list/tests.rs @@ -0,0 +1,133 @@ +use super::*; + +extern crate test; +use test::Bencher; + +#[test] +fn test_contains_and_insert() { + fn do_insert(i : u32) -> bool { + i % 2 == 0 + } + + let mut list = TinyList::new(); + + for i in 0 .. 10 { + for j in 0 .. i { + if do_insert(j) { + assert!(list.contains(&j)); + } else { + assert!(!list.contains(&j)); + } + } + + assert!(!list.contains(&i)); + + if do_insert(i) { + list.insert(i); + assert!(list.contains(&i)); + } + } +} + +#[test] +fn test_remove_first() { + let mut list = TinyList::new(); + list.insert(1); + list.insert(2); + list.insert(3); + list.insert(4); + assert_eq!(list.len(), 4); + + assert!(list.remove(&4)); + assert!(!list.contains(&4)); + + assert_eq!(list.len(), 3); + assert!(list.contains(&1)); + assert!(list.contains(&2)); + assert!(list.contains(&3)); +} + +#[test] +fn test_remove_last() { + let mut list = TinyList::new(); + list.insert(1); + list.insert(2); + list.insert(3); + list.insert(4); + assert_eq!(list.len(), 4); + + assert!(list.remove(&1)); + assert!(!list.contains(&1)); + + assert_eq!(list.len(), 3); + assert!(list.contains(&2)); + assert!(list.contains(&3)); + assert!(list.contains(&4)); +} + +#[test] +fn test_remove_middle() { + let mut list = TinyList::new(); + list.insert(1); + list.insert(2); + list.insert(3); + list.insert(4); + assert_eq!(list.len(), 4); + + assert!(list.remove(&2)); + assert!(!list.contains(&2)); + + assert_eq!(list.len(), 3); + assert!(list.contains(&1)); + assert!(list.contains(&3)); + assert!(list.contains(&4)); +} + +#[test] +fn test_remove_single() { + let mut list = TinyList::new(); + list.insert(1); + assert_eq!(list.len(), 1); + + assert!(list.remove(&1)); + assert!(!list.contains(&1)); + + assert_eq!(list.len(), 0); +} + +#[bench] +fn bench_insert_empty(b: &mut Bencher) { + b.iter(|| { + let mut list = TinyList::new(); + list.insert(1); + }) +} + +#[bench] +fn bench_insert_one(b: &mut Bencher) { + b.iter(|| { + let mut list = TinyList::new_single(0); + list.insert(1); + }) +} + +#[bench] +fn bench_remove_empty(b: &mut Bencher) { + b.iter(|| { + TinyList::new().remove(&1) + }); +} + +#[bench] +fn bench_remove_unknown(b: &mut Bencher) { + b.iter(|| { + TinyList::new_single(0).remove(&1) + }); +} + +#[bench] +fn bench_remove_one(b: &mut Bencher) { + b.iter(|| { + TinyList::new_single(1).remove(&1) + }); +} |
