diff --git a/src/main/kotlin/ru/otus/homework/hw2_fun.kt b/src/main/kotlin/ru/otus/homework/hw2_fun.kt new file mode 100644 index 0000000..32439bd --- /dev/null +++ b/src/main/kotlin/ru/otus/homework/hw2_fun.kt @@ -0,0 +1,45 @@ +package ru.otus.homework + +import java.lang.System.nanoTime + + +fun sumInt (a: Int, b: Int, vararg others: Int) :Int = a+b+others.sum() + +fun connect ( vararg stLine:String, ch:Char=' '):String { + + // проверка на пустой массив stLine + if ( stLine.size == 0 ) {return "" } + var stRet:String = stLine[0] + + var i=1 + + while ( i < stLine.size ) { + + stRet = stRet+ch+stLine[i] + + i++ + } + return stRet +} + +fun calcTimeFun( proc: ()-> Unit):Long { + + val result = nanoTime() + proc() + return nanoTime()-result +} + + + +fun longPrint ( ) { + + val n=50 + var i=0 + while ( i < n ){ + println("nebo") + i++ + } +} + + + diff --git a/src/test/kotlin/ru/otus/homework/hw2_funTest.kt b/src/test/kotlin/ru/otus/homework/hw2_funTest.kt new file mode 100644 index 0000000..9f107c5 --- /dev/null +++ b/src/test/kotlin/ru/otus/homework/hw2_funTest.kt @@ -0,0 +1,28 @@ +package ru.otus.homework + +import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Test + + + +class hw2_funTest { + + @Test + fun sumIntTest() { + + Assertions.assertEquals( + 14, + sumInt(2,3,4,5) + ) + } + + @Test + fun connectTest() { + + Assertions.assertEquals( + "a-b-c", + connect("a","b","c", ch='-') + ) + } + +} \ No newline at end of file