Решение на Форматиране на импорти от Симеон Георгиев
Към профила на Симеон Георгиев
Резултати
- 6 точки от тестове
- 0 бонус точки
- 6 точки общо
- 6 успешни тест(а)
- 14 неуспешни тест(а)
Код
use std::collections::{BTreeSet, HashMap};
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 visited = HashMap::new();
let mut result = Vec::new();
match order {
Order::Original => {
for import in imports {
let inline_import = import.0.join("::");
if visited.insert(inline_import.clone(), true).is_none() {
result.push(inline_import);
}
}
}
Order::Sorted => {
let mut imports_set = BTreeSet::new();
for import in imports {
let inline_import = import.0.join("::");
imports_set.insert(inline_import);
}
result.extend(imports_set.into_iter());
}
}
result
}
pub fn format_nested(imports: &[Import], order: Order) -> Vec<String> {
todo!()
}
Лог от изпълнението
Compiling solution v0.1.0 (/tmp/d20241203-1739405-jwj2vd/solution)
warning: unused variable: `imports`
--> src/lib.rs:36:22
|
36 | 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:36:42
|
36 | 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.99s
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:37: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:37:5
---- solution_test::test_nested_empty stdout ----
thread 'solution_test::test_nested_empty' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_only_crate stdout ----
thread 'solution_test::test_nested_only_crate' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_original stdout ----
thread 'solution_test::test_nested_original' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_original_2 stdout ----
thread 'solution_test::test_nested_original_2' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_original_duplicates stdout ----
thread 'solution_test::test_nested_original_duplicates' panicked at 'not yet implemented', src/lib.rs:37: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:37:5
---- solution_test::test_nested_original_self stdout ----
thread 'solution_test::test_nested_original_self' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_sorted stdout ----
thread 'solution_test::test_nested_sorted' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_sorted_2 stdout ----
thread 'solution_test::test_nested_sorted_2' panicked at 'not yet implemented', src/lib.rs:37:5
---- solution_test::test_nested_sorted_duplicates stdout ----
thread 'solution_test::test_nested_sorted_duplicates' panicked at 'not yet implemented', src/lib.rs:37: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:37:5
---- solution_test::test_nested_sorted_self stdout ----
thread 'solution_test::test_nested_sorted_self' panicked at 'not yet implemented', src/lib.rs:37: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`
