Added tests to exercises in 'Data Classes'
This commit is contained in:
parent
5ecfc320c6
commit
5c40324529
|
@ -9,9 +9,11 @@ data class AirlineTicket(
|
||||||
)
|
)
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
|
/*
|
||||||
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
||||||
println(ticket)
|
println(ticket)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
/* Expected output:
|
/* Expected output:
|
||||||
AirlineTicket(first=Bruce, last=Eckel, ticket=123456, origin=DEN, destination=HND)
|
AirlineTicket(firstName=Bruce, lastName=Eckel, ticket=123456, origin=DEN, destination=HND)
|
||||||
*/
|
*/
|
|
@ -2,5 +2,9 @@ type: edu
|
||||||
files:
|
files:
|
||||||
- name: src/Task.kt
|
- name: src/Task.kt
|
||||||
visible: true
|
visible: true
|
||||||
|
placeholders:
|
||||||
|
- offset: 30
|
||||||
|
length: 143
|
||||||
|
placeholder_text: // Implement AirlineTicket class
|
||||||
- name: test/Tests.kt
|
- name: test/Tests.kt
|
||||||
visible: false
|
visible: false
|
||||||
|
|
|
@ -1,10 +1,30 @@
|
||||||
package dataClassesExercise1
|
package dataClassesExercise1
|
||||||
|
|
||||||
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import util.TIMEOUT
|
import util.TIMEOUT
|
||||||
import util.untestable
|
import util.checkParametersOfConstructor
|
||||||
|
import util.loadClass
|
||||||
|
import util.runAndCheckSystemOutput
|
||||||
|
|
||||||
class TestDataClassesExercise1 {
|
class TestDataClassesExercise1 {
|
||||||
@Test(timeout = TIMEOUT)
|
@Test(timeout = TIMEOUT)
|
||||||
fun test() = untestable()
|
fun test() {
|
||||||
|
val ticketClass = loadClass("dataClassesExercise1", "AirlineTicket")
|
||||||
|
|
||||||
|
val constructor = ticketClass.constructors.first()
|
||||||
|
checkParametersOfConstructor(constructor, ticketClass, listOf(
|
||||||
|
"firstName" to "kotlin.String",
|
||||||
|
"lastName" to "kotlin.String",
|
||||||
|
"ticket" to "kotlin.Int",
|
||||||
|
"origin" to "kotlin.String",
|
||||||
|
"destination" to "kotlin.String"
|
||||||
|
))
|
||||||
|
Assert.assertTrue("'AirlineTicket' class is expected to be defined as 'data' class", ticketClass.isData)
|
||||||
|
runAndCheckSystemOutput("Wrong output",
|
||||||
|
"AirlineTicket(firstName=Bruce, lastName=Eckel, ticket=123456, origin=DEN, destination=HND)") {
|
||||||
|
val ticket = constructor.call("Bruce", "Eckel", 123456, "DEN", "HND")
|
||||||
|
println(ticket)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -19,6 +19,6 @@ fun main() {
|
||||||
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
||||||
println(ticket.transferTicket("Svetlana", "Isakova"))
|
println(ticket.transferTicket("Svetlana", "Isakova"))
|
||||||
}
|
}
|
||||||
/* Expected output:
|
/* Output:
|
||||||
AirlineTicket(first=Svetlana, last=Isakova, ticket=123456, origin=DEN, destination=HND)
|
AirlineTicket(firstName=Svetlana, lastName=Isakova, ticket=123456, origin=DEN, destination=HND)
|
||||||
*/
|
*/
|
|
@ -2,5 +2,9 @@ type: edu
|
||||||
files:
|
files:
|
||||||
- name: src/Task.kt
|
- name: src/Task.kt
|
||||||
visible: true
|
visible: true
|
||||||
|
placeholders:
|
||||||
|
- offset: 280
|
||||||
|
length: 70
|
||||||
|
placeholder_text: TODO()
|
||||||
- name: test/Tests.kt
|
- name: test/Tests.kt
|
||||||
visible: false
|
visible: false
|
||||||
|
|
|
@ -4,8 +4,11 @@ import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
class TestDataClassesExercise2 {
|
class TestDataClassesExercise2 {
|
||||||
@Test fun testSolution() {
|
@Test
|
||||||
//TODO: implement your test here
|
fun testTransferTicket() {
|
||||||
Assert.assertTrue("Tests not implemented for the task", false)
|
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
||||||
}
|
Assert.assertEquals("Wrong result after copy",
|
||||||
|
AirlineTicket("Svetlana", "Isakova", 123456, "DEN", "HND"),
|
||||||
|
ticket.transferTicket("Svetlana", "Isakova"))
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue