Решение на FMI Buzz от Ралица Димитрова

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

Към профила на Ралица Димитрова

Резултати

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

Код

pub fn fizzbuzz(n: usize) -> Vec<String> {
return custom_buzz(n, 3, 5);
}
pub fn custom_buzz(n: usize, k1: u8, k2: u8) -> Vec<String> {
let fizzbuzzer = FizzBuzzer {
k1: k1,
k2: k2,
labels: [
String::from("Fizz"),
String::from("Buzz"),
String::from("Fizzbuzz")
],
};
return fizzbuzzer.take(n);
}
pub struct FizzBuzzer {
pub k1: u8,
pub k2: u8,
pub labels: [String; 3],
}
impl FizzBuzzer {
pub fn take(&self, n: usize) -> Vec<String> {
let mut result: Vec<String> = Vec::new();
let num1 = self.k1 as usize;
let num2 = self.k2 as usize;
if num1 == 0 || num1 == 1 || num2 == 0 || num2 == 1 {
panic!("K1 and K2 cannot be 0 or 1");
}
for i in 1..n+1 {
if i % num1 == 0 && i % num2 == 0 {
result.push(String::from("FizzBuzz"));
} else if i % num1 == 0 {
result.push(String::from("Fizz"));
} else if i % num2 == 0 {
result.push(String::from("Buzz"));
} else {
result.push(i.to_string());
}
}
return result;
}
pub fn change_label(&mut self, index: usize, value: &String) {
if index > 2 {
panic!("Index out of bounds");
}
self.labels[index] = String::from(value);
}
}

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

Compiling solution v0.1.0 (/tmp/d20201028-2816268-8wr1wj/solution)
    Finished test [unoptimized + debuginfo] target(s) in 2.03s
     Running target/debug/deps/solution-ebb42508826ef2b4

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target/debug/deps/solution_test-9e954a53ed808c89

running 10 tests
test solution_test::test_change_label_basic ... FAILED
test solution_test::test_change_label_invalid ... ok
test solution_test::test_classic1 ... FAILED
test solution_test::test_classic2 ... FAILED
test solution_test::test_coefficients1 ... FAILED
test solution_test::test_coefficients2 ... FAILED
test solution_test::test_coefficients_invalid ... ok
test solution_test::test_struct_basic ... FAILED
test solution_test::test_struct_invalid ... ok
test solution_test::test_zeroes ... ok

failures:

---- solution_test::test_change_label_basic stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some("FizzBuzz")`,
 right: `Some("Fizzbuzz")`', tests/solution_test.rs:121:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- solution_test::test_classic1 stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16"]`,
 right: `["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "Fizzbuzz", "16"]`', tests/solution_test.rs:19:5

---- solution_test::test_classic2 stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some("FizzBuzz")`,
 right: `Some("Fizzbuzz")`', tests/solution_test.rs:34:5

---- solution_test::test_coefficients1 stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some("FizzBuzz")`,
 right: `Some("Fizzbuzz")`', tests/solution_test.rs:48:5

---- solution_test::test_coefficients2 stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some("FizzBuzz")`,
 right: `Some("Fizzbuzz")`', tests/solution_test.rs:57:5

---- solution_test::test_struct_basic stdout ----
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `["1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz", "16"]`,
 right: `["1", "2", "Физ", "4", "Бъз", "Физ", "7", "8", "Физ", "Бъз", "11", "Физ", "13", "14", "Физбъз", "16"]`', tests/solution_test.rs:81:5


failures:
    solution_test::test_change_label_basic
    solution_test::test_classic1
    solution_test::test_classic2
    solution_test::test_coefficients1
    solution_test::test_coefficients2
    solution_test::test_struct_basic

test result: FAILED. 4 passed; 6 failed; 0 ignored; 0 measured; 0 filtered out

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

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

Ралица качи първо решение на 28.10.2020 14:44 (преди 9 месеца)