diff --git a/.gitignore b/.gitignore index 2822a599b..8ad48cdeb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,16 @@ out + +# IDEA .idea +*.iml +local.properties + +# Gradle .gradle build -local.properties -*.iml + +# Eclipse +bin +.settings +.project +.classpath diff --git a/README.md b/README.md index 594be3332..d09aee3ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -[![official JetBrains project](http://jb.gg/badges/official-plastic.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) +[![obsolete JetBrains project](https://jb.gg/badges/obsolete-plastic.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) + +### This project is obsolete. +### For the last version of Koans, check [the course](https://www.jetbrains.com/help/education/learner-start-guide.html?section=Kotlin%20Koans) in [the EduTools plugin](https://www.jetbrains.com/help/education/install-edutools-plugin.html?section=IntelliJ%20IDEA) or [online version](https://play.kotlinlang.org/koans/overview). +### The task content can be found at https://github.com/Kotlin/kotlin-koans-edu. Kotlin Koans =========== @@ -80,6 +84,6 @@ You can find [here](https://www.jetbrains.com/help/idea/navigating-to-action.htm You can solve the similar tasks using Educational Plugin or in the browser: - EduTools Plugin https://www.jetbrains.com/help/education/learner-start-guide.html?section=Kotlin%20Koans -- online version of koans http://try.kotl.in +- online version of koans https://try.kotl.in The koans tasks for web-demo and educational plugin can be found here: https://github.com/Kotlin/kotlin-koans-edu diff --git a/build.gradle b/build.gradle index 5376b74d5..ea0bbf3cc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.2.10' + ext.kotlin_version = '1.3.21' repositories { mavenCentral() @@ -23,6 +23,10 @@ repositories { dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - compile 'com.google.guava:guava:16.0' - testCompile 'junit:junit:4.12' + compile 'com.google.guava:guava:28.0-jre' + testCompile 'org.junit.jupiter:junit-jupiter:5.4.0' } + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 15b8ed9a8..440702935 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip diff --git a/src/i_introduction/_0_Hello_World/n00Start.kt b/src/i_introduction/_0_Hello_World/n00Start.kt index 352ca5bfc..febe6b0ad 100644 --- a/src/i_introduction/_0_Hello_World/n00Start.kt +++ b/src/i_introduction/_0_Hello_World/n00Start.kt @@ -3,6 +3,21 @@ package i_introduction._0_Hello_World import util.TODO import util.doc0 +/* + +Note that this project is obsolete. +For the last version of Koans, check either +online version + - https://play.kotlinlang.org/koans/overview +or +the course in the EduTools plugin + - https://www.jetbrains.com/help/education/learner-start-guide.html?section=Kotlin%20Koans + - https://www.jetbrains.com/help/education/install-edutools-plugin.html?section=IntelliJ%20IDEA + +The task content can be found at https://github.com/Kotlin/kotlin-koans-edu. + + */ + fun todoTask0(): Nothing = TODO( """ Task 0. diff --git a/src/i_introduction/_5_String_Templates/n05StringTemplates.kt b/src/i_introduction/_5_String_Templates/n05StringTemplates.kt index e8bfc187b..7b7f9b625 100644 --- a/src/i_introduction/_5_String_Templates/n05StringTemplates.kt +++ b/src/i_introduction/_5_String_Templates/n05StringTemplates.kt @@ -4,15 +4,15 @@ import util.TODO import util.doc5 fun example1(a: Any, b: Any) = - "This is some text in which variables ($a, $b) appear." + "This is some text in which variables ($a, $b) appear." fun example2(a: Any, b: Any) = - "You can write it in a Java way as well. Like this: " + a + ", " + b + "!" + "You can write it in a Java way as well. Like this: " + a + ", " + b + "!" fun example3(c: Boolean, x: Int, y: Int) = "Any expression can be used: ${if (c) x else y}" fun example4() = - """ + """ You can use raw strings to write multiline text. There is no escaping here, so raw strings are useful for writing regex patterns, you don't need to escape a backslash by a backslash. diff --git a/src/i_introduction/_7_Nullable_Types/n07NullableTypes.kt b/src/i_introduction/_7_Nullable_Types/n07NullableTypes.kt index 2bb3171b7..1d0109436 100644 --- a/src/i_introduction/_7_Nullable_Types/n07NullableTypes.kt +++ b/src/i_introduction/_7_Nullable_Types/n07NullableTypes.kt @@ -23,13 +23,13 @@ fun todoTask7(client: Client?, message: String?, mailer: Mailer): Nothing = TODO ) fun sendMessageToClient( - client: Client?, message: String?, mailer: Mailer + client: Client?, message: String?, mailer: Mailer ) { todoTask7(client, message, mailer) } -class Client (val personalInfo: PersonalInfo?) -class PersonalInfo (val email: String?) +class Client(val personalInfo: PersonalInfo?) +class PersonalInfo(val email: String?) interface Mailer { fun sendMessage(email: String, message: String) diff --git a/src/i_introduction/_8_Smart_Casts/n08SmartCasts.kt b/src/i_introduction/_8_Smart_Casts/n08SmartCasts.kt index 16db662f3..6f3a6675e 100644 --- a/src/i_introduction/_8_Smart_Casts/n08SmartCasts.kt +++ b/src/i_introduction/_8_Smart_Casts/n08SmartCasts.kt @@ -6,14 +6,15 @@ import util.doc8 // 'sealed' modifier restricts the type hierarchy: // all the subclasses must be declared in the same file sealed class Expr + class Num(val value: Int) : Expr() class Sum(val left: Expr, val right: Expr) : Expr() fun eval(e: Expr): Int = - when (e) { - is Num -> todoTask8(e) - is Sum -> todoTask8(e) - } + when (e) { + is Num -> todoTask8(e) + is Sum -> todoTask8(e) + } fun todoTask8(expr: Expr): Nothing = TODO( """ diff --git a/src/ii_collections/n16FlatMap.kt b/src/ii_collections/n16FlatMap.kt index 8601e523b..22f9b92f4 100644 --- a/src/ii_collections/n16FlatMap.kt +++ b/src/ii_collections/n16FlatMap.kt @@ -7,12 +7,14 @@ fun example() { result == listOf('a', 'b', 'c', '1', '2') } -val Customer.orderedProducts: Set get() { - // Return all products this customer has ordered - todoCollectionTask() -} +val Customer.orderedProducts: Set + get() { + // Return all products this customer has ordered + todoCollectionTask() + } -val Shop.allOrderedProducts: Set get() { - // Return all products that were ordered by at least one customer - todoCollectionTask() -} +val Shop.allOrderedProducts: Set + get() { + // Return all products that were ordered by at least one customer + todoCollectionTask() + } diff --git a/src/ii_collections/n19Sum.kt b/src/ii_collections/n19Sum.kt index 5704a29cc..bfd89c56b 100644 --- a/src/ii_collections/n19Sum.kt +++ b/src/ii_collections/n19Sum.kt @@ -7,6 +7,6 @@ fun example6() { fun Customer.getTotalOrderPrice(): Double { // Return the sum of prices of all products that a customer has ordered. - // Note: a customer may order the same product for several times. + // Note: a customer may order the same product several times. todoCollectionTask() } diff --git a/src/ii_collections/n22Fold.kt b/src/ii_collections/n22Fold.kt index ddfc0461c..2fd2f2fcb 100644 --- a/src/ii_collections/n22Fold.kt +++ b/src/ii_collections/n22Fold.kt @@ -8,14 +8,13 @@ fun example9() { // The same as fun whatFoldDoes(): Int { var result = 1 - listOf(1, 2, 3, 4).forEach { element -> result = element * result} + listOf(1, 2, 3, 4).forEach { element -> result = element * result } return result } fun Shop.getSetOfProductsOrderedByEachCustomer(): Set { // Return the set of products that were ordered by each of the customers - return customers.fold(allOrderedProducts, { - orderedByAll, customer -> + return customers.fold(allOrderedProducts, { orderedByAll, customer -> todoCollectionTask() }) } diff --git a/src/ii_collections/n24ExtensionsOnCollections.kt b/src/ii_collections/n24ExtensionsOnCollections.kt index 1d7cc64dd..3188c180e 100644 --- a/src/ii_collections/n24ExtensionsOnCollections.kt +++ b/src/ii_collections/n24ExtensionsOnCollections.kt @@ -8,7 +8,7 @@ fun todoTask24(): Nothing = TODO( The function should do the same as '_24_JavaCode.doSomethingStrangeWithCollection'. Replace all invocations of 'todoTask24()' with the appropriate code. """, - references = { c: Collection -> _24_JavaCode().doSomethingStrangeWithCollection(c) } + references = { c: Collection -> _24_JavaCode().doSomethingStrangeWithCollection(c) } ) fun doSomethingStrangeWithCollection(collection: Collection): Collection? { diff --git a/src/ii_collections/todoUtil.kt b/src/ii_collections/todoUtil.kt index fdeea5754..ce8e75f16 100644 --- a/src/ii_collections/todoUtil.kt +++ b/src/ii_collections/todoUtil.kt @@ -3,10 +3,10 @@ package ii_collections import util.TODO fun todoCollectionTask(): Nothing = TODO( - """ + """ Common task for working with collections. Look through the Shop API, which all the tasks are using. Each individual task is described in the function name and the comment. """, - references = { shop: Shop -> shop.customers } + references = { shop: Shop -> shop.customers } ) diff --git a/src/iii_conventions/MyDateUtil.kt b/src/iii_conventions/MyDateUtil.kt index 1e97d97ec..dfa7d1f99 100644 --- a/src/iii_conventions/MyDateUtil.kt +++ b/src/iii_conventions/MyDateUtil.kt @@ -1,6 +1,6 @@ package iii_conventions -import iii_conventions.TimeInterval.* +import iii_conventions.TimeInterval.DAY import java.util.* fun MyDate.nextDay() = addTimeIntervals(DAY, 1) diff --git a/src/iii_conventions/n28ForLoop.kt b/src/iii_conventions/n28ForLoop.kt index 520b4297f..1f4369566 100644 --- a/src/iii_conventions/n28ForLoop.kt +++ b/src/iii_conventions/n28ForLoop.kt @@ -4,18 +4,22 @@ import util.TODO import util.doc28 fun iterateOverCollection(collection: Collection) { - for (element in collection) {} + for (element in collection) { + } } fun iterateOverString() { // You can iterate over anything that has an 'iterator' method, member or extension. - for (c in "abcd") {} + for (c in "abcd") { + } "abcd".iterator() //library extension method } fun iterateOverRange() { - for (i in 1..10) {} - for (c in 'a'..'z') {} + for (i in 1..10) { + } + for (c in 'a'..'z') { + } } fun todoTask28(): Nothing = TODO( diff --git a/src/iii_conventions/n29OperatorsOverloading.kt b/src/iii_conventions/n29OperatorsOverloading.kt index 5dcd71615..3f96b416f 100644 --- a/src/iii_conventions/n29OperatorsOverloading.kt +++ b/src/iii_conventions/n29OperatorsOverloading.kt @@ -1,7 +1,7 @@ package iii_conventions -import util.TODO import iii_conventions.TimeInterval.* +import util.TODO fun todoTask29(): Nothing = TODO( """ diff --git a/src/iv_properties/n35HowDelegatesWork.kt b/src/iv_properties/n35HowDelegatesWork.kt index 8f409f971..0462f5556 100644 --- a/src/iv_properties/n35HowDelegatesWork.kt +++ b/src/iv_properties/n35HowDelegatesWork.kt @@ -16,7 +16,7 @@ fun todoTask35(): Nothing = TODO( Store only the time in milliseconds in 'timeInMillis' property. Use the extension functions 'MyDate.toMillis' and 'Long.toDate'. """, - references = { date: MyDate -> date.toMillis().toDate()} + references = { date: MyDate -> date.toMillis().toDate() } ) class D { diff --git a/src/util/kotlinUtil.kt b/src/util/kotlinUtil.kt index e70e5e60a..3e3704fbf 100644 --- a/src/util/kotlinUtil.kt +++ b/src/util/kotlinUtil.kt @@ -2,9 +2,9 @@ package util @Suppress("UNUSED_PARAMETER") fun TODO( - task: String, - documentation: Unit = Unit, - references: Function = {} + task: String, + documentation: Unit = Unit, + references: Function = {} ): Nothing = throw NotImplementedException(task) class NotImplementedException(message: String) : Exception(message) \ No newline at end of file diff --git a/src/v_builders/data.kt b/src/v_builders/data.kt index becd3dbdb..8e089bd68 100644 --- a/src/v_builders/data.kt +++ b/src/v_builders/data.kt @@ -20,4 +20,4 @@ val crocodile = Product("crocodile", 20000.2, 1) val cushion = Product("cushion", 131.0, 0) fun getProducts() = listOf(cactus, cake, camera, car, carrot, cellPhone, chimney, certificate, cigar, coffee, coffeeMaker, - cola, cranberry, crocs, crocodile, cushion) \ No newline at end of file + cola, cranberry, crocs, crocodile, cushion) \ No newline at end of file diff --git a/src/v_builders/html.kt b/src/v_builders/html.kt index 7cdd04925..680bef9e4 100644 --- a/src/v_builders/html.kt +++ b/src/v_builders/html.kt @@ -14,40 +14,40 @@ open class Tag(val name: String) { } } -class Attribute(val name : String, val value : String) { +class Attribute(val name: String, val value: String) { override fun toString() = """$name="$value"""" } -fun T.set(name: String, value: String?): T { +fun T.set(name: String, value: String?): T { if (value != null) { attributes.add(Attribute(name, value)) } return this } -fun Tag.doInit(tag: T, init: T.() -> Unit): T { +fun Tag.doInit(tag: T, init: T.() -> Unit): T { tag.init() children.add(tag) return tag } -class Html: Tag("html") -class Table: Tag("table") -class Center: Tag("center") -class TR: Tag("tr") -class TD: Tag("td") -class Text(val text: String): Tag("b") { +class Html : Tag("html") +class Table : Tag("table") +class Center : Tag("center") +class TR : Tag("tr") +class TD : Tag("td") +class Text(val text: String) : Tag("b") { override fun toString() = text } fun html(init: Html.() -> Unit): Html = Html().apply(init) -fun Html.table(init : Table.() -> Unit) = doInit(Table(), init) -fun Html.center(init : Center.() -> Unit) = doInit(Center(), init) +fun Html.table(init: Table.() -> Unit) = doInit(Table(), init) +fun Html.center(init: Center.() -> Unit) = doInit(Center(), init) -fun Table.tr(color: String? = null, init : TR.() -> Unit) = doInit(TR(), init).set("bgcolor", color) +fun Table.tr(color: String? = null, init: TR.() -> Unit) = doInit(TR(), init).set("bgcolor", color) -fun TR.td(color: String? = null, align : String = "left", init : TD.() -> Unit) = doInit(TD(), init).set("align", align).set("bgcolor", color) +fun TR.td(color: String? = null, align: String = "left", init: TD.() -> Unit) = doInit(TD(), init).set("align", align).set("bgcolor", color) -fun Tag.text(s : Any?) = doInit(Text(s.toString()), {}) +fun Tag.text(s: Any?) = doInit(Text(s.toString()), {}) diff --git a/src/v_builders/htmlDemo.kt b/src/v_builders/htmlDemo.kt index e45ab7d18..59ba4feb7 100644 --- a/src/v_builders/htmlDemo.kt +++ b/src/v_builders/htmlDemo.kt @@ -8,7 +8,7 @@ import javax.swing.SwingConstants.CENTER fun main(args: Array) { - with (JFrame("Product popularity")) { + with(JFrame("Product popularity")) { setSize(600, 600) defaultCloseOperation = JFrame.EXIT_ON_CLOSE add(JScrollPane(JLabel(renderProductTable(), CENTER))) diff --git a/src/v_builders/n37StringAndMapBuilders.kt b/src/v_builders/n37StringAndMapBuilders.kt index acf976b2c..76e554f5a 100644 --- a/src/v_builders/n37StringAndMapBuilders.kt +++ b/src/v_builders/n37StringAndMapBuilders.kt @@ -1,7 +1,6 @@ package v_builders import util.TODO -import java.util.* fun buildStringExample(): String { fun buildString(build: StringBuilder.() -> Unit): String { diff --git a/src/v_builders/n39HtmlBuilders.kt b/src/v_builders/n39HtmlBuilders.kt index 8a50a6e19..578d50521 100644 --- a/src/v_builders/n39HtmlBuilders.kt +++ b/src/v_builders/n39HtmlBuilders.kt @@ -6,7 +6,7 @@ import v_builders.data.getProducts import v_builders.htmlLibrary.* fun getTitleColor() = "#b9c9fe" -fun getCellColor(row: Int, column: Int) = if ((row + column) %2 == 0) "#dce4ff" else "#eff2ff" +fun getCellColor(row: Int, column: Int) = if ((row + column) % 2 == 0) "#dce4ff" else "#eff2ff" fun todoTask39(): Nothing = TODO( """ diff --git a/src/v_builders/n40BuildersHowItWorks.kt b/src/v_builders/n40BuildersHowItWorks.kt index ca7e53930..95a8a705e 100644 --- a/src/v_builders/n40BuildersHowItWorks.kt +++ b/src/v_builders/n40BuildersHowItWorks.kt @@ -32,7 +32,7 @@ fun task40() = linkedMapOf( b. function declaration c. function invocation */ - 1 to insertAnswerHere(), + 1 to insertAnswerHere(), /* 2. In the Kotlin code @@ -49,7 +49,7 @@ fun task40() = linkedMapOf( b. argument name c. argument value */ - 2 to insertAnswerHere(), + 2 to insertAnswerHere(), /* 3. The block @@ -62,7 +62,7 @@ from the previous question is: c. something mysterious */ - 3 to insertAnswerHere(), + 3 to insertAnswerHere(), /* 4. For the code @@ -84,5 +84,5 @@ which of the following is true: } } */ - 4 to insertAnswerHere() + 4 to insertAnswerHere() ) diff --git a/src/vi_generics/n41GenericFunctions.kt b/src/vi_generics/n41GenericFunctions.kt index 4a58b02aa..38d333c9c 100644 --- a/src/vi_generics/n41GenericFunctions.kt +++ b/src/vi_generics/n41GenericFunctions.kt @@ -13,10 +13,10 @@ fun task41(): Nothing = TODO( You should write a function that splits the collection into two collections given as arguments. The signature of the 'toCollection()' function from the standard library may help you. """, - references = { l: List -> - l.partition { it > 0 } - l.toCollection(HashSet()) - } + references = { l: List -> + l.partition { it > 0 } + l.toCollection(HashSet()) + } ) fun List.partitionWordsAndLines(): Pair, List> { diff --git a/test/i_introduction/_0_Hello_World/N00StartKtTest.kt b/test/i_introduction/_0_Hello_World/N00StartKtTest.kt index fba012b64..c54f2945e 100644 --- a/test/i_introduction/_0_Hello_World/N00StartKtTest.kt +++ b/test/i_introduction/_0_Hello_World/N00StartKtTest.kt @@ -1,10 +1,11 @@ package i_introduction._0_Hello_World -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N00StartKtTest { - @Test fun testOk() { + @Test + fun testOk() { assertEquals("OK", task0()) } } \ No newline at end of file diff --git a/test/i_introduction/_10_Object_Expressions/N10ObjectExpressionsKtTest.kt b/test/i_introduction/_10_Object_Expressions/N10ObjectExpressionsKtTest.kt index e4109778c..0e1924707 100644 --- a/test/i_introduction/_10_Object_Expressions/N10ObjectExpressionsKtTest.kt +++ b/test/i_introduction/_10_Object_Expressions/N10ObjectExpressionsKtTest.kt @@ -1,10 +1,11 @@ package i_introduction._10_Object_Expressions -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N10ObjectExpressionsKtTest { - @Test fun testSort() { + @Test + fun testSort() { assertEquals(listOf(5, 2, 1), task10()) } } diff --git a/test/i_introduction/_11_SAM_Conversions/N11SAMConversionsKtTest.kt b/test/i_introduction/_11_SAM_Conversions/N11SAMConversionsKtTest.kt index e8ea97fce..f07bf41d3 100644 --- a/test/i_introduction/_11_SAM_Conversions/N11SAMConversionsKtTest.kt +++ b/test/i_introduction/_11_SAM_Conversions/N11SAMConversionsKtTest.kt @@ -1,10 +1,11 @@ package i_introduction._11_SAM_Conversions -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N11SAMConversionsKtTest { - @Test fun testSort() { + @Test + fun testSort() { assertEquals(listOf(5, 2, 1), task11()) } } diff --git a/test/i_introduction/_12_Extensions_On_Collections/N12ExtensionsOnCollectionsKtTest.kt b/test/i_introduction/_12_Extensions_On_Collections/N12ExtensionsOnCollectionsKtTest.kt index 3c15f1764..801a0c0ba 100644 --- a/test/i_introduction/_12_Extensions_On_Collections/N12ExtensionsOnCollectionsKtTest.kt +++ b/test/i_introduction/_12_Extensions_On_Collections/N12ExtensionsOnCollectionsKtTest.kt @@ -1,10 +1,11 @@ package i_introduction._12_Extensions_On_Collections -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N12ExtensionsOnCollectionsKtTest { - @Test fun testSort() { + @Test + fun testSort() { assertEquals(listOf(5, 2, 1), task12()) } } diff --git a/test/i_introduction/_1_Java_To_Kotlin_Converter/N01JavaToKotlinConverterKtTest.kt b/test/i_introduction/_1_Java_To_Kotlin_Converter/N01JavaToKotlinConverterKtTest.kt index 8ec1046bf..c6a27b920 100644 --- a/test/i_introduction/_1_Java_To_Kotlin_Converter/N01JavaToKotlinConverterKtTest.kt +++ b/test/i_introduction/_1_Java_To_Kotlin_Converter/N01JavaToKotlinConverterKtTest.kt @@ -1,10 +1,11 @@ package i_introduction._1_Java_To_Kotlin_Converter -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N01JavaToKotlinConverterKtTest { - @Test fun collection() { + @Test + fun collection() { assertEquals("{1, 2, 3, 42, 555}", task1(listOf(1, 2, 3, 42, 555))) } } diff --git a/test/i_introduction/_2_Named_Arguments/N02NamedArgumentsKtTest.kt b/test/i_introduction/_2_Named_Arguments/N02NamedArgumentsKtTest.kt index 4fe3a86c7..0463722d5 100644 --- a/test/i_introduction/_2_Named_Arguments/N02NamedArgumentsKtTest.kt +++ b/test/i_introduction/_2_Named_Arguments/N02NamedArgumentsKtTest.kt @@ -1,10 +1,12 @@ package i_introduction._2_Named_Arguments -import org.junit.Assert.assertEquals +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N02NamedArgumentsKtTest { - @org.junit.Test fun testJoinToString() { + @Test + fun testJoinToString() { assertEquals("{1, 2, 3, 42, 555}", task2(listOf(1, 2, 3, 42, 555))) } diff --git a/test/i_introduction/_3_Default_Arguments/N03DefaultArgumentsKtTest.kt b/test/i_introduction/_3_Default_Arguments/N03DefaultArgumentsKtTest.kt index 5e2c142e4..1a23ff522 100644 --- a/test/i_introduction/_3_Default_Arguments/N03DefaultArgumentsKtTest.kt +++ b/test/i_introduction/_3_Default_Arguments/N03DefaultArgumentsKtTest.kt @@ -1,11 +1,12 @@ package i_introduction._3_Default_Arguments -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N03DefaultArgumentsKtTest { - @Test fun testDefaultAndNamedParams() { + @Test + fun testDefaultAndNamedParams() { assertEquals("a42b1C42D2", task3()) } } \ No newline at end of file diff --git a/test/i_introduction/_4_Lambdas/N04LambdasKtTest.kt b/test/i_introduction/_4_Lambdas/N04LambdasKtTest.kt index 341cf671b..ae198252e 100644 --- a/test/i_introduction/_4_Lambdas/N04LambdasKtTest.kt +++ b/test/i_introduction/_4_Lambdas/N04LambdasKtTest.kt @@ -1,15 +1,17 @@ package i_introduction._4_Lambdas -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class N04LambdasKtTest { - @Test fun contains() { + @Test + fun contains() { assertTrue(task4(listOf(1, 2, 3))) } - @Test fun notContains() { + @Test + fun notContains() { assertFalse(task4(listOf(1, 3, 5))) } } \ No newline at end of file diff --git a/test/i_introduction/_5_String_Templates/N05StringTemplatesKtTest.kt b/test/i_introduction/_5_String_Templates/N05StringTemplatesKtTest.kt index 98466b32e..80f4099a5 100644 --- a/test/i_introduction/_5_String_Templates/N05StringTemplatesKtTest.kt +++ b/test/i_introduction/_5_String_Templates/N05StringTemplatesKtTest.kt @@ -1,20 +1,22 @@ package i_introduction._5_String_Templates -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test -import java.util.regex.Pattern +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class N05StringTemplatesKtTest { - @Test fun match() { + @Test + fun match() { assertTrue("11 MAR 1952".matches(task5().toRegex())) } - @Test fun match1() { + @Test + fun match1() { assertTrue("24 AUG 1957".matches(task5().toRegex())) } - @Test fun doNotMatch() { + @Test + fun doNotMatch() { assertFalse("24 RRR 1957".matches(task5().toRegex())) } } diff --git a/test/i_introduction/_6_Data_Classes/N06DataClassesKtTest.kt b/test/i_introduction/_6_Data_Classes/N06DataClassesKtTest.kt index 17e1e11a6..942bdfdfb 100644 --- a/test/i_introduction/_6_Data_Classes/N06DataClassesKtTest.kt +++ b/test/i_introduction/_6_Data_Classes/N06DataClassesKtTest.kt @@ -1,11 +1,12 @@ package i_introduction._6_Data_Classes -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N06DataClassesKtTest { - @Test fun testListOfPeople() { + @Test + fun testListOfPeople() { assertEquals("[Person(name=Alice, age=29), Person(name=Bob, age=31)]", task6().toString()) } } \ No newline at end of file diff --git a/test/i_introduction/_7_Nullable_Types/N07NullableTypesKtTest.kt b/test/i_introduction/_7_Nullable_Types/N07NullableTypesKtTest.kt index 5f10d1b47..c0b3967d3 100644 --- a/test/i_introduction/_7_Nullable_Types/N07NullableTypesKtTest.kt +++ b/test/i_introduction/_7_Nullable_Types/N07NullableTypesKtTest.kt @@ -1,49 +1,52 @@ package i_introduction._7_Nullable_Types -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N07NullableTypesKtTest { - fun testSendMessageToClient( - client: Client?, - message: String?, - email: String? = null, - shouldBeInvoked: Boolean = false + private fun testSendMessageToClient( + client: Client?, + message: String?, + email: String? = null, + shouldBeInvoked: Boolean = false ) { var invoked = false sendMessageToClient(client, message, object : Mailer { override fun sendMessage(actualEmail: String, actualMessage: String) { invoked = true - assertEquals("The message is not as expected:", - message, actualMessage) - assertEquals("The email is not as expected:", - email, actualEmail) + assertEquals(message, actualMessage, "The message is not as expected:") + assertEquals(email, actualEmail, "The email is not as expected:") } }) - assertEquals("The function 'sendMessage' should${if (shouldBeInvoked) "" else "n't"} be invoked", - shouldBeInvoked, invoked) + assertEquals(shouldBeInvoked, invoked, + "The function 'sendMessage' should${if (shouldBeInvoked) "" else "n't"} be invoked") } - @Test fun everythingIsOk() { + @Test + fun everythingIsOk() { testSendMessageToClient(Client(PersonalInfo("bob@gmail.com")), - "Hi Bob! We have an awesome proposition for you...", - "bob@gmail.com", - true) + "Hi Bob! We have an awesome proposition for you...", + "bob@gmail.com", + true) } - @Test fun noMessage() { + @Test + fun noMessage() { testSendMessageToClient(Client(PersonalInfo("bob@gmail.com")), null) } - @Test fun noEmail() { + @Test + fun noEmail() { testSendMessageToClient(Client(PersonalInfo(null)), "Hi Bob! We have an awesome proposition for you...") } - @Test fun noPersonalInfo() { + @Test + fun noPersonalInfo() { testSendMessageToClient(Client(null), "Hi Bob! We have an awesome proposition for you...") } - @Test fun noClient() { + @Test + fun noClient() { testSendMessageToClient(null, "Hi Bob! We have an awesome proposition for you...") } } \ No newline at end of file diff --git a/test/i_introduction/_8_Smart_Casts/N08SmartCastsKtTest.kt b/test/i_introduction/_8_Smart_Casts/N08SmartCastsKtTest.kt index 59bb54fdc..53ca9f368 100644 --- a/test/i_introduction/_8_Smart_Casts/N08SmartCastsKtTest.kt +++ b/test/i_introduction/_8_Smart_Casts/N08SmartCastsKtTest.kt @@ -1,18 +1,21 @@ package i_introduction._8_Smart_Casts -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N08SmartCastsKtTest { - @Test fun testNum() { - assertEquals("'eval' on Num should work:", 2, eval(Num(2))) + @Test + fun testNum() { + assertEquals(2, eval(Num(2)), "'eval' on Num should work:") } - @Test fun testSum() { - assertEquals("'eval' on Sum should work:", 3, eval(Sum(Num(2), Num(1)))) + @Test + fun testSum() { + assertEquals(3, eval(Sum(Num(2), Num(1))), "'eval' on Sum should work:") } - @Test fun testRecursion() { - assertEquals("'eval' should work recursively:", 6, eval(Sum(Sum(Num(1), Num(2)), Num(3)))) + @Test + fun testRecursion() { + assertEquals(6, eval(Sum(Sum(Num(1), Num(2)), Num(3))), "'eval' should work recursively:") } } \ No newline at end of file diff --git a/test/i_introduction/_9_Extension_Functions/N09ExtensionFunctionsKtTest.kt b/test/i_introduction/_9_Extension_Functions/N09ExtensionFunctionsKtTest.kt index 2f9a93ca5..cd27b1b44 100644 --- a/test/i_introduction/_9_Extension_Functions/N09ExtensionFunctionsKtTest.kt +++ b/test/i_introduction/_9_Extension_Functions/N09ExtensionFunctionsKtTest.kt @@ -1,14 +1,16 @@ package i_introduction._9_Extension_Functions -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N09ExtensionFunctionsKtTest { - @Test fun testIntExtension() { - assertEquals("Rational number creation error: ", RationalNumber(4, 1), 4.r()) + @Test + fun testIntExtension() { + assertEquals(RationalNumber(4, 1), 4.r(), "Rational number creation error: ") } - @Test fun testPairExtension() { - assertEquals("Rational number creation error: ", RationalNumber(2, 3), Pair(2, 3).r()) + @Test + fun testPairExtension() { + assertEquals(RationalNumber(2, 3), Pair(2, 3).r(), "Rational number creation error: ") } } \ No newline at end of file diff --git a/test/ii_collections/N13IntroductionKtTest.kt b/test/ii_collections/N13IntroductionKtTest.kt index f2afddde8..4aa961c15 100644 --- a/test/ii_collections/N13IntroductionKtTest.kt +++ b/test/ii_collections/N13IntroductionKtTest.kt @@ -2,11 +2,12 @@ package ii_collections import ii_collections.data.customers import ii_collections.data.shop -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N13IntroductionKtTest { - @Test fun testSetOfCustomers() { + @Test + fun testSetOfCustomers() { assertEquals(customers.values.toSet(), shop.getSetOfCustomers()) } } diff --git a/test/ii_collections/N14FilterMapKtTest.kt b/test/ii_collections/N14FilterMapKtTest.kt index 7d1ef617b..85aa5f7b1 100644 --- a/test/ii_collections/N14FilterMapKtTest.kt +++ b/test/ii_collections/N14FilterMapKtTest.kt @@ -1,18 +1,20 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N14FilterMapKtTest { - @Test fun testCitiesCustomersAreFrom() { + @Test + fun testCitiesCustomersAreFrom() { assertEquals(setOf(Canberra, Vancouver, Budapest, Ankara, Tokyo), shop.getCitiesCustomersAreFrom()) } /** * Returns the list of the customers who live in the city 'city' */ - @Test fun testCustomersFromCity() { + @Test + fun testCustomersFromCity() { assertEquals(listOf(customers[lucas], customers[cooper]), shop.getCustomersFrom(Canberra)) } } diff --git a/test/ii_collections/N15AllAnyAndOtherPredicatesKtTest.kt b/test/ii_collections/N15AllAnyAndOtherPredicatesKtTest.kt index 66762b54c..cf11b0458 100644 --- a/test/ii_collections/N15AllAnyAndOtherPredicatesKtTest.kt +++ b/test/ii_collections/N15AllAnyAndOtherPredicatesKtTest.kt @@ -1,28 +1,33 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.* -import org.junit.Test +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test class N15AllAnyAndOtherPredicatesKtTest { - @Test fun testCustomerIsFromCity() { + @Test + fun testCustomerIsFromCity() { assertTrue(customers[lucas]!!.isFrom(Canberra)) assertFalse(customers[lucas]!!.isFrom(Budapest)) } - @Test fun testAllCustomersAreFromCity() { + @Test + fun testAllCustomersAreFromCity() { assertFalse(shop.checkAllCustomersAreFrom(Canberra)) } - @Test fun testAnyCustomerIsFromCity() { + @Test + fun testAnyCustomerIsFromCity() { assertTrue(shop.hasCustomerFrom(Canberra)) } - @Test fun testCountCustomersFromCity() { + @Test + fun testCountCustomersFromCity() { assertEquals(2, shop.countCustomersFrom(Canberra)) } - @Test fun testFirstCustomerFromCity() { + @Test + fun testFirstCustomerFromCity() { assertEquals(customers[lucas], shop.findFirstCustomerFrom(Canberra)) assertEquals(null, shop.findFirstCustomerFrom(City("Chicago"))) } diff --git a/test/ii_collections/N16FlatMapKtTest.kt b/test/ii_collections/N16FlatMapKtTest.kt index 6e30e2e9c..8a4b5b627 100644 --- a/test/ii_collections/N16FlatMapKtTest.kt +++ b/test/ii_collections/N16FlatMapKtTest.kt @@ -1,15 +1,17 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N16FlatMapKtTest { - @Test fun testGetOrderedProductsSet() { + @Test + fun testGetOrderedProductsSet() { assertEquals(setOf(idea), customers[reka]!!.orderedProducts) } - @Test fun testGetAllOrderedProducts() { + @Test + fun testGetAllOrderedProducts() { assertEquals(orderedProducts, shop.allOrderedProducts) } } diff --git a/test/ii_collections/N17MaxMinKtTest.kt b/test/ii_collections/N17MaxMinKtTest.kt index f4b92f9a7..25ddecfdf 100644 --- a/test/ii_collections/N17MaxMinKtTest.kt +++ b/test/ii_collections/N17MaxMinKtTest.kt @@ -1,15 +1,17 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N17MaxMinKtTest { - @Test fun testCustomerWithMaximumNumberOfOrders() { + @Test + fun testCustomerWithMaximumNumberOfOrders() { assertEquals(customers[reka], shop.getCustomerWithMaximumNumberOfOrders()) } - @Test fun testTheMostExpensiveOrderedProduct() { + @Test + fun testTheMostExpensiveOrderedProduct() { assertEquals(rubyMine, customers[nathan]!!.getMostExpensiveOrderedProduct()) } } diff --git a/test/ii_collections/N18SortKtTest.kt b/test/ii_collections/N18SortKtTest.kt index 1cb9ecb25..8bdb04f14 100644 --- a/test/ii_collections/N18SortKtTest.kt +++ b/test/ii_collections/N18SortKtTest.kt @@ -2,11 +2,12 @@ package ii_collections import ii_collections.data.shop import ii_collections.data.sortedCustomers -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N18SortKtTest { - @Test fun testGetCustomersSortedByNumberOfOrders() { + @Test + fun testGetCustomersSortedByNumberOfOrders() { assertEquals(sortedCustomers, shop.getCustomersSortedByNumberOfOrders()) } } diff --git a/test/ii_collections/N19SumKtTest.kt b/test/ii_collections/N19SumKtTest.kt index 50d25ed0d..5f7882f5b 100644 --- a/test/ii_collections/N19SumKtTest.kt +++ b/test/ii_collections/N19SumKtTest.kt @@ -3,15 +3,17 @@ package ii_collections import ii_collections.data.customers import ii_collections.data.lucas import ii_collections.data.nathan -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N19SumKtTest { - @Test fun testGetTotalOrderPrice() { + @Test + fun testGetTotalOrderPrice() { assertEquals(148.0, customers[nathan]!!.getTotalOrderPrice(), 0.001) } - @Test fun testTotalPriceForRepeatedProducts() { + @Test + fun testTotalPriceForRepeatedProducts() { assertEquals(586.0, customers[lucas]!!.getTotalOrderPrice(), 0.001) } } diff --git a/test/ii_collections/N20GroupByKtTest.kt b/test/ii_collections/N20GroupByKtTest.kt index dca8e6a53..a8b2e543c 100644 --- a/test/ii_collections/N20GroupByKtTest.kt +++ b/test/ii_collections/N20GroupByKtTest.kt @@ -2,11 +2,12 @@ package ii_collections import ii_collections.data.groupedByCities import ii_collections.data.shop -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N20GroupByKtTest { - @Test fun testGroupCustomersByCity() { + @Test + fun testGroupCustomersByCity() { assertEquals(groupedByCities, shop.groupCustomersByCity()) } } diff --git a/test/ii_collections/N21PartitionKtTest.kt b/test/ii_collections/N21PartitionKtTest.kt index 256050fc2..0a9347549 100644 --- a/test/ii_collections/N21PartitionKtTest.kt +++ b/test/ii_collections/N21PartitionKtTest.kt @@ -3,11 +3,12 @@ package ii_collections import ii_collections.data.customers import ii_collections.data.reka import ii_collections.data.shop -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N21PartitionKtTest { - @Test fun testGetCustomersWhoHaveMoreUndeliveredOrdersThanDelivered() { + @Test + fun testGetCustomersWhoHaveMoreUndeliveredOrdersThanDelivered() { assertEquals(setOf(customers[reka]), shop.getCustomersWithMoreUndeliveredOrdersThanDelivered()) } } diff --git a/test/ii_collections/N22FoldKtTest.kt b/test/ii_collections/N22FoldKtTest.kt index 5b182a80e..1b0494761 100644 --- a/test/ii_collections/N22FoldKtTest.kt +++ b/test/ii_collections/N22FoldKtTest.kt @@ -1,21 +1,22 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N22FoldKtTest { - @Test fun testGetProductsOrderedByAllCustomers() { + @Test + fun testGetProductsOrderedByAllCustomers() { val testShop = shop("test shop for 'fold'", - customer(lucas, Canberra, - order(idea), - order(webStorm) - ), - customer(reka, Budapest, - order(idea), - order(youTrack) - ) + customer(lucas, Canberra, + order(idea), + order(webStorm) + ), + customer(reka, Budapest, + order(idea), + order(youTrack) + ) ) assertEquals(setOf(idea), testShop.getSetOfProductsOrderedByEachCustomer()) } diff --git a/test/ii_collections/N23CompoundTasksKtTest.kt b/test/ii_collections/N23CompoundTasksKtTest.kt index b2f341161..f0c0df107 100644 --- a/test/ii_collections/N23CompoundTasksKtTest.kt +++ b/test/ii_collections/N23CompoundTasksKtTest.kt @@ -1,35 +1,38 @@ package ii_collections import ii_collections.data.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N23CompoundTasksKtTest { - @Test fun testGetCustomersWhoOrderedProduct() { + @Test + fun testGetCustomersWhoOrderedProduct() { assertEquals(setOf(customers[reka], customers[asuka]), shop.getCustomersWhoOrderedProduct(idea)) } - @Test fun testMostExpensiveDeliveredProduct() { + @Test + fun testMostExpensiveDeliveredProduct() { val testShop = shop("test shop for 'most expensive delivered product'", - customer(lucas, Canberra, - order(idea, isDelivered = false), - order(reSharper) - ) + customer(lucas, Canberra, + order(idea, isDelivered = false), + order(reSharper) + ) ) assertEquals(reSharper, testShop.customers[0].getMostExpensiveDeliveredProduct()) } - @Test fun testNumberOfTimesEachProductWasOrdered() { + @Test + fun testNumberOfTimesEachProductWasOrdered() { assertEquals(4, shop.getNumberOfTimesProductWasOrdered(idea)) } - @Test fun testNumberOfTimesEachProductWasOrderedForRepeatedProduct() { - assertEquals("A customer may order a product for several times", - 3, shop.getNumberOfTimesProductWasOrdered(reSharper)) + @Test + fun testNumberOfTimesEachProductWasOrderedForRepeatedProduct() { + assertEquals(3, shop.getNumberOfTimesProductWasOrdered(reSharper), "A customer may order a product for several times") } - @Test fun testNumberOfTimesEachProductWasOrderedForRepeatedInOrderProduct() { - assertEquals("An order may contain a particular product more than once", - 3, shop.getNumberOfTimesProductWasOrdered(phpStorm)) + @Test + fun testNumberOfTimesEachProductWasOrderedForRepeatedInOrderProduct() { + assertEquals(3, shop.getNumberOfTimesProductWasOrdered(phpStorm), "An order may contain a particular product more than once") } } diff --git a/test/ii_collections/N24ExtensionsOnCollectionsKtTest.kt b/test/ii_collections/N24ExtensionsOnCollectionsKtTest.kt index 1b363a9cc..e3fd8862f 100644 --- a/test/ii_collections/N24ExtensionsOnCollectionsKtTest.kt +++ b/test/ii_collections/N24ExtensionsOnCollectionsKtTest.kt @@ -1,31 +1,35 @@ package ii_collections -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N24ExtensionsOnCollectionsKtTest { - @Test fun testCollectionOfOneElement() { + @Test + fun testCollectionOfOneElement() { doTest(listOf("a"), listOf("a")) } - @Test fun testEmptyCollection() { + @Test + fun testEmptyCollection() { doTest(null, listOf()) } - @Test fun testSimpleCollection() { + @Test + fun testSimpleCollection() { doTest(listOf("a", "c"), listOf("a", "bb", "c")) } - @Test fun testCollectionWithEmptyStrings() { + @Test + fun testCollectionWithEmptyStrings() { doTest(listOf("", "", "", ""), listOf("", "", "", "", "a", "bb", "ccc", "dddd")) } - @Test fun testCollectionWithTwoGroupsOfMaximalSize() { + @Test + fun testCollectionWithTwoGroupsOfMaximalSize() { doTest(listOf("a", "c"), listOf("a", "bb", "c", "dd")) } private fun doTest(expected: Collection?, argument: Collection) { - assertEquals("The function 'doSomethingStrangeWithCollection' should do at least something with a collection:", - expected, doSomethingStrangeWithCollection(argument)) + assertEquals(expected, doSomethingStrangeWithCollection(argument), "The function 'doSomethingStrangeWithCollection' should do at least something with a collection:") } } \ No newline at end of file diff --git a/test/ii_collections/TestShop.kt b/test/ii_collections/TestShop.kt index e7abbe849..c706716b1 100644 --- a/test/ii_collections/TestShop.kt +++ b/test/ii_collections/TestShop.kt @@ -37,34 +37,33 @@ fun order(vararg products: Product, isDelivered: Boolean = true) = Order(product fun shop(name: String, vararg customers: Customer) = Shop(name, customers.toList()) val shop = shop("jb test shop", - customer(lucas, Canberra, - order(reSharper), - order(reSharper, dotMemory, dotTrace) - ), - customer(cooper, Canberra), - customer(nathan, Vancouver, - order(rubyMine, webStorm) - ), - customer(reka, Budapest, - order(idea, isDelivered = false), - order(idea, isDelivered = false), - order(idea) - ), - customer(bajram, Ankara, - order(reSharper) - ), - customer(asuka, Tokyo, - order(idea) - ), - customer(riku, Tokyo, - order(phpStorm, phpStorm), - order(phpStorm) - ) + customer(lucas, Canberra, + order(reSharper), + order(reSharper, dotMemory, dotTrace) + ), + customer(cooper, Canberra), + customer(nathan, Vancouver, + order(rubyMine, webStorm) + ), + customer(reka, Budapest, + order(idea, isDelivered = false), + order(idea, isDelivered = false), + order(idea) + ), + customer(bajram, Ankara, + order(reSharper) + ), + customer(asuka, Tokyo, + order(idea) + ), + customer(riku, Tokyo, + order(phpStorm, phpStorm), + order(phpStorm) + ) ) -val customers: Map = shop.customers.fold(hashMapOf(), { - map, customer -> +val customers: Map = shop.customers.fold(hashMapOf(), { map, customer -> map[customer.name] = customer map }) @@ -74,9 +73,9 @@ val orderedProducts = setOf(idea, reSharper, dotTrace, dotMemory, rubyMine, webS val sortedCustomers = listOf(cooper, nathan, bajram, asuka, lucas, riku, reka).map { customers[it] } val groupedByCities = mapOf( - Canberra to listOf(lucas, cooper), - Vancouver to listOf(nathan), - Budapest to listOf(reka), - Ankara to listOf(bajram), - Tokyo to listOf(asuka, riku) + Canberra to listOf(lucas, cooper), + Vancouver to listOf(nathan), + Budapest to listOf(reka), + Ankara to listOf(bajram), + Tokyo to listOf(asuka, riku) ).mapValues { it.value.map { name -> customers[name] } } diff --git a/test/iii_conventions/N25ComparisonKtTest.kt b/test/iii_conventions/N25ComparisonKtTest.kt index 4031bc681..61a4870bd 100644 --- a/test/iii_conventions/N25ComparisonKtTest.kt +++ b/test/iii_conventions/N25ComparisonKtTest.kt @@ -1,25 +1,28 @@ package iii_conventions import iii_conventions.test.s -import org.junit.Assert.assertTrue -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class N25ComparisonKtTest { /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ - @Test fun testDateComparison() { + @Test + fun testDateComparison() { assertTrue(task25(MyDate(2014, 1, 1), MyDate(2014, 1, 2))) } - @Test fun testBefore() { + @Test + fun testBefore() { val first = MyDate(2014, 5, 10) val second = MyDate(2014, 7, 11) - assertTrue("The date ${first.s} should be before ${second.s}", first < second) + assertTrue(first < second, "The date ${first.s} should be before ${second.s}") } - @Test fun testAfter() { + @Test + fun testAfter() { val first = MyDate(2014, 10, 20) val second = MyDate(2014, 7, 11) - assertTrue("The date ${first.s} should be after ${second.s}", first > second) + assertTrue(first > second, "The date ${first.s} should be after ${second.s}") } /* If you declare 'compareTo' as an extension function, remove this one to make the code compile */ diff --git a/test/iii_conventions/N26InRangeKtTest.kt b/test/iii_conventions/N26InRangeKtTest.kt index e531b8a4e..71bda3ce0 100644 --- a/test/iii_conventions/N26InRangeKtTest.kt +++ b/test/iii_conventions/N26InRangeKtTest.kt @@ -1,49 +1,58 @@ package iii_conventions import iii_conventions.test.s -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N26InRangeKtTest { fun doTest(date: MyDate, first: MyDate, last: MyDate, shouldBeInRange: Boolean) { val message = "The date ${date.s} should${if (shouldBeInRange) "" else "n't"} be in range: ${first.s}..${last.s}" - assertEquals(message, shouldBeInRange, checkInRange(date, first, last)) + assertEquals(shouldBeInRange, checkInRange(date, first, last), message) } /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ - @Test fun testInRange() { + @Test + fun testInRange() { doTest(MyDate(2014, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = true) } - @Test fun testBefore() { + @Test + fun testBefore() { doTest(MyDate(2013, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false) } - @Test fun testAfter() { + @Test + fun testAfter() { doTest(MyDate(2015, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false) } - @Test fun testEqualsToBegin() { + @Test + fun testEqualsToBegin() { doTest(MyDate(2014, 3, 22), MyDate(2014, 3, 22), MyDate(2015, 1, 1), shouldBeInRange = true) } - @Test fun testEqualsToEnd() { + @Test + fun testEqualsToEnd() { doTest(MyDate(2015, 1, 1), MyDate(2014, 3, 22), MyDate(2015, 1, 1), shouldBeInRange = true) } - @Test fun testInOneDayRange() { + @Test + fun testInOneDayRange() { doTest(MyDate(2015, 1, 1), MyDate(2015, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = true) } - @Test fun testInvalidRange() { + @Test + fun testInvalidRange() { doTest(MyDate(2014, 2, 1), MyDate(2015, 1, 1), MyDate(2014, 1, 1), shouldBeInRange = false) } - @Test fun testInvalidRangeEqualsToBegin() { + @Test + fun testInvalidRangeEqualsToBegin() { doTest(MyDate(2015, 1, 1), MyDate(2015, 1, 1), MyDate(2014, 1, 1), shouldBeInRange = false) } - @Test fun testInvalidRangeEqualsToEnd() { + @Test + fun testInvalidRangeEqualsToEnd() { doTest(MyDate(2014, 1, 1), MyDate(2015, 1, 1), MyDate(2014, 1, 1), shouldBeInRange = false) } } \ No newline at end of file diff --git a/test/iii_conventions/N27RangeToKtTest.kt b/test/iii_conventions/N27RangeToKtTest.kt index 761b4937f..1ec48e08a 100644 --- a/test/iii_conventions/N27RangeToKtTest.kt +++ b/test/iii_conventions/N27RangeToKtTest.kt @@ -1,25 +1,28 @@ package iii_conventions import iii_conventions.test.s -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N27RangeToKtTest { fun doTest(date: MyDate, first: MyDate, last: MyDate, shouldBeInRange: Boolean) { val message = "The date ${date.s} should${if (shouldBeInRange) "" else "n't"} be in range: ${first.s}..${last.s}" - assertEquals(message, shouldBeInRange, checkInRange2(date, first, last)) + assertEquals(shouldBeInRange, checkInRange2(date, first, last), message) } /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ - @Test fun testInRange() { + @Test + fun testInRange() { doTest(MyDate(2014, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = true) } - @Test fun testBefore() { + @Test + fun testBefore() { doTest(MyDate(2013, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false) } - @Test fun testAfter() { + @Test + fun testAfter() { doTest(MyDate(2015, 3, 22), MyDate(2014, 1, 1), MyDate(2015, 1, 1), shouldBeInRange = false) } } \ No newline at end of file diff --git a/test/iii_conventions/N28ForLoopKtTest.kt b/test/iii_conventions/N28ForLoopKtTest.kt index 8bde75d74..00620955e 100644 --- a/test/iii_conventions/N28ForLoopKtTest.kt +++ b/test/iii_conventions/N28ForLoopKtTest.kt @@ -1,49 +1,50 @@ package iii_conventions -import org.junit.Assert.assertEquals -import org.junit.Assert.assertFalse -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Test import java.util.* class N28ForLoopKtTest { /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ - @Test fun testIterateOverDateRange() { + @Test + fun testIterateOverDateRange() { val actualDateRange = ArrayList() - iterateOverDateRange(MyDate(2014, 5, 1), MyDate(2014, 5, 5), { - date: MyDate -> actualDateRange.add(date) - }) + iterateOverDateRange(MyDate(2014, 5, 1), MyDate(2014, 5, 5)) { date: MyDate -> + actualDateRange.add(date) + } val expectedDateRange = arrayListOf( - MyDate(2014, 5, 1), MyDate(2014, 5, 2), MyDate(2014, 5, 3), MyDate(2014, 5, 4), MyDate(2014, 5, 5)) - assertEquals("Incorrect iteration over five nice spring dates", - expectedDateRange, actualDateRange) + MyDate(2014, 5, 1), MyDate(2014, 5, 2), MyDate(2014, 5, 3), MyDate(2014, 5, 4), MyDate(2014, 5, 5)) + assertEquals(expectedDateRange, actualDateRange, "Incorrect iteration over five nice spring dates") } - @Test fun testIterateOverEmptyRange() { + @Test + fun testIterateOverEmptyRange() { var invoked = false iterateOverDateRange(MyDate(2014, 1, 1), MyDate(2013, 1, 1), { invoked = true }) - assertFalse("Handler was invoked on an empty range", invoked) + assertFalse(invoked, "Handler was invoked on an empty range") } - @Test fun testIterateOverLeapYearEndOfFebruary() { + @Test + fun testIterateOverLeapYearEndOfFebruary() { val actualDateRange = ArrayList() - iterateOverDateRange(MyDate(2016, 1, 26), MyDate(2016, 2, 1), { - date: MyDate -> actualDateRange.add(date) - }) + iterateOverDateRange(MyDate(2016, 1, 26), MyDate(2016, 2, 1)) { date: MyDate -> + actualDateRange.add(date) + } val expectedDateRange = arrayListOf( - MyDate(2016, 1, 26), MyDate(2016, 1, 27), MyDate(2016, 1, 28), MyDate(2016, 1, 29), MyDate(2016, 2, 1)) - assertEquals("Incorrect iteration over nice end of February of Leap-Year", - expectedDateRange, actualDateRange) + MyDate(2016, 1, 26), MyDate(2016, 1, 27), MyDate(2016, 1, 28), MyDate(2016, 1, 29), MyDate(2016, 2, 1)) + assertEquals(expectedDateRange, actualDateRange, "Incorrect iteration over nice end of February of Leap-Year") } - @Test fun testIterateOverTheNewYear() { + @Test + fun testIterateOverTheNewYear() { val actualDateRange = ArrayList() - iterateOverDateRange(MyDate(2016, 11, 31), MyDate(2017, 0, 1), { - date: MyDate -> actualDateRange.add(date) - }) + iterateOverDateRange(MyDate(2016, 11, 31), MyDate(2017, 0, 1)) { date: MyDate -> + actualDateRange.add(date) + } val expectedDateRange = arrayListOf( - MyDate(2016, 11, 31), MyDate(2017, 0, 1)) - assertEquals("Incorrect iteration over the end of the year", - expectedDateRange, actualDateRange) + MyDate(2016, 11, 31), MyDate(2017, 0, 1)) + assertEquals(expectedDateRange, actualDateRange, "Incorrect iteration over the end of the year") } } \ No newline at end of file diff --git a/test/iii_conventions/N29OperatorsOverloadingKtTest.kt b/test/iii_conventions/N29OperatorsOverloadingKtTest.kt index d9629b7ed..90d52e72d 100644 --- a/test/iii_conventions/N29OperatorsOverloadingKtTest.kt +++ b/test/iii_conventions/N29OperatorsOverloadingKtTest.kt @@ -1,26 +1,30 @@ package iii_conventions import iii_conventions.TimeInterval.* -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N29OperatorsOverloadingKtTest { /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ - @Test fun testAddTimeIntervals() { + @Test + fun testAddTimeIntervals() { assertEquals(MyDate(2014, 5, 22), MyDate(1983, 5, 22).addTimeIntervals(YEAR, 31)) assertEquals(MyDate(1983, 5, 29), MyDate(1983, 5, 22).addTimeIntervals(DAY, 7)) assertEquals(MyDate(1983, 5, 29), MyDate(1983, 5, 22).addTimeIntervals(WEEK, 1)) } - @Test fun testAddOneTimeInterval() { + @Test + fun testAddOneTimeInterval() { assertEquals(MyDate(2015, 5, 8), task29_1(MyDate(2014, 5, 1))) } - @Test fun testOneMonth() { + @Test + fun testOneMonth() { assertEquals(MyDate(2016, 0, 27), task29_2(MyDate(2014, 0, 1))) } - @Test fun testMonthChange() { + @Test + fun testMonthChange() { assertEquals(MyDate(2016, 1, 20), task29_2(MyDate(2014, 0, 25))) } } \ No newline at end of file diff --git a/test/iii_conventions/N30DestructuringDeclarationsKtTest.kt b/test/iii_conventions/N30DestructuringDeclarationsKtTest.kt index 51278ee06..71c9b8ff9 100644 --- a/test/iii_conventions/N30DestructuringDeclarationsKtTest.kt +++ b/test/iii_conventions/N30DestructuringDeclarationsKtTest.kt @@ -1,11 +1,12 @@ package iii_conventions.multiAssignemnt -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class N30DestructuringDeclarationsKtTest { - @Test fun testIsLeapDay() { + @Test + fun testIsLeapDay() { assertTrue(isLeapDay(MyDate(2016, 1, 29))) assertFalse(isLeapDay(MyDate(2015, 1, 29))) } diff --git a/test/iii_conventions/N31InvokeKtTest.kt b/test/iii_conventions/N31InvokeKtTest.kt index e732455e7..c4f995ad4 100644 --- a/test/iii_conventions/N31InvokeKtTest.kt +++ b/test/iii_conventions/N31InvokeKtTest.kt @@ -1,18 +1,20 @@ package iii_conventions -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N31InvokeKtTest { - @Test fun testTask17() { + @Test + fun testTask17() { assertEquals(4, task31(Invokable())) } - @Test fun testNumberOfInvocations() { + @Test + fun testNumberOfInvocations() { val message = "The number of invocations is incorrect" fun testInvokable(numberOfInvocations: Int, invokeSeveralTimes: (Invokable) -> Invokable) { val invokable = Invokable() - assertEquals(message, numberOfInvocations, invokeSeveralTimes(invokable).getNumberOfInvocations()) + assertEquals(numberOfInvocations, invokeSeveralTimes(invokable).getNumberOfInvocations(), message) } testInvokable(1) { it() } diff --git a/test/iv_properties/N32PropertiesKtTest.kt b/test/iv_properties/N32PropertiesKtTest.kt index 6bfbc2f4a..0a19ba676 100644 --- a/test/iv_properties/N32PropertiesKtTest.kt +++ b/test/iv_properties/N32PropertiesKtTest.kt @@ -1,18 +1,18 @@ package iv_properties -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N32PropertiesKtTest { - @Test fun testPropertyWithCounter() { + @Test + fun testPropertyWithCounter() { val q = PropertyExample() q.propertyWithCounter = 14 q.propertyWithCounter = 21 q.propertyWithCounter = 32 - assertEquals("The property q.counter should contain the number of assignments to q.propertyWithCounter:", - 3, q.counter) + assertEquals(3, q.counter, "The property q.counter should contain the number of assignments to q.propertyWithCounter:") // Here we have to use !! due to false smart cast impossible - assertEquals("The property q.propertyWithCounter should be set:", 32, q.propertyWithCounter!!) + assertEquals(32, q.propertyWithCounter!!, "The property q.propertyWithCounter should be set:") } } \ No newline at end of file diff --git a/test/iv_properties/N33LazyPropertyKtTest.kt b/test/iv_properties/N33LazyPropertyKtTest.kt index 32bf4e6bf..c54eb2096 100644 --- a/test/iv_properties/N33LazyPropertyKtTest.kt +++ b/test/iv_properties/N33LazyPropertyKtTest.kt @@ -1,24 +1,26 @@ package iv_properties -import org.junit.Assert.* -import org.junit.Test +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test class N33LazyPropertyKtTest { - @Test fun testLazy() { + @Test + fun testLazy() { var initialized = false - val lazyProperty = LazyProperty({ initialized = true; 42 }) - assertFalse("Property shouldn't be initialized before access", initialized) + val lazyProperty = LazyProperty { initialized = true; 42 } + assertFalse(initialized, "Property shouldn't be initialized before access") val result: Int = lazyProperty.lazy - assertTrue("Property should be initialized after access", initialized) + assertTrue(initialized, "Property should be initialized after access") assertEquals(42, result) } - @Test fun initializedOnce() { + @Test + fun initializedOnce() { var initialized = 0 - val lazyProperty = LazyProperty( { initialized++; 42 }) + val lazyProperty = LazyProperty({ initialized++; 42 }) lazyProperty.lazy lazyProperty.lazy - assertEquals("Lazy property should be initialized once", 1, initialized) + assertEquals(1, initialized, "Lazy property should be initialized once") } } diff --git a/test/iv_properties/N34DelegatesExamplesKtTest.kt b/test/iv_properties/N34DelegatesExamplesKtTest.kt index 8f2ecdf68..812a3b23b 100644 --- a/test/iv_properties/N34DelegatesExamplesKtTest.kt +++ b/test/iv_properties/N34DelegatesExamplesKtTest.kt @@ -1,24 +1,26 @@ package iv_properties -import org.junit.Assert.* -import org.junit.Test +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test class N34DelegatesExamplesKtTest { - @Test fun testLazy() { + @Test + fun testLazy() { var initialized = false - val lazyProperty = LazyPropertyUsingDelegates({ initialized = true; 42 }) - assertFalse("Property shouldn't be initialized before access", initialized) + val lazyProperty = LazyPropertyUsingDelegates { initialized = true; 42 } + assertFalse(initialized, "Property shouldn't be initialized before access") val result: Int = lazyProperty.lazyValue - assertTrue("Property should be initialized after access", initialized) + assertTrue(initialized, "Property should be initialized after access") assertEquals(42, result) } - @Test fun initializedOnce() { + @Test + fun initializedOnce() { var initialized = 0 - val lazyProperty = LazyPropertyUsingDelegates( { initialized++; 42 }) + val lazyProperty = LazyPropertyUsingDelegates { initialized++; 42 } lazyProperty.lazyValue lazyProperty.lazyValue - assertEquals("Lazy property should be initialized once", 1, initialized) + assertEquals(1, initialized, "Lazy property should be initialized once") } } \ No newline at end of file diff --git a/test/iv_properties/N35HowDelegatesWorkKtTest.kt b/test/iv_properties/N35HowDelegatesWorkKtTest.kt index 24321527e..492b6e6b8 100644 --- a/test/iv_properties/N35HowDelegatesWorkKtTest.kt +++ b/test/iv_properties/N35HowDelegatesWorkKtTest.kt @@ -1,11 +1,12 @@ package iv_properties import iii_conventions.MyDate -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N35HowDelegatesWorkKtTest { - @Test fun testDate() { + @Test + fun testDate() { val d = D() /* Month numbering starts with 0 (0-Jan, 1-Feb, ... 11-Dec) */ d.date = MyDate(2014, 1, 13) diff --git a/test/util/AdditionalTest.kt b/test/util/AdditionalTest.kt index 53a729d40..204005aa0 100644 --- a/test/util/AdditionalTest.kt +++ b/test/util/AdditionalTest.kt @@ -6,28 +6,29 @@ import i_introduction._4_Lambdas.N04LambdasKtTest import i_introduction._7_Nullable_Types.N07NullableTypesKtTest import i_introduction._8_Smart_Casts.N08SmartCastsKtTest import ii_collections.N24ExtensionsOnCollectionsKtTest -import org.junit.Assert.assertTrue -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class AdditionalTest { - @Test fun test() { + @Test + fun test() { invokeTests( - { N01JavaToKotlinConverterKtTest().collection() }, - { N03DefaultArgumentsKtTest().testDefaultAndNamedParams() }, - { N04LambdasKtTest().contains() }, - { N07NullableTypesKtTest().everythingIsOk() }, - { N08SmartCastsKtTest().testNum() }, - { N24ExtensionsOnCollectionsKtTest().testCollectionOfOneElement() } + { N01JavaToKotlinConverterKtTest().collection() }, + { N03DefaultArgumentsKtTest().testDefaultAndNamedParams() }, + { N04LambdasKtTest().contains() }, + { N07NullableTypesKtTest().everythingIsOk() }, + { N08SmartCastsKtTest().testNum() }, + { N24ExtensionsOnCollectionsKtTest().testCollectionOfOneElement() } ) - assertTrue("${JavaCode.set}", JavaCode.set.isEmpty()) + assertTrue(JavaCode.set.isEmpty(), "${JavaCode.set}") } private fun invokeTests(vararg tests: () -> Unit) { for (test in tests) { try { test() + } catch (e: NotImplementedException) { } - catch (e: NotImplementedException) {} } } } diff --git a/test/v_builders/N36ExtensionFunctionLiteralsKtTest.kt b/test/v_builders/N36ExtensionFunctionLiteralsKtTest.kt index bcf60fe92..48b95e514 100644 --- a/test/v_builders/N36ExtensionFunctionLiteralsKtTest.kt +++ b/test/v_builders/N36ExtensionFunctionLiteralsKtTest.kt @@ -1,13 +1,13 @@ package v_builders -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N36ExtensionFunctionLiteralsKtTest { - @Test fun testIsOddAndIsEven() { + @Test + fun testIsOddAndIsEven() { val result = task36() - assertEquals("The functions 'isOdd' and 'isEven' should be implemented correctly", - listOf(false, true, true), result) + assertEquals(listOf(false, true, true), result, "The functions 'isOdd' and 'isEven' should be implemented correctly") } } \ No newline at end of file diff --git a/test/v_builders/N37StringAndMapBuildersKtTest.kt b/test/v_builders/N37StringAndMapBuildersKtTest.kt index 5afed6f47..5c2a4700e 100644 --- a/test/v_builders/N37StringAndMapBuildersKtTest.kt +++ b/test/v_builders/N37StringAndMapBuildersKtTest.kt @@ -1,16 +1,17 @@ package v_builders -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test import java.util.* class N37StringAndMapBuildersKtTest { - @Test fun testBuildMap() { + @Test + fun testBuildMap() { val map = task37() val expected = HashMap() for (i in 0..10) { expected[i] = "$i" } - assertEquals("Map should be filled with the right values", expected, map) + assertEquals(expected, map, "Map should be filled with the right values") } } \ No newline at end of file diff --git a/test/v_builders/N38TheFunctionApplyKtTest.kt b/test/v_builders/N38TheFunctionApplyKtTest.kt index 222a3d2a5..2c939e935 100644 --- a/test/v_builders/N38TheFunctionApplyKtTest.kt +++ b/test/v_builders/N38TheFunctionApplyKtTest.kt @@ -1,11 +1,12 @@ package v_builders.examples -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test import java.util.* class N38TheFunctionApplyKtTest { - @Test fun testBuildString() { + @Test + fun testBuildString() { val expected = StringBuilder().apply { append("Numbers: ") for (i in 1..10) { @@ -13,10 +14,11 @@ class N38TheFunctionApplyKtTest { } }.toString() val actual = buildString() - assertEquals("String should be built:", expected, actual) + assertEquals(expected, actual, "String should be built:") } - @Test fun testBuildMap() { + @Test + fun testBuildMap() { val expected = HashMap().apply { put(0, "0") for (i in 1..10) { @@ -24,6 +26,6 @@ class N38TheFunctionApplyKtTest { } } val actual = buildMap() - assertEquals("Map should be filled with the right values", expected, actual) + assertEquals(expected, actual, "Map should be filled with the right values") } } diff --git a/test/v_builders/N39HtmlBuildersKtTest.kt b/test/v_builders/N39HtmlBuildersKtTest.kt index 806b47932..58c3b09f1 100644 --- a/test/v_builders/N39HtmlBuildersKtTest.kt +++ b/test/v_builders/N39HtmlBuildersKtTest.kt @@ -1,16 +1,18 @@ package v_builders -import org.junit.Assert.assertTrue -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test class N39HtmlBuildersKtTest { - @Test fun productTableIsFilled() { + @Test + fun productTableIsFilled() { val result = renderProductTable() - assertTrue("Product table should contain corresponding data", result.contains("cactus")) + assertTrue(result.contains("cactus"), "Product table should contain corresponding data") } - @Test fun productTableIsColored() { + @Test + fun productTableIsColored() { val result = renderProductTable() - assertTrue("Product table should be colored", result.contains("bgcolor")) + assertTrue(result.contains("bgcolor"), "Product table should be colored") } } diff --git a/test/v_builders/N40BuildersHowItWorksKtTest.kt b/test/v_builders/N40BuildersHowItWorksKtTest.kt index 525b172a3..7a50d8092 100644 --- a/test/v_builders/N40BuildersHowItWorksKtTest.kt +++ b/test/v_builders/N40BuildersHowItWorksKtTest.kt @@ -1,13 +1,14 @@ package v_builders -import org.junit.Assert.fail -import org.junit.Test +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.fail import util.questions.Answer.b import util.questions.Answer.c import v_builders.builders.task40 class N40BuildersHowItWorksKtTest { - @Test fun testBuildersQuiz() { + @Test + fun testBuildersQuiz() { val answers = task40() if (answers.values.toSet() == setOf(null)) { fail("Please specify your answers!") diff --git a/test/vi_generics/N41GenericFunctionsKtTest.kt b/test/vi_generics/N41GenericFunctionsKtTest.kt index bacab18b3..329573c91 100644 --- a/test/vi_generics/N41GenericFunctionsKtTest.kt +++ b/test/vi_generics/N41GenericFunctionsKtTest.kt @@ -1,16 +1,18 @@ package vi_generics -import org.junit.Assert.assertEquals -import org.junit.Test +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test class N41GenericFunctionsKtTest { - @Test fun testPartitionWordsAndLines() { + @Test + fun testPartitionWordsAndLines() { val (words, lines) = listOf("a", "a b", "c", "d e").partitionWordsAndLines() assertEquals(listOf("a", "c"), words) assertEquals(listOf("a b", "d e"), lines) } - @Test fun testPartitionLettersAndOtherSymbols() { + @Test + fun testPartitionLettersAndOtherSymbols() { val (letters, other) = setOf('a', '%', 'r', '}').partitionLettersAndOtherSymbols() assertEquals(setOf('a', 'r'), letters) assertEquals(setOf('%', '}'), other)