feat(rust): add are the same kata

This commit is contained in:
Dmitriy Pleshevskiy 2021-10-29 17:52:02 +03:00
parent 9c56b92632
commit 0c2f6e04a5
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
fn comp(a: Vec<i64>, b: Vec<i64>) -> bool {
let mut a = a.into_iter().map(|x| x * x).collect::<Vec<_>>();
let mut b = b;
a.sort();
b.sort();
a == b
}
fn testing(a: Vec<i64>, b: Vec<i64>, exp: bool) -> () {
assert_eq!(comp(a, b), exp)
}
#[test]
fn tests_comp() {
let a1 = vec![121, 144, 19, 161, 19, 144, 19, 11];
let a2 = vec![
11 * 11,
121 * 121,
144 * 144,
19 * 19,
161 * 161,
19 * 19,
144 * 144,
19 * 19,
];
testing(a1, a2, true);
let a1 = vec![121, 144, 19, 161, 19, 144, 19, 11];
let a2 = vec![
11 * 21,
121 * 121,
144 * 144,
19 * 19,
161 * 161,
19 * 19,
144 * 144,
19 * 19,
];
testing(a1, a2, false);
let a1 = vec![121, 144, 19, 161, -19, 144, 19, -11];
let a2 = vec![
11 * 11,
121 * 121,
144 * 144,
19 * 19,
161 * 161,
19 * 19,
144 * 144,
19 * 19,
];
testing(a1, a2, true);
}