Решение на Форматиране на импорти от Ивона Стоянова
Резултати
- 6 точки от тестове
- 0 бонус точки
- 6 точки общо
- 6 успешни тест(а)
- 14 неуспешни тест(а)
Код
use std::collections::HashSet;
#[derive(Debug)]
pub struct Import<'a>(pub &'a [&'a str]);
pub enum Order {
Original,
Sorted,
}
pub fn format_flat(imports: &[Import], order: Order) -> Vec<String> {
let mut result: Vec<String> = Vec::new();
let mut imports_iter = imports.iter();
while let Some(path) = imports_iter.next() {
result.push(path.0.join("::"));
}
let mut seen = HashSet::new();
let mut unique_result: Vec<String> = result.into_iter().filter(|item| seen.insert(item.clone())).collect();
match order {
Order::Original => unique_result,
Order::Sorted => {
unique_result.sort();
unique_result
}
}
}
pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
todo!()
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20241203-1739405-xigr7j/solution) warning: unused variable: `imports` --> src/lib.rs:29:22 | 29 | 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:29:42 | 29 | 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 1.21s Running tests/solution_test.rs (target/debug/deps/solution_test-1428e1090729d165) running 20 tests test solution_test::test_flat_empty ... ok test solution_test::test_flat_multi_crate ... ok test solution_test::test_flat_original ... ok test solution_test::test_flat_original_duplicates ... ok test solution_test::test_flat_sorted ... ok test solution_test::test_flat_sorted_duplicates ... ok test solution_test::test_nested_basic ... 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_nested_basic stdout ---- thread 'solution_test::test_nested_basic' panicked at 'not yet implemented', src/lib.rs:30:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ---- solution_test::test_nested_deep stdout ---- thread 'solution_test::test_nested_deep' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_empty stdout ---- thread 'solution_test::test_nested_empty' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_only_crate stdout ---- thread 'solution_test::test_nested_only_crate' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_original stdout ---- thread 'solution_test::test_nested_original' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_original_2 stdout ---- thread 'solution_test::test_nested_original_2' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_original_duplicates stdout ---- thread 'solution_test::test_nested_original_duplicates' panicked at 'not yet implemented', src/lib.rs:30: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:30:5 ---- solution_test::test_nested_original_self stdout ---- thread 'solution_test::test_nested_original_self' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_sorted stdout ---- thread 'solution_test::test_nested_sorted' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_sorted_2 stdout ---- thread 'solution_test::test_nested_sorted_2' panicked at 'not yet implemented', src/lib.rs:30:5 ---- solution_test::test_nested_sorted_duplicates stdout ---- thread 'solution_test::test_nested_sorted_duplicates' panicked at 'not yet implemented', src/lib.rs:30: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:30:5 ---- solution_test::test_nested_sorted_self stdout ---- thread 'solution_test::test_nested_sorted_self' panicked at 'not yet implemented', src/lib.rs:30:5 failures: 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. 6 passed; 14 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s error: test failed, to rerun pass `--test solution_test`