From 237671a0b2777e1ac4e80e63852c3e87431a1868 Mon Sep 17 00:00:00 2001 From: elbaro Date: Sun, 16 Jun 2019 15:26:16 +0900 Subject: [PATCH] Round up reading time --- components/utils/src/site.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/utils/src/site.rs b/components/utils/src/site.rs index 6ae6c105..54bac1c6 100644 --- a/components/utils/src/site.rs +++ b/components/utils/src/site.rs @@ -9,7 +9,7 @@ pub fn get_reading_analytics(content: &str) -> (usize, usize) { // https://help.medium.com/hc/en-us/articles/214991667-Read-time // 275 seems a bit too high though - (word_count, (word_count / 200)) + (word_count, ((word_count + 199) / 200)) } #[derive(Debug, PartialEq, Clone)] @@ -86,11 +86,18 @@ mod tests { assert!(res.is_err()); } + #[test] + fn reading_analytics_empty_text() { + let (word_count, reading_time) = get_reading_analytics(" "); + assert_eq!(word_count, 0); + assert_eq!(reading_time, 0); + } + #[test] fn reading_analytics_short_text() { let (word_count, reading_time) = get_reading_analytics("Hello World"); assert_eq!(word_count, 2); - assert_eq!(reading_time, 0); + assert_eq!(reading_time, 1); } #[test]