Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/kotlin/ru/otus/homework/homework.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package ru.otus.homework

import kotlin.random.Random
import kotlin.time.measureTime

fun task1(n1: Int, n2: Int, vararg numbers: Int): Int {
return numbers.sum() + n1 +n2
}

fun task2(vararg words: String, separator: Char = ' '): String {
return words.joinToString(separator.toString())
}

fun task4(timedFun: () -> Unit) {
val time = measureTime { timedFun() }
println("|-------------------------------|")
println(" function duration was ${time.inWholeMilliseconds} ms")
println("|-------------------------------|")
}

fun task4Example() {
task4 {
val time = Random.nextLong(1L, 3_000L)
Thread.sleep(time)
}
}

fun main() {
task4Example()
}
26 changes: 26 additions & 0 deletions src/test/kotlin/ru/otus/homework/TaskTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ru.otus.homework

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test

class TaskTest {
@Test
fun task1() {
Assertions.assertEquals(
10,
task1(1,2,3,4)
)
}

@Test
fun task2() {
Assertions.assertEquals(
"str1 str2 str3",
task2("str1", "str2", "str3")
)
Assertions.assertEquals(
"str1,str2,str3",
task2("str1", "str2", "str3", separator = ',')
)
}
}