Upcasting/Exercise 2 tests
This commit is contained in:
parent
111c4155db
commit
43a1b193dc
|
@ -1,6 +1,7 @@
|
||||||
// Upcasting/UpcastExercise2.kt
|
|
||||||
package upcastingExercise2
|
package upcastingExercise2
|
||||||
|
|
||||||
|
import atomictest.trace
|
||||||
|
|
||||||
interface Apple {
|
interface Apple {
|
||||||
fun consume(): String
|
fun consume(): String
|
||||||
}
|
}
|
||||||
|
@ -29,6 +30,12 @@ fun main() {
|
||||||
Braeburn()
|
Braeburn()
|
||||||
)
|
)
|
||||||
apples.forEach {
|
apples.forEach {
|
||||||
println(it.consume())
|
trace(it.consume())
|
||||||
}
|
}
|
||||||
|
trace eq """
|
||||||
|
chomp GrannySmith
|
||||||
|
bite Gala
|
||||||
|
press Fuji
|
||||||
|
peel Braeburn
|
||||||
|
"""
|
||||||
}
|
}
|
|
@ -3,20 +3,20 @@ files:
|
||||||
- name: src/Task.kt
|
- name: src/Task.kt
|
||||||
visible: true
|
visible: true
|
||||||
placeholders:
|
placeholders:
|
||||||
- offset: 105
|
- offset: 98
|
||||||
length: 76
|
length: 76
|
||||||
placeholder_text: class GrannySmith
|
placeholder_text: class GrannySmith
|
||||||
- offset: 183
|
- offset: 176
|
||||||
length: 61
|
length: 61
|
||||||
placeholder_text: class Gala
|
placeholder_text: class Gala
|
||||||
- offset: 246
|
- offset: 239
|
||||||
length: 62
|
length: 62
|
||||||
placeholder_text: class Fuji
|
placeholder_text: class Fuji
|
||||||
- offset: 310
|
- offset: 303
|
||||||
length: 69
|
length: 69
|
||||||
placeholder_text: class Braeburn
|
placeholder_text: class Braeburn
|
||||||
- offset: 498
|
- offset: 491
|
||||||
length: 25
|
length: 23
|
||||||
placeholder_text: // println(it.consume())
|
placeholder_text: // trace(it.consume())
|
||||||
- name: test/Tests.kt
|
- name: test/Tests.kt
|
||||||
visible: false
|
visible: false
|
||||||
|
|
|
@ -1,11 +1,57 @@
|
||||||
package upcastingExercise2
|
package upcastingExercise2
|
||||||
|
|
||||||
|
import atomictest.trace
|
||||||
|
import org.junit.FixMethodOrder
|
||||||
import org.junit.Test
|
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 {
|
class TestUpcastingExercise2 {
|
||||||
@Test fun testSolution() {
|
|
||||||
//TODO: implement your test here
|
private val packageName = "upcastingExercise2"
|
||||||
unimplementedTest()
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue