Skip to content

Commit

Permalink
added a codewars solution 'fizz buzz test'
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmir17 committed Jun 19, 2024
1 parent 7cc8149 commit 607d254
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions codewars_kata_training/examples/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,41 @@ mod directions_reduction_tests {
}


#[cfg(test)]
mod fizz_buzz_tests {

pub trait Fizzy {
fn fizzy(&self);
}

impl Fizzy for i32 {
fn fizzy(&self) {
for i in 1..self + 1 {
println!("{}", convert_to_fizz_buzz(i))
}
}
}

fn convert_to_fizz_buzz(n: i32) -> String {
if n % (3 * 5) == 0 {
return String::from("FizzBuzz")
} else if n % 3 == 0 {
return String::from("Fizz")
} else if n % 5 == 0 {
return String::from("Buzz")
} else {
return n.to_string()
}
}

#[test]
fn main() {
for x in 1..=10 {
x.fizzy()
}
}
}

#[cfg(test)]
mod duplicate_counter_tests {
use std::collections::HashMap;
Expand Down

0 comments on commit 607d254

Please sign in to comment.