-
Notifications
You must be signed in to change notification settings - Fork 9
/
lib.rs
49 lines (43 loc) · 1.04 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pub fn is_palindrome<T: PartialEq>(li: &Vec<T>) -> bool {
let mid = li.len() / 2;
for i in 0..mid {
if li.get(i).unwrap() != li.get(li.len() - (1 + i)).unwrap() {
return false;
}
}
true
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_odd_elements() {
let li = vec![1, 2, 3, 2, 1];
assert_eq!(is_palindrome(&li), true);
}
#[test]
fn test_even_elements() {
let li = vec![1, 2, 2, 1];
assert_eq!(is_palindrome(&li), true);
}
#[test]
fn test_odd_elements_non() {
let li = vec![1, 3, 3, 2, 1];
assert_eq!(is_palindrome(&li), false);
}
#[test]
fn test_even_elements_non() {
let li = vec![1, 3, 2, 1];
assert_eq!(is_palindrome(&li), false);
}
#[test]
fn test_empty_list() {
let li = Vec::<usize>::new();
assert_eq!(is_palindrome(&li), true);
}
#[test]
fn test_one_elemens() {
let li = vec![1];
assert_eq!(is_palindrome(&li), true);
}
}