Skip to content

Commit d3f0ef2

Browse files
committed
feat: add tests
1 parent 43bdc65 commit d3f0ef2

File tree

1 file changed

+57
-2
lines changed
  • find_duplicate_file_in_system/src

1 file changed

+57
-2
lines changed
+57-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,62 @@
1+
pub struct Solution {}
2+
3+
impl Solution {
4+
pub fn find_duplicate(paths: Vec<String>) -> Vec<Vec<String>> {
5+
vec![vec![]]
6+
}
7+
}
8+
19
#[cfg(test)]
210
mod tests {
11+
use super::*;
12+
13+
fn sort(array: &mut Vec<Vec<String>>) {
14+
for r in array.iter_mut() {
15+
r.sort();
16+
}
17+
array.sort();
18+
}
19+
20+
fn correct(paths: &Vec<&str>, expected: &Vec<Vec<&str>>) {
21+
let mut result = Solution::find_duplicate(paths.iter().map(|x| x.to_string()).collect())
22+
.iter()
23+
.map(|r| r.iter().map(|x| x.to_string()).collect())
24+
.collect();
25+
let mut expected = expected
26+
.iter()
27+
.map(|r| r.iter().map(|x| x.to_string()).collect())
28+
.collect();
29+
sort(&mut expected);
30+
sort(&mut result);
31+
assert_eq!(result, expected);
32+
}
33+
34+
#[test]
35+
fn example_1() {
36+
let paths = vec![
37+
"root/a 1.txt(abcd) 2.txt(efgh)",
38+
"root/c 3.txt(abcd)",
39+
"root/c/d 4.txt(efgh)",
40+
"root 4.txt(efgh)",
41+
];
42+
let expected = vec![
43+
vec!["root/a/2.txt", "root/c/d/4.txt", "root/4.txt"],
44+
vec!["root/a/1.txt", "root/c/3.txt"],
45+
];
46+
correct(&paths, &expected);
47+
}
48+
349
#[test]
4-
fn it_works() {
5-
assert_eq!(2 + 2, 4);
50+
fn example_2() {
51+
let paths = vec![
52+
"root/a 1.txt(abcd) 2.txt(efgh)",
53+
"root/c 3.txt(abcd)",
54+
"root/c/d 4.txt(efgh)",
55+
];
56+
let expected = vec![
57+
vec!["root/a/2.txt", "root/c/d/4.txt"],
58+
vec!["root/a/1.txt", "root/c/3.txt"],
59+
];
60+
correct(&paths, &expected);
661
}
762
}

0 commit comments

Comments
 (0)