Skip to content

Instantly share code, notes, and snippets.

@augustovictor
Created November 27, 2018 11:37
Show Gist options
  • Select an option

  • Save augustovictor/707d80ee58c8e3d1969ebe9566fa9a38 to your computer and use it in GitHub Desktop.

Select an option

Save augustovictor/707d80ee58c8e3d1969ebe9566fa9a38 to your computer and use it in GitHub Desktop.
import org.junit.Assert.assertEquals
import org.junit.Test
class Wrapper {
companion object {
fun wrap(s: String, lineSize: Int): String {
var formattedString = ""
formattedString += if (s.length > lineSize) s.substring(0, lineSize) + "\n" + wrap(s.substring(lineSize), lineSize) else s
return formattedString
}
}
}
class WordWrapperTest {
@Test
fun `should wrap a 1 1`() {
assertEquals("x", Wrapper.wrap("x", 1))
assertEquals("a", Wrapper.wrap("a", 1))
}
@Test
fun `should wrap a 2 1`() {
assertEquals("x\nx", Wrapper.wrap("xx", 1))
assertEquals("a\na", Wrapper.wrap("aa", 1))
}
@Test
fun `should wrap a 3 2`() {
val word = Wrapper.wrap("xxx", 2)
assertEquals("xx\nx", word)
}
@Test
fun `should wrap a 4 1`() {
assertEquals("x\nx\nx\nx", Wrapper.wrap("xxxx", 1))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment