Решение на FMI Buzz от Мерилин Писина

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

Към профила на Мерилин Писина

Резултати

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

Код

pub fn fizzbuzz(n: usize) -> Vec<String> {
let mut result: Vec<String> = vec![];
for i in 1..n+1 {
let pair = (i%3, i%5);
match pair {
(0, 0) => result.push(String::from("FizzBuzz")),
(0, _) => result.push(String::from("Fizz")),
(_, 0) => result.push(String::from("Buzz")),
_ => result.push(i.to_string()),
}
}
result
}
pub fn custom_buzz(n: usize, k1: u8, k2: u8) -> Vec<String> {
let mut result: Vec<String> = vec![];
if k1 <= 1 || k2 <= 1 {
panic!("invalid argument");
}
let first = usize::from(k1);
let second = usize::from(k2);
for i in 1..n+1 {
let pair = (i%first, i%second);
match pair {
(0, 0) => result.push(String::from("FizzBuzz")),
(0, _) => result.push(String::from("Fizz")),
(_, 0) => result.push(String::from("Buzz")),
_ => result.push(i.to_string()),
}
}
result
}
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![];
if self.k1 <= 1 || self.k2 <= 1 {
panic!("invalid argument");
}
let first = usize::from(self.k1);
let second = usize::from(self.k2);
for i in 1..n+1 {
let pair = (i%first, i%second);
match pair {
(0, 0) => result.push(String::from(&self.labels[2])),
(0, _) => result.push(String::from(&self.labels[0])),
(_, 0) => result.push(String::from(&self.labels[1])),
_ => result.push(i.to_string()),
}
}
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-s3qmgf/solution)
    Finished test [unoptimized + debuginfo] target(s) in 2.09s
     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 ... ok
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 ... ok
test solution_test::test_struct_invalid ... ok
test solution_test::test_zeroes ... ok

failures:

---- 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


failures:
    solution_test::test_classic1
    solution_test::test_classic2
    solution_test::test_coefficients1
    solution_test::test_coefficients2

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

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

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

Мерилин качи първо решение на 28.10.2020 13:04 (преди 9 месеца)