Решение на упр.03 задача 1 от Георги Стоянов

Обратно към всички решения

Към профила на Георги Стоянов

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 1 неуспешни тест(а)

Код

fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
let mut start_index = 0;
let mut target = String::new();
for (i, el) in text.char_indices() {
if el == ' ' {
let temp = String::from(&text[start_index..i]);
if temp == word {
for (j, el2) in word.char_indices() {
target.push(palette[j % palette.len()]);
}
}
target.push(' ');
start_index = i + el.len_utf8();
}
}
let temp = &text[start_index..];
if temp == word {
for (k, _) in word.char_indices() {
target.push(palette[k % palette.len()]);
}
} else {
target.push_str(temp);
}
target
}
fn main() {
assert_eq!(
rainbow_replace("плодова салата", "плодова", &['🍆', '🍎', '🍒']),
"🍆🍎🍒🍆🍎🍒🍆 салата".to_string(),
);
}

Лог от изпълнението

Updating crates.io index
     Locking 17 packages to latest compatible versions
   Compiling proc-macro2 v1.0.103
   Compiling unicode-ident v1.0.22
   Compiling quote v1.0.41
   Compiling futures-core v0.3.31
   Compiling futures-sink v0.3.31
   Compiling futures-channel v0.3.31
   Compiling memchr v2.7.6
   Compiling syn v2.0.108
   Compiling slab v0.4.11
   Compiling pin-utils v0.1.0
   Compiling futures-task v0.3.31
   Compiling futures-io v0.3.31
   Compiling pin-project-lite v0.2.16
   Compiling solution v0.1.0 (/tmp/d20251030-1757769-grlia2/solution)
warning: unused variable: `el2`
 --> src/lib.rs:8:25
  |
8 |                 for (j, el2) in word.char_indices() {
  |                         ^^^ help: if this is intentional, prefix it with an underscore: `_el2`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function `rainbow_replace` is never used
 --> src/lib.rs:1:4
  |
1 | fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
  |    ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: function `main` is never used
  --> src/lib.rs:27:4
   |
27 | fn main() {
   |    ^^^^

warning: `solution` (lib) generated 3 warnings
   Compiling futures-macro v0.3.31
   Compiling futures-util v0.3.31
   Compiling futures-executor v0.3.31
   Compiling futures v0.3.31
warning: unused variable: `el2`
 --> tests/../src/lib.rs:8:25
  |
8 |                 for (j, el2) in word.char_indices() {
  |                         ^^^ help: if this is intentional, prefix it with an underscore: `_el2`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function `main` is never used
  --> tests/../src/lib.rs:27:4
   |
27 | fn main() {
   |    ^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `solution` (test "solution_test") generated 2 warnings
    Finished `test` profile [unoptimized + debuginfo] target(s) in 8.40s
     Running tests/solution_test.rs (target/debug/deps/solution_test-bfd50394249726db)

running 1 test
test solution_test::test_basic ... FAILED

failures:

---- solution_test::test_basic stdout ----
thread 'solution_test::test_basic' panicked at tests/solution_test.rs:10:5:
assertion `left == right` failed
  left: "🍆🍒🍎🍆🍒🍎🍆 салата"
 right: "🍆🍎🍒🍆🍎🍒🍆 салата"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    solution_test::test_basic

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `--test solution_test`

История (1 версия и 0 коментара)

Георги качи първо решение на 23.10.2025 21:30 (преди 7 дена)