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() {
|
||||
/*
|
||||
val ticket = AirlineTicket("Bruce", "Eckel", 123456, "DEN", "HND")
|
||||
println(ticket)
|
||||
*/
|
||||
}
|
||||
/* 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:
|
||||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 30
|
||||
length: 143
|
||||
placeholder_text: // Implement AirlineTicket class
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
||||
|
|
|
@ -1,10 +1,30 @@
|
|||
package dataClassesExercise1
|
||||
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import util.TIMEOUT
|
||||
import util.untestable
|
||||
import util.checkParametersOfConstructor
|
||||
import util.loadClass
|
||||
import util.runAndCheckSystemOutput
|
||||
|
||||
class TestDataClassesExercise1 {
|
||||
@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")
|
||||
println(ticket.transferTicket("Svetlana", "Isakova"))
|
||||
}
|
||||
/* Expected output:
|
||||
AirlineTicket(first=Svetlana, last=Isakova, ticket=123456, origin=DEN, destination=HND)
|
||||
/* Output:
|
||||
AirlineTicket(firstName=Svetlana, lastName=Isakova, ticket=123456, origin=DEN, destination=HND)
|
||||
*/
|
|
@ -2,5 +2,9 @@ type: edu
|
|||
files:
|
||||
- name: src/Task.kt
|
||||
visible: true
|
||||
placeholders:
|
||||
- offset: 280
|
||||
length: 70
|
||||
placeholder_text: TODO()
|
||||
- name: test/Tests.kt
|
||||
visible: false
|
||||
|
|
|
@ -4,8 +4,11 @@ import org.junit.Assert
|
|||
import org.junit.Test
|
||||
|
||||
class TestDataClassesExercise2 {
|
||||
@Test fun testSolution() {
|
||||
//TODO: implement your test here
|
||||
Assert.assertTrue("Tests not implemented for the task", false)
|
||||
}
|
||||
@Test
|
||||
fun testTransferTicket() {
|
||||
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