diff --git a/Object-Oriented Programming/Base Class Initialization/Exercise 2/src/Task.kt b/Object-Oriented Programming/Base Class Initialization/Exercise 2/src/Task.kt index 8a67f26e..5e78d925 100644 --- a/Object-Oriented Programming/Base Class Initialization/Exercise 2/src/Task.kt +++ b/Object-Oriented Programming/Base Class Initialization/Exercise 2/src/Task.kt @@ -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 + """ } \ No newline at end of file diff --git a/Object-Oriented Programming/Base Class Initialization/Exercise 2/task-info.yaml b/Object-Oriented Programming/Base Class Initialization/Exercise 2/task-info.yaml index ee0e78c4..9f0bcf93 100644 --- a/Object-Oriented Programming/Base Class Initialization/Exercise 2/task-info.yaml +++ b/Object-Oriented Programming/Base Class Initialization/Exercise 2/task-info.yaml @@ -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 diff --git a/Object-Oriented Programming/Base Class Initialization/Exercise 2/test/Tests.kt b/Object-Oriented Programming/Base Class Initialization/Exercise 2/test/Tests.kt index fe023162..c2d2ec2c 100644 --- a/Object-Oriented Programming/Base Class Initialization/Exercise 2/test/Tests.kt +++ b/Object-Oriented Programming/Base Class Initialization/Exercise 2/test/Tests.kt @@ -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" + ) + ) + } } \ No newline at end of file diff --git a/Object-Oriented Programming/Composition/Exercise 2/task-info.yaml b/Object-Oriented Programming/Composition/Exercise 2/task-info.yaml index 1a7c9a63..49ffd409 100644 --- a/Object-Oriented Programming/Composition/Exercise 2/task-info.yaml +++ b/Object-Oriented Programming/Composition/Exercise 2/task-info.yaml @@ -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