Skip to content

Commit

Permalink
fizzy: remove macro from tests
Browse files Browse the repository at this point in the history
part of #1824
  • Loading branch information
senekor committed Aug 14, 2024
1 parent 938cac5 commit 6967d17
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions exercises/practice/fizzy/tests/fizzy.rs
Original file line number Diff line number Diff line change
@@ -1,82 +1,83 @@
use fizzy::*;

macro_rules! expect {
() => {
vec![
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13",
"14", "fizzbuzz", "16",
]
};
}

#[test]
fn simple() {
let got = fizz_buzz::<i32>().apply(1..=16).collect::<Vec<_>>();
assert_eq!(expect!(), got);
let actual = fizz_buzz::<i32>().apply(1..=16).collect::<Vec<_>>();
let expected = [
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14",
"fizzbuzz", "16",
];
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn u8() {
let got = fizz_buzz::<u8>().apply(1_u8..=16).collect::<Vec<_>>();
assert_eq!(expect!(), got);
let actual = fizz_buzz::<u8>().apply(1_u8..=16).collect::<Vec<_>>();
let expected = [
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14",
"fizzbuzz", "16",
];
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn u64() {
let got = fizz_buzz::<u64>().apply(1_u64..=16).collect::<Vec<_>>();
assert_eq!(expect!(), got);
let actual = fizz_buzz::<u64>().apply(1_u64..=16).collect::<Vec<_>>();
let expected = [
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14",
"fizzbuzz", "16",
];
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn nonsequential() {
let collatz_12 = &[12, 6, 3, 10, 5, 16, 8, 4, 2, 1];
let expect = vec![
"fizz", "fizz", "fizz", "buzz", "buzz", "16", "8", "4", "2", "1",
];
let got = fizz_buzz::<i32>()
let actual = fizz_buzz::<i32>()
.apply(collatz_12.iter().cloned())
.collect::<Vec<_>>();
assert_eq!(expect, got);
let expected = vec![
"fizz", "fizz", "fizz", "buzz", "buzz", "16", "8", "4", "2", "1",
];
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn custom() {
let expect = vec![
let expected = vec![
"1", "2", "Fizz", "4", "Buzz", "Fizz", "Bam", "8", "Fizz", "Buzz", "11", "Fizz", "13",
"Bam", "BuzzFizz", "16",
];
let fizzer: Fizzy<i32> = Fizzy::new()
.add_matcher(Matcher::new(|n: i32| n % 5 == 0, "Buzz"))
.add_matcher(Matcher::new(|n: i32| n % 3 == 0, "Fizz"))
.add_matcher(Matcher::new(|n: i32| n % 7 == 0, "Bam"));
let got = fizzer.apply(1..=16).collect::<Vec<_>>();
assert_eq!(expect, got);
let actual = fizzer.apply(1..=16).collect::<Vec<_>>();
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn f64() {
// a tiny bit more complicated becuase range isn't natively implemented on floats
// NOTE: this test depends on a language feature introduced in Rust 1.34. If you
// have an older compiler, upgrade. If you have an older compiler and cannot upgrade,
// feel free to ignore this test.
let got = fizz_buzz::<f64>()
let actual = fizz_buzz::<f64>()
.apply(std::iter::successors(Some(1.0), |prev| Some(prev + 1.0)))
.take(16)
.collect::<Vec<_>>();
assert_eq!(expect!(), got);
let expected = [
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14",
"fizzbuzz", "16",
];
assert_eq!(actual, expected);
}

#[test]
#[ignore]
fn minimal_generic_bounds() {
// NOTE: this test depends on a language feature introduced in Rust 1.34. If you
// have an older compiler, upgrade. If you have an older compiler and cannot upgrade,
// feel free to ignore this test.
use std::fmt;
use std::ops::{Add, Rem};

Expand Down Expand Up @@ -114,11 +115,15 @@ fn minimal_generic_bounds() {
}
}

let got = fizz_buzz::<Fizzable>()
let actual = fizz_buzz::<Fizzable>()
.apply(std::iter::successors(Some(Fizzable(1)), |prev| {
Some(*prev + 1.into())
}))
.take(16)
.collect::<Vec<_>>();
assert_eq!(expect!(), got);
let expected = [
"1", "2", "fizz", "4", "buzz", "fizz", "7", "8", "fizz", "buzz", "11", "fizz", "13", "14",
"fizzbuzz", "16",
];
assert_eq!(actual, expected);
}

0 comments on commit 6967d17

Please sign in to comment.