Basic Class Initialization/Exercise 2 tests
This commit is contained in:
parent
856e83389b
commit
4cd6b54e2b
|
@ -1,8 +1,10 @@
|
|||
package baseClassInitializationExercise2
|
||||
|
||||
import atomictest.trace
|
||||
|
||||
open class Plate(description: String) {
|
||||
init {
|
||||
println("Plate-$description")
|
||||
trace("Plate-$description")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +12,7 @@ class DinnerPlate : Plate("DinnerPlate")
|
|||
|
||||
open class Utensil(description: String) {
|
||||
init {
|
||||
println("Utensil-$description")
|
||||
trace("Utensil-$description")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +24,7 @@ class Knife : Utensil("Knife")
|
|||
|
||||
open class Custom {
|
||||
init {
|
||||
println("Custom")
|
||||
trace("Custom")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,10 +34,18 @@ class PlaceSetting : Custom() {
|
|||
val knife = Knife()
|
||||
val plate = DinnerPlate()
|
||||
init {
|
||||
println("PlaceSetting")
|
||||
trace("PlaceSetting")
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
PlaceSetting()
|
||||
trace eq """
|
||||
Custom
|
||||
Utensil-Spoon
|
||||
Utensil-Fork
|
||||
Utensil-Knife
|
||||
Plate-DinnerPlate
|
||||
PlaceSetting
|
||||
"""
|
||||
}
|
|
@ -3,8 +3,8 @@ files:
|
|||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 420
|
||||
length: 166
|
||||
- offset: 439
|
||||
length: 164
|
||||
placeholder_text: class PlaceSetting
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
||||
|
|
|
@ -1,11 +1,50 @@
|
|||
package baseClassInitializationExercise2
|
||||
|
||||
import org.junit.FixMethodOrder
|
||||
import org.junit.Test
|
||||
import util.unimplementedTest
|
||||
import org.junit.runners.MethodSorters
|
||||
import util.*
|
||||
import kotlin.reflect.full.createInstance
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
class TestBaseClassInitializationExercise2 {
|
||||
@Test fun testSolution() {
|
||||
//TODO: implement your test here
|
||||
unimplementedTest()
|
||||
|
||||
private val packageName = "baseClassInitializationExercise2"
|
||||
|
||||
@Test
|
||||
fun `#01 classes structure`() {
|
||||
loadClass(packageName, "DinnerPlate").apply {
|
||||
assertInheritance("Plate")
|
||||
}
|
||||
loadClass(packageName, "Spoon").apply {
|
||||
assertInheritance("Utensil")
|
||||
}
|
||||
loadClass(packageName, "Fork").apply {
|
||||
assertInheritance("Utensil")
|
||||
}
|
||||
loadClass(packageName, "Knife").apply {
|
||||
assertInheritance("Utensil")
|
||||
}
|
||||
loadClass(packageName, "PlaceSetting").apply {
|
||||
assertInheritance("Custom")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `#02 initialisation`() {
|
||||
loadClass(packageName, "PlaceSetting").createInstance()
|
||||
assertEquals(
|
||||
message = "Incorrect result of PlaceSetting initialisation",
|
||||
actual = loadTraceContent(),
|
||||
expected = listOf(
|
||||
"Custom",
|
||||
"Utensil-Spoon",
|
||||
"Utensil-Fork",
|
||||
"Utensil-Knife",
|
||||
"Plate-DinnerPlate",
|
||||
"PlaceSetting"
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -21,5 +21,13 @@ files:
|
|||
|
||||
fun poll(): E = removeAt(0)
|
||||
}
|
||||
- offset: 752
|
||||
length: 17
|
||||
placeholder_text: stack[0] eq 1
|
||||
- offset: 943
|
||||
length: 45
|
||||
placeholder_text: |-
|
||||
queue.add(2, "???")
|
||||
queue[2] eq "???"
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
||||
|
|
Loading…
Reference in New Issue