data_structure/lib.rs
1pub mod linear;
2pub mod sorting;
3pub mod non_linear;
4
5/// 表示数据结构操作中常见的错误类型
6///
7/// # 变体
8///
9/// - `IndexErr` - 索引越界错误,通常发生在访问、插入或删除元素时索引无效
10/// - `FullErr` - 容器已满错误,通常发生在向固定容量容器插入新元素时超出限制
11#[derive(Debug)]
12pub enum Err {
13 IndexErr,
14 FullErr,
15}
16
17#[cfg(test)]
18mod tests {
19 use crate::linear::array::ArrayList;
20
21 #[test]
22 fn test1() {
23 let mut arr: ArrayList<char> = ArrayList::new();
24 arr.insert(1, 'a').expect("TODO: panic message");
25 arr.insert(2, 'b').expect("TODO: panic message");
26 arr.insert(3, 'c').expect("TODO: panic message");
27 // assert_eq!(arr.get_element(1), Ok('a'));
28 // assert_eq!(arr.length(), 3);
29 // let index = arr.locate_index('c').unwrap();
30 // assert_eq!(index, 3);
31 // let result = arr.get_element(4).unwrap();
32 // println!("{:?}", result);
33 // assert_eq!(result, 'c');
34 }
35}