Решение на Форматиране на импорти от Радосвет Сечков
Към профила на Радосвет Сечков
Резултати
- 3 точки от тестове
- 0 бонус точки
- 3 точки общо
- 3 успешни тест(а)
- 17 неуспешни тест(а)
Код
pub struct Import<'a>(pub &'a [&'a str]);
impl<'a> Import<'a> {
fn to_vec_s(&self) -> Vec<&str> {
let mut vec: Vec<&str> = Vec::new();
for i in self.0 {
vec.push(*i);
}
vec
}
}
#[derive(PartialEq)]
pub enum Order {
Original,
Sorted,
}
pub enum Compare {
One,
Two
}
use crate::Compare::{One, Two};
pub fn compare(s1: String, s2: String) -> Compare {
if s1.len() > s2.len() {
let mut iter = s1.chars();
for i in s2.chars() {
if let Some(c) = iter.next() {
if c > i {
return One;
} else if c < i {
return Two;
}
}
}
} else {
let mut iter = s1.chars();
for i in s2.chars() {
if let Some(c) = iter.next() {
if c < i {
return Two;
} else if c > i {
return One;
}
}
}
}
Two
}
pub fn sorted_lex(vec: &mut Vec<String>) -> Vec<String> {
for i in 0 .. vec.len() - 1 {
for j in i + 1 .. vec.len() {
let s = vec[i].clone();
if let One = compare(vec[i].clone(), vec[j].clone()) {
vec[i] = vec[j].clone();
vec[j] = s;
}
}
}
vec.to_vec()
}
pub fn format_flat(imports: &[Import], order: Order) -> Vec<String> {
let mut vec: Vec<String> = Vec::new();
for i in imports {
let mut s = String::new();
for j in i.to_vec_s() {
s.push_str(j);
s.push_str("::");
}
s.pop();
s.pop();
vec.push(s);
}
let result = if order == Order::Original {vec} else {sorted_lex(&mut vec)};
result
}
pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
todo!()
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20241203-1739405-1r8edtc/solution)
warning: unused variable: `imports`
--> src/lib.rs:86:22
|
86 | pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
| ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_imports`
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `order`
--> src/lib.rs:86:42
|
86 | pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_order`
warning: `solution` (lib) generated 2 warnings
Finished test [unoptimized + debuginfo] target(s) in 0.93s
Running tests/solution_test.rs (target/debug/deps/solution_test-1428e1090729d165)
running 20 tests
test solution_test::test_flat_multi_crate ... ok
test solution_test::test_flat_empty ... FAILED
test solution_test::test_flat_original ... ok
test solution_test::test_flat_original_duplicates ... FAILED
test solution_test::test_flat_sorted ... ok
test solution_test::test_nested_basic ... FAILED
test solution_test::test_flat_sorted_duplicates ... FAILED
test solution_test::test_nested_deep ... FAILED
test solution_test::test_nested_empty ... FAILED
test solution_test::test_nested_only_crate ... FAILED
test solution_test::test_nested_original ... FAILED
test solution_test::test_nested_original_2 ... FAILED
test solution_test::test_nested_original_duplicates ... FAILED
test solution_test::test_nested_original_multi_crate ... FAILED
test solution_test::test_nested_original_self ... FAILED
test solution_test::test_nested_sorted ... FAILED
test solution_test::test_nested_sorted_2 ... FAILED
test solution_test::test_nested_sorted_duplicates ... FAILED
test solution_test::test_nested_sorted_multi_crate ... FAILED
test solution_test::test_nested_sorted_self ... FAILED
failures:
---- solution_test::test_flat_empty stdout ----
thread 'solution_test::test_flat_empty' panicked at 'attempt to subtract with overflow', src/lib.rs:54:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- solution_test::test_flat_original_duplicates stdout ----
thread 'solution_test::test_flat_original_duplicates' panicked at 'assertion failed: `(left == right)`
left: `["std::string::String", "std::iter::once", "std::iter", "std::iter", "std::iter::repeat", "std::string::String"]`,
right: `["std::string::String", "std::iter::once", "std::iter", "std::iter::repeat"]`', tests/solution_test.rs:44:5
---- solution_test::test_nested_basic stdout ----
thread 'solution_test::test_nested_basic' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_flat_sorted_duplicates stdout ----
thread 'solution_test::test_flat_sorted_duplicates' panicked at 'assertion failed: `(left == right)`
left: `["std::iter::once", "std::iter", "std::iter", "std::iter::repeat", "std::string::String", "std::string::String"]`,
right: `["std::iter", "std::iter::once", "std::iter::repeat", "std::string::String"]`', tests/solution_test.rs:88:5
---- solution_test::test_nested_deep stdout ----
thread 'solution_test::test_nested_deep' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_empty stdout ----
thread 'solution_test::test_nested_empty' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_only_crate stdout ----
thread 'solution_test::test_nested_only_crate' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_original stdout ----
thread 'solution_test::test_nested_original' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_original_2 stdout ----
thread 'solution_test::test_nested_original_2' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_original_duplicates stdout ----
thread 'solution_test::test_nested_original_duplicates' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_original_multi_crate stdout ----
thread 'solution_test::test_nested_original_multi_crate' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_original_self stdout ----
thread 'solution_test::test_nested_original_self' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_sorted stdout ----
thread 'solution_test::test_nested_sorted' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_sorted_2 stdout ----
thread 'solution_test::test_nested_sorted_2' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_sorted_duplicates stdout ----
thread 'solution_test::test_nested_sorted_duplicates' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_sorted_multi_crate stdout ----
thread 'solution_test::test_nested_sorted_multi_crate' panicked at 'not yet implemented', src/lib.rs:87:5
---- solution_test::test_nested_sorted_self stdout ----
thread 'solution_test::test_nested_sorted_self' panicked at 'not yet implemented', src/lib.rs:87:5
failures:
solution_test::test_flat_empty
solution_test::test_flat_original_duplicates
solution_test::test_flat_sorted_duplicates
solution_test::test_nested_basic
solution_test::test_nested_deep
solution_test::test_nested_empty
solution_test::test_nested_only_crate
solution_test::test_nested_original
solution_test::test_nested_original_2
solution_test::test_nested_original_duplicates
solution_test::test_nested_original_multi_crate
solution_test::test_nested_original_self
solution_test::test_nested_sorted
solution_test::test_nested_sorted_2
solution_test::test_nested_sorted_duplicates
solution_test::test_nested_sorted_multi_crate
solution_test::test_nested_sorted_self
test result: FAILED. 3 passed; 17 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass `--test solution_test`
