diff --git a/src/main/kotlin/me/yujinyan/facktory/text/FileReaders.kt b/src/main/kotlin/me/yujinyan/facktory/text/FileReaders.kt index 281b3e7..71cf0d7 100644 --- a/src/main/kotlin/me/yujinyan/facktory/text/FileReaders.kt +++ b/src/main/kotlin/me/yujinyan/facktory/text/FileReaders.kt @@ -2,7 +2,7 @@ package me.yujinyan.facktory.text import java.io.File -internal fun readTextsUnderResourcePath(path: String) = sequence { +internal fun readTextResource(path: String) = sequence { val resource = javaClass.getResource(path) ?: throw IllegalArgumentException("No resource found under $path") diff --git a/src/main/kotlin/me/yujinyan/facktory/text/MarkovGenerator.kt b/src/main/kotlin/me/yujinyan/facktory/text/MarkovGenerator.kt index 6b23609..4d7c00a 100644 --- a/src/main/kotlin/me/yujinyan/facktory/text/MarkovGenerator.kt +++ b/src/main/kotlin/me/yujinyan/facktory/text/MarkovGenerator.kt @@ -17,7 +17,7 @@ public class MarkovGenerator(private val n: Int) { } } - public fun feedResourcesText(path: String): Unit = readTextsUnderResourcePath(path) + public fun feedTextResource(path: String): Unit = readTextResource(path) .forEach { feed(it) } public fun generate(length: Int): String = buildString { diff --git a/src/test/kotlin/me/yujinyan/facktory/FileReaderTest.kt b/src/test/kotlin/me/yujinyan/facktory/FileReaderTest.kt index 67efd45..9ef89c9 100644 --- a/src/test/kotlin/me/yujinyan/facktory/FileReaderTest.kt +++ b/src/test/kotlin/me/yujinyan/facktory/FileReaderTest.kt @@ -4,25 +4,25 @@ import io.kotest.assertions.throwables.shouldThrow import io.kotest.matchers.sequences.shouldContain import io.kotest.matchers.sequences.shouldHaveSize import io.kotest.matchers.string.shouldContain -import me.yujinyan.facktory.text.readTextsUnderResourcePath +import me.yujinyan.facktory.text.readTextResource import org.junit.jupiter.api.Test class FileReaderTest { @Test fun `can read path`() { - readTextsUnderResourcePath("/factory/text/en") + readTextResource("/factory/text/en") .shouldContain("Hello World!") } @Test fun `can read path with trailing slash`() { - readTextsUnderResourcePath("/factory/text/en/") + readTextResource("/factory/text/en/") .shouldContain("Hello World!") } @Test fun `can read file`() { - readTextsUnderResourcePath("/factory/text/en/Hello.txt") + readTextResource("/factory/text/en/Hello.txt") .apply { shouldHaveSize(1) shouldContain("Hello World!") @@ -32,7 +32,7 @@ class FileReaderTest { @Test fun `throws exception if provided non-existent path`() { shouldThrow { - readTextsUnderResourcePath("/does/not/exist").first() + readTextResource("/does/not/exist").first() }.message shouldContain "/does/not/exist" } } diff --git a/src/test/kotlin/me/yujinyan/facktory/MarkovGeneratorTest.kt b/src/test/kotlin/me/yujinyan/facktory/MarkovGeneratorTest.kt index a95866e..d99f088 100644 --- a/src/test/kotlin/me/yujinyan/facktory/MarkovGeneratorTest.kt +++ b/src/test/kotlin/me/yujinyan/facktory/MarkovGeneratorTest.kt @@ -8,7 +8,7 @@ class MarkovGeneratorTest { @Test fun `can read text from resources`() { val generator = MarkovGenerator(3).apply { - feedResourcesText("/factory/text/cn") + feedTextResource("/factory/text/cn") } repeat(3) { generator.generate(60).also { println(it) }