1
1
Fork 0

Upcasting/Exercise 2 tests

This commit is contained in:
Pavel Nikolaev 2020-07-30 18:00:11 +02:00
parent 111c4155db
commit 43a1b193dc
3 changed files with 66 additions and 13 deletions

View File

@ -1,6 +1,7 @@
// Upcasting/UpcastExercise2.kt
package upcastingExercise2
import atomictest.trace
interface Apple {
fun consume(): String
}
@ -29,6 +30,12 @@ fun main() {
Braeburn()
)
apples.forEach {
println(it.consume())
trace(it.consume())
}
trace eq """
chomp GrannySmith
bite Gala
press Fuji
peel Braeburn
"""
}

View File

@ -3,20 +3,20 @@ files:
- name: src/Task.kt
visible: true
placeholders:
- offset: 105
- offset: 98
length: 76
placeholder_text: class GrannySmith
- offset: 183
- offset: 176
length: 61
placeholder_text: class Gala
- offset: 246
- offset: 239
length: 62
placeholder_text: class Fuji
- offset: 310
- offset: 303
length: 69
placeholder_text: class Braeburn
- offset: 498
length: 25
placeholder_text: // println(it.consume())
- offset: 491
length: 23
placeholder_text: // trace(it.consume())
- name: test/Tests.kt
visible: false

View File

@ -1,11 +1,57 @@
package upcastingExercise2
import atomictest.trace
import org.junit.FixMethodOrder
import org.junit.Test
import util.unimplementedTest
import org.junit.runners.MethodSorters
import util.*
import kotlin.reflect.KClass
import kotlin.reflect.full.createInstance
import kotlin.test.assertEquals
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class TestUpcastingExercise2 {
@Test fun testSolution() {
//TODO: implement your test here
unimplementedTest()
private val packageName = "upcastingExercise2"
private fun loadClass(className: String): KClass<*> = loadClass(packageName, className)
@Test
fun `#01 classes structure`() {
loadClass("Apple").apply {
assertInterface()
assertDeclaredMemberFunction("consume")
}
listOf("GrannySmith", "Gala", "Fuji", "Braeburn").forEach {
loadClass(it).apply {
assertAbstract(expected = false)
assertInheritance("Apple")
assertDeclaredMemberFunction("consume")
}
}
}
@Test
fun `#02 consume apples`() {
listOf("GrannySmith", "Gala", "Fuji", "Braeburn").forEach {
loadClass("Apple").apply {
val consume = assertDeclaredMemberFunction("consume")
val apple = loadClass(it).createInstance()
trace(consume.call(apple) as String)
}
}
assertEquals(
message = "Incorrect sequence of actions applied to the apples",
actual = loadTraceContent(),
expected = listOf(
"chomp GrannySmith",
"bite Gala",
"press Fuji",
"peel Braeburn"
)
)
}
}