Debian Codegraph @

src/insort/tests.rs

raw symbols SCIP
1 use craterust-analyzer cargo timsort 0.1.3 crate/::{comparatorrust-analyzer cargo timsort 0.1.3 comparator()., neverrust-analyzer cargo timsort 0.1.3 never()., ord_t_comparatorrust-analyzer cargo timsort 0.1.3 ord_t_comparator().};
2
3 /// Test the insertion sort implementation with an empty list
4 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
5 fn emptyrust-analyzer cargo timsort 0.1.3 insort/tests/empty().() {
6 let mut list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u32> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
7 sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().(&mut list);
8 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
9 }
10
11 /// Test the insertion sort implementation with a single-element list
12 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
13 fn singlerust-analyzer cargo timsort 0.1.3 insort/tests/single().() {
14 let mut list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![42];
15 sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().(&mut list);
16 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 42);
17 }
18
19 /// Test the insertion sort implementation with a short unsorted list
20 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
21 fn unsortedrust-analyzer cargo timsort 0.1.3 insort/tests/unsorted().() {
22 let mut list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![3, 1, 0, 4];
23 sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().(&mut list);
24 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 0);
25 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 1);
26 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 3);
27 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 4);
28 }
29
30 /// Test the insertion sort implementation with a short backward list
31 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
32 fn reverserust-analyzer cargo timsort 0.1.3 insort/tests/reverse().() {
33 let mut list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![21, 18, 7, 1];
34 sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().(&mut list);
35 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 1);
36 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 7);
37 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 18);
38 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 21);
39 }
40
41 /// Test the insertion sort implementation with a short unsorted list
42 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
43 fn sortedrust-analyzer cargo timsort 0.1.3 insort/tests/sorted().() {
44 let mut list = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0, 1, 2, 3];
45 sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().(&mut list);
46 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 0);
47 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 1);
48 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 2);
49 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(list[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().3]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). == 3);
50 }
51
52 /// Make sure the sort is stable.
53 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
54 fn stablerust-analyzer cargo timsort 0.1.3 insort/tests/stable().() {
55 let len = 256;
56 let mut key1: usize = 0;
57 let mut key2: usize = 0;
58 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
59 struct Itemrust-analyzer cargo timsort 0.1.3 insort/tests/Item# {
60 key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1.: usize,
61 key2rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key2.: usize,
62 }
63 let mut list: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Itemrust-analyzer cargo timsort 0.1.3 insort/tests/Item#> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#len)
64 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| {
65 key1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
66 key1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`RemAssign<Self>`]rem_assign().5;
67 key2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
68 Itemrust-analyzer cargo timsort 0.1.3 insort/tests/Item# { key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1., key2rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key2. }
69 })
70 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
71 superrust-analyzer cargo timsort 0.1.3 insort/::sortrust-analyzer cargo timsort 0.1.3 insort/sort().(&mut list, &comparatorrust-analyzer cargo timsort 0.1.3 comparator().(|a: &Itemrust-analyzer cargo timsort 0.1.3 insort/tests/Item#, b| Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(a.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().b.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1.))).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(neverrust-analyzer cargo timsort 0.1.3 never().);
72 for pair in list.windowsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]windows().(2) {
73 let (a, b) = (&pair[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &pair[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
74 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1. <= b.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1.);
75 if a.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().b.key1rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key1. {
76 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(a.key2rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key2. <= b.key2rust-analyzer cargo timsort 0.1.3 insort/tests/Item#key2.);
77 }
78 }
79 }
80
81 /// Insertion sort implementation convenience used for tests.
82 fn sortrust-analyzer cargo timsort 0.1.3 insort/tests/sort().<T: Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#>(list: &mut [T]) {
83 superrust-analyzer cargo timsort 0.1.3 insort/::sortrust-analyzer cargo timsort 0.1.3 insort/sort().(list, &ord_t_comparatorrust-analyzer cargo timsort 0.1.3 ord_t_comparator().()).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(neverrust-analyzer cargo timsort 0.1.3 never().);
84 }