Решение на Форматиране на импорти от Димитър Тагарев
Към профила на Димитър Тагарев
Резултати
- 6 точки от тестове
- 0 бонус точки
- 6 точки общо
- 6 успешни тест(а)
- 14 неуспешни тест(а)
Код
use std::collections::HashSet;
pub fn add(left: usize, right: usize) -> usize {
left + right
}
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 unique_imports: Vec<&Import> = {
let mut seen = HashSet::new();
imports
.iter()
.filter(|import| seen.insert(import.0))
.collect()
};
if let Order::Sorted = order {
unique_imports.sort_by(|a, b| a.0.cmp(&b.0));
}
unique_imports
.into_iter()
.map(|import| import.0.join("::"))
.map(String::from)
.collect()
}
pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
todo!()
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20241203-1739405-1w3az07/solution)
warning: unused variable: `imports`
--> src/lib.rs:34:22
|
34 | 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:34:42
|
34 | 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.24s
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:35: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:35:5
---- solution_test::test_nested_empty stdout ----
thread 'solution_test::test_nested_empty' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_only_crate stdout ----
thread 'solution_test::test_nested_only_crate' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_original stdout ----
thread 'solution_test::test_nested_original' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_original_2 stdout ----
thread 'solution_test::test_nested_original_2' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_original_duplicates stdout ----
thread 'solution_test::test_nested_original_duplicates' panicked at 'not yet implemented', src/lib.rs:35: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:35:5
---- solution_test::test_nested_original_self stdout ----
thread 'solution_test::test_nested_original_self' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_sorted stdout ----
thread 'solution_test::test_nested_sorted' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_sorted_2 stdout ----
thread 'solution_test::test_nested_sorted_2' panicked at 'not yet implemented', src/lib.rs:35:5
---- solution_test::test_nested_sorted_duplicates stdout ----
thread 'solution_test::test_nested_sorted_duplicates' panicked at 'not yet implemented', src/lib.rs:35: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:35:5
---- solution_test::test_nested_sorted_self stdout ----
thread 'solution_test::test_nested_sorted_self' panicked at 'not yet implemented', src/lib.rs:35: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`
