diff --git a/src/main/kotlin/ru/otus/homework/homework.kt b/src/main/kotlin/ru/otus/homework/homework.kt new file mode 100644 index 0000000..246f8cd --- /dev/null +++ b/src/main/kotlin/ru/otus/homework/homework.kt @@ -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() +} \ No newline at end of file diff --git a/src/test/kotlin/ru/otus/homework/TaskTest.kt b/src/test/kotlin/ru/otus/homework/TaskTest.kt new file mode 100644 index 0000000..14f3d2b --- /dev/null +++ b/src/test/kotlin/ru/otus/homework/TaskTest.kt @@ -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 = ',') + ) + } +} \ No newline at end of file