use std::io::BufRead;
use std::iter::Iterator;
-fn tally_marks(n: usize, mark: Option<&str>) -> String {
- match mark {
+fn tally_marks(n: usize, mark: Option<&str>) -> HTML {
+ HTML(match mark {
None => {
let fives = { 0..n / 5 }.map(|_| 'πΈ');
let ones = { 0..n % 5 }.map(|_| 'π·');
fives.chain(ones).collect()
}
Some(m) => { 0..n }.map(|_| m).collect(),
- }
+ })
}
#[derive(PartialEq, Eq, Debug)]
None => tally += 1,
Some(ref content) => {
if tally > 0 {
- out.push(HTML(tally_marks(tally, mark)));
+ out.push(tally_marks(tally, mark));
tally = 0;
}
out.push(HTML::escape(content));
}
}
if tally > 0 {
- out.push(HTML(tally_marks(tally, mark)));
+ out.push(tally_marks(tally, mark));
}
HTML(
out.into_iter()
- .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
+ .map(|html| html.0)
.collect::<Vec<_>>()
.join(" "),
)
row.entries.get(notcol).expect("Key vanished?!"),
)
})
- .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
+ .map(|html| html.0)
.collect::<Vec<_>>()
.join(", "),
)
#[test]
fn test_tally_marks() {
- assert_eq!(tally_marks(1, None), "π·");
- assert_eq!(tally_marks(2, None), "π·π·");
- assert_eq!(tally_marks(3, None), "π·π·π·");
- assert_eq!(tally_marks(4, None), "π·π·π·π·");
- assert_eq!(tally_marks(5, None), "πΈ");
- assert_eq!(tally_marks(6, None), "πΈπ·");
- assert_eq!(tally_marks(7, None), "πΈπ·π·");
- assert_eq!(tally_marks(8, None), "πΈπ·π·π·");
- assert_eq!(tally_marks(9, None), "πΈπ·π·π·π·");
- assert_eq!(tally_marks(10, None), "πΈπΈ");
- assert_eq!(tally_marks(11, None), "πΈπΈπ·");
- assert_eq!(tally_marks(1, Some("x")), "x");
- assert_eq!(tally_marks(4, Some("x")), "xxxx");
- assert_eq!(tally_marks(5, Some("x")), "xxxxx");
- assert_eq!(tally_marks(6, Some("x")), "xxxxxx");
- assert_eq!(tally_marks(2, Some("π")), "ππ");
+ assert_eq!(tally_marks(1, None), "π·".into());
+ assert_eq!(tally_marks(2, None), "π·π·".into());
+ assert_eq!(tally_marks(3, None), "π·π·π·".into());
+ assert_eq!(tally_marks(4, None), "π·π·π·π·".into());
+ assert_eq!(tally_marks(5, None), "πΈ".into());
+ assert_eq!(tally_marks(6, None), "πΈπ·".into());
+ assert_eq!(tally_marks(7, None), "πΈπ·π·".into());
+ assert_eq!(tally_marks(8, None), "πΈπ·π·π·".into());
+ assert_eq!(tally_marks(9, None), "πΈπ·π·π·π·".into());
+ assert_eq!(tally_marks(10, None), "πΈπΈ".into());
+ assert_eq!(tally_marks(11, None), "πΈπΈπ·".into());
+ assert_eq!(tally_marks(1, Some("x")), "x".into());
+ assert_eq!(tally_marks(4, Some("x")), "xxxx".into());
+ assert_eq!(tally_marks(5, Some("x")), "xxxxx".into());
+ assert_eq!(tally_marks(6, Some("x")), "xxxxxx".into());
+ assert_eq!(tally_marks(2, Some("π")), "ππ".into());
}
fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {