incomplete assignment bug from EA fixed
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package sum
|
||||
|
||||
import java.util.*
|
||||
fun sum(a : IntArray) : Int {
|
||||
// Write your solution here
|
||||
<!UNRESOLVED_REFERENCE!>res<!> = 0
|
||||
for (e in a)
|
||||
res +=<!SYNTAX!><!>
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun main(args : Array<String>) {
|
||||
test(0)
|
||||
test(1, 1)
|
||||
test(-1, -1, 0)
|
||||
test(6, 1, 2, 3)
|
||||
test(6, 1, 1, 1, 1, 1, 1)
|
||||
}
|
||||
// HELPER FUNCTIONS
|
||||
fun test(expectedSum : Int, vararg data : Int) {
|
||||
val actualSum = sum(data)
|
||||
assertEquals(actualSum, expectedSum, "\ndata = ${Arrays.toString(data)}\n" +
|
||||
"sum(data) = ${actualSum}, but must be $expectedSum ")
|
||||
}
|
||||
fun assertEquals<T>(actual : T?, expected : T?, message : Any? = null) {
|
||||
if (actual != expected) {
|
||||
if (message == null)
|
||||
throw AssertionError()
|
||||
else
|
||||
throw AssertionError(message)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user