diff --git a/src/test/kotlin/net/thauvin/erik/readingtime/ReadingTimeTest.kt b/src/test/kotlin/net/thauvin/erik/readingtime/ReadingTimeTest.kt index 5567fbd..99f6bb3 100644 --- a/src/test/kotlin/net/thauvin/erik/readingtime/ReadingTimeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/readingtime/ReadingTimeTest.kt @@ -17,36 +17,54 @@ class ReadingTimeTest { assertEquals(3, wordCount("one two three")) assertEquals(2, wordCount(" one two ")) assertEquals(7, wordCount(rt.text)) - assertEquals(210, wordCount(blogPost)) + assertEquals(505, wordCount(blogPost)) + assertEquals(391, wordCount(mediumPost)) } @Test fun testImgCount() { assertEquals(1, imgCount(rt.text)) - assertEquals(4, imgCount(blogPost)) + assertEquals(11, imgCount(blogPost)) assertEquals(3, imgCount(mediumPost)) } @Test fun testReadingTimeInSec() { assertEquals((wordCount(rt.text) / (rt.wpm / 60.0)) + 12.0, rt.calcReadingTimeInSec()) + rt.text = " " assertEquals(12.0 + 11.0, rt.calcReadingTimeInSec()) + rt.text = blogPost - assertEquals((wordCount(rt.text) / (rt.wpm / 60.0)) + 12.0 + 11.0 + 10.0 + 9.0, rt.calcReadingTimeInSec()) + assertEquals( + (wordCount(rt.text) / (rt.wpm / 60.0)) + 12.0 + 11.0 + 10.0 + 9.0 + 8.0 + 7.0 + 6.0 + 5.0 + 4.0 + 3.0 + 3.0, + rt.calcReadingTimeInSec() + ) + + rt.excludeImages = true + assertEquals((wordCount(rt.text) / (rt.wpm / 60.0)), rt.calcReadingTimeInSec()) + rt.excludeImages = false + rt.text = mediumPost rt.wpm = 300 - assertEquals(wordCount(rt.text) / (rt.wpm / 60.0) + 12.0 + 11.0 + 10.0, rt.calcReadingTimeInSec()) + assertEquals(wordCount(rt.text) / (300.0 / 60.0) + 12.0 + 11.0 + 10.0, rt.calcReadingTimeInSec()) + rt.wpm = 275 } @Test fun testReadingTime() { rt.text = blogPost - assertEquals("2 min read", rt.calcReadingTime()) + assertEquals("4 min read", rt.calcReadingTime()) + rt.plural = "mins read" - assertEquals("2 mins read", rt.calcReadingTime()) + assertEquals("4 mins read", rt.calcReadingTime()) + rt.text = mediumPost rt.plural = "" assertEquals("2", rt.calcReadingTime()) + + rt.text = "This is a test." + rt.postfix = "" + assertEquals("1", rt.calcReadingTime()) } } diff --git a/src/test/resources/medium.html b/src/test/resources/medium.html index 85f39b6..2d28dc5 100644 --- a/src/test/resources/medium.html +++ b/src/test/resources/medium.html @@ -1,46 +1,60 @@ -Eons ago, a couple of Medium engineers got fed up. They were sick of having to scroll all the way down the page to see how long a story was. It was wearing out their trackpad, it was making their fingers sore, and they figured there must be a better way. So they sat down and devised a simple formula, and the Medium read time was born.

-
-
-
-
-
-
Image for post
- Image for post - +
+
+

+ Eons ago, a couple of Medium engineers got fed up. They were sick of having to scroll all the way down the + page to see how long a story was. It was wearing out their trackpad, it was making their fingers sore, and + they figured there must be a better way. So they sat down and devised a simple formula, and the Medium read + time was born.

+
+
+
+
+
+
Image for post
+ Image for post + +
+
+
-
-
+
+

With the widespread + adoption of this feature across the internet, we decided to shed some light on exactly what goes in to + our read time calculation.

+

Read time is based on the + average reading speed of an adult (roughly 275 WPM). We take the total word count of a post and + translate it into minutes. Then, we add 12 seconds for each inline image. Boom, read + time.

+

Lately, we have + seen more and more long form stories containing a ton of images. With our release of image grids, we expect even more of + these types of essays.

+

Our original read + time calculation was geared toward “slow” images, like comics, where you would really want to sit down + and invest in the image. This resulted in articles with crazy big read times. For instance, this article containing 140 images was clocking in at a whopping + 87 minute read. So we amended our read time calculation to count 12 seconds for the first image, 11 for + the second, and minus an additional second for each subsequent image. Any images after the tenth image + are counted at three seconds.

+

You might see this + change reflected across the site. Keep in mind that our estimated read time is just that: an estimation. You might finish a story faster or slower depending on various + factors such as how many children or cats you have, your caffeine/alcohol intake, or if you’re a + time-traveler from the future and already read that story. We just want to give you a ballpark figure so + you can decide whether you have time to read one more story before the bus comes, or if you should + bookmark it for later.

+

We aren’t done with + read time yet. In the future, we’d like to tailor it to your reading speed, account for the complexity of an article, and add + support for other languages. We’ll be sure to let you know about these changes as they happen.

- -

With the widespread - adoption of this feature across the internet, we decided to shed some light on exactly what goes in to our read time - calculation.

-

Read time is based on the average - reading speed of an adult (roughly 275 WPM). We take the total word count of a post and translate it into minutes. - Then, we add 12 seconds for each inline image. Boom, read time.

-

Lately, we have seen more and - more long form stories containing a ton of images. With our release of image grids, we expect even more of these types of essays.

-

Our original read time - calculation was geared toward “slow” images, like comics, where you would really want to sit down and invest in the - image. This resulted in articles with crazy big read times. For instance, this article containing 140 images was clocking in at a whopping 87 minute read. So we amended - our read time calculation to count 12 seconds for the first image, 11 for the second, and minus an additional second - for each subsequent image. Any images after the tenth image are counted at three seconds.

-

You might see this change - reflected across the site. Keep in mind that our estimated read time is just that: an estimation. - You might finish a story faster or slower depending on various factors such as how many children or cats you have, - your caffeine/alcohol intake, or if you’re a time-traveler from the future and already read that story. We just want - to give you a ballpark figure so you can decide whether you have time to read one more story before the bus comes, - or if you should bookmark it for later.

-

We aren’t done with read time - yet. In the future, we’d like to tailor it to your reading speed, account for the complexity of an article, and add support for - other languages. We’ll be sure to let you know about these changes as they happen.

+ diff --git a/src/test/resources/post.html b/src/test/resources/post.html index c0a685d..799fca4 100644 --- a/src/test/resources/post.html +++ b/src/test/resources/post.html @@ -1,6 +1,30 @@

HTML Ipsum Presents

-

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

+

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. + Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas + semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien + ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. + Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

+ +
+
Definition list
+
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna + aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea + commodo consequat.
+
Lorem ipsum dolor sit amet
+
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna + aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea + commodo consequat.
+
+ +

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, + feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies + mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat + wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros + ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. + Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam + erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus

Header Level 2

@@ -10,7 +34,9 @@
  • -

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.

    +

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet + congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus + est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.

    Header Level 3

    @@ -20,7 +46,7 @@
  • -

    Header Level 4

    +

    Header Level 4

    -

    Header Level 5

    +
    Header Level 5
    + + + +
    Header Level 6
    + + + +
    Header Level 6
    + + + +
    Header Level 6
    + + + +
    Header Level 6
    + + + +
    Header Level 6
    + + + +
    Header Level 6
    + + + +
    Header Level 6