diff --git a/src/i_introduction/_10_Object_Expressions/ObjectExpressions.kt b/src/i_introduction/_10_Object_Expressions/ObjectExpressions.kt index 1726c826b..67a75a768 100644 --- a/src/i_introduction/_10_Object_Expressions/ObjectExpressions.kt +++ b/src/i_introduction/_10_Object_Expressions/ObjectExpressions.kt @@ -1,45 +1,22 @@ package i_introduction._10_Object_Expressions -import java.util.Comparator -import util.TODO -import java.io.File -import java.awt.event.MouseListener -import java.awt.event.MouseAdapter -import java.awt.event.MouseEvent - -fun objectLiteral() { - - abstract class Foo { - abstract fun foo() - } - - // Anonymous object extending a class - val foo: Foo = object : Foo() { - override fun foo() { - // ... - } - } - - // Anonymous object extending an interface - runInANewThread(object : Runnable { - override fun run() { - // ... - } - }) -} - -fun runInANewThread(runnable: Runnable) = Thread(runnable).start() +import java.util.* +import util.* fun todoTask10(): Nothing = TODO( """ Task 10. - Add an object expression that extends MouseAdapter and counts the number of mouse clicks - as an argument to the function 'handleMouse()'. - """ + Read about object expressions that play the same role in Kotlin as anonymous classes do in Java. + + Add an object expression that provides a comparator to sort a list in a descending order using java.util.Collections class. + In Kotlin you use Kotlin library extensions instead of java.util.Collections, + but this example is still a good demonstration of mixing Kotlin and Java code. + """, + documentation = doc10() ) -fun task10(handleMouse: (MouseListener) -> Unit): Int { - var mouseClicks = 0 - handleMouse(todoTask10()) - return mouseClicks +fun task10(): List { + val arrayList = arrayListOf(1, 5, 2) + Collections.sort(arrayList, todoTask10()) + return arrayList } \ No newline at end of file diff --git a/src/i_introduction/_11_SAM_Conversions/SAMConversions.kt b/src/i_introduction/_11_SAM_Conversions/SAMConversions.kt new file mode 100644 index 000000000..b9ef32814 --- /dev/null +++ b/src/i_introduction/_11_SAM_Conversions/SAMConversions.kt @@ -0,0 +1,22 @@ +package i_introduction._11_SAM_Conversions + +import util.TODO +import util.doc11_1 +import java.util.* + +fun todoTask11() = TODO( + """ + Task 11. + When an object implements a SAM interface (one with a Single Abstract Method), you can pass a lambda instead. + Read more about SAM conversions in the blog posts about Kotlin. + + Rewrite the previous example changing an object expression to a lambda. + """, + documentation = doc11_1() +) + +fun task11(): List { + val arrayList = arrayListOf(1, 5, 2) + Collections.sort(arrayList, { x, y -> todoTask11() }) + return arrayList +} diff --git a/src/i_introduction/_12_Extensions_On_Collections/ExtensionsOnCollections.kt b/src/i_introduction/_12_Extensions_On_Collections/ExtensionsOnCollections.kt new file mode 100644 index 000000000..7d90a6cee --- /dev/null +++ b/src/i_introduction/_12_Extensions_On_Collections/ExtensionsOnCollections.kt @@ -0,0 +1,22 @@ +package i_introduction._12_Extensions_On_Collections + +import util.* + +fun todoTask12() = TODO( + """ + Task 12. + In Kotlin standard library there are lots of extension functions that make the work with collections more convenient. + Rewrite the previous example once more using an extension function 'sortedDescending'. + + Kotlin code can be easily mixed with Java code. + Thus in Kotlin we don't introduce our own collections, but use standard Java ones (slightly improved). + Read about read-only and mutable views on Java collections. + """, + documentation = doc12_1() +) + +fun task12(): List { + todoTask12() + return arrayListOf(1, 5, 2) +} + diff --git a/src/i_introduction/_1_Functions/JavaCode1.java b/src/i_introduction/_1_Java_To_Kotlin_Converter/JavaCode1.java similarity index 91% rename from src/i_introduction/_1_Functions/JavaCode1.java rename to src/i_introduction/_1_Java_To_Kotlin_Converter/JavaCode1.java index 723be6ad8..f373204aa 100644 --- a/src/i_introduction/_1_Functions/JavaCode1.java +++ b/src/i_introduction/_1_Java_To_Kotlin_Converter/JavaCode1.java @@ -1,4 +1,4 @@ -package i_introduction._1_Functions; +package i_introduction._1_Java_To_Kotlin_Converter; import util.JavaCode; diff --git a/src/i_introduction/_1_Functions/Functions.kt b/src/i_introduction/_1_Java_To_Kotlin_Converter/JavaToKotlinConverter.kt similarity index 88% rename from src/i_introduction/_1_Functions/Functions.kt rename to src/i_introduction/_1_Java_To_Kotlin_Converter/JavaToKotlinConverter.kt index 264d759ce..122f34795 100644 --- a/src/i_introduction/_1_Functions/Functions.kt +++ b/src/i_introduction/_1_Java_To_Kotlin_Converter/JavaToKotlinConverter.kt @@ -1,4 +1,4 @@ -package i_introduction._1_Functions +package i_introduction._1_Java_To_Kotlin_Converter import util.TODO diff --git a/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParams.kt b/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParams.kt deleted file mode 100644 index ca2713bf7..000000000 --- a/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParams.kt +++ /dev/null @@ -1,23 +0,0 @@ -package i_introduction._2_Default_And_Named_Params - -import util.* - -fun todoTask2_1(): Nothing = TODO( - """ - Task 2(1). - Rewrite all overloaded functions 'JavaCode2.foo()' as one function 'foo()' in Kotlin using default parameters. - The function 'foo()' is declared below; you have to add parameters and replace 'todoTask2_1()' with a real body. - Uncomment the commented code and make it compile. - """, - documentation = doc2(), - references = { name: String -> JavaCode2().foo(name); foo(name) }) - -fun foo(name: String): String = todoTask2_1() - -fun task2_1(): String { - todoTask2_1() -// return (foo("a") + -// foo("b", number = 1) + -// foo("c", toUpperCase = true) + -// foo(name = "d", number = 2, toUpperCase = true)) -} diff --git a/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParamsUsage.kt b/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParamsUsage.kt deleted file mode 100644 index 8c316664f..000000000 --- a/src/i_introduction/_2_Default_And_Named_Params/DefaultAndNamedParamsUsage.kt +++ /dev/null @@ -1,17 +0,0 @@ -package i_introduction._2_Default_And_Named_Params - -import util.TODO -import i_introduction._1_Functions.task1 - -fun todoTask2_2(): Nothing = TODO( - """ - Task 2(2). - Implement the same logic as in 'task1' again through the library method 'joinToString()'. - Change values of some of the 'joinToString' arguments. - """, - references = { collection: Collection -> task1(collection); collection.joinToString() }) - -fun task2_2(collection: Collection): String { - todoTask2_2() - return collection.joinToString() -} diff --git a/src/i_introduction/_2_Named_Arguments/NamedArguments.kt b/src/i_introduction/_2_Named_Arguments/NamedArguments.kt new file mode 100644 index 000000000..54ac43375 --- /dev/null +++ b/src/i_introduction/_2_Named_Arguments/NamedArguments.kt @@ -0,0 +1,19 @@ +package i_introduction._2_Named_Arguments + +import util.* +import i_introduction._1_Java_To_Kotlin_Converter.task1 + +fun todoTask2() = TODO( + """ + Task 2. + Implement the same logic as in 'task1' again through the library method 'joinToString()'. + Change values of some of the 'joinToString' arguments. + Use default and named arguments to improve the readability of the function invocation. + """, + documentation = doc2(), + references = { collection: Collection -> task1(collection); collection.joinToString() }) + +fun task2(collection: Collection): String { + todoTask2() + return collection.joinToString() +} diff --git a/src/i_introduction/_3_Default_Arguments/DefaultAndNamedParams.kt b/src/i_introduction/_3_Default_Arguments/DefaultAndNamedParams.kt new file mode 100644 index 000000000..6b3f79344 --- /dev/null +++ b/src/i_introduction/_3_Default_Arguments/DefaultAndNamedParams.kt @@ -0,0 +1,24 @@ +package i_introduction._3_Default_Arguments + +import util.* + +fun todoTask3_() = TODO( + """ + Task 3. + Several overloads of 'JavaCode2.foo()' can be replaced with one function in Kotlin. + Change the declaration of the function 'foo' in a way that makes the code using 'foo' compile. + You have to add parameters and replace 'todoTask3()' with a real body. + Uncomment the commented code and make it compile. + """, + documentation = doc2(), + references = { name: String -> JavaCode2().foo(name); foo(name) }) + +fun foo(name: String): String = todoTask3_() + +fun task3_(): String { + todoTask3_() +// return (foo("a") + +// foo("b", number = 1) + +// foo("c", toUpperCase = true) + +// foo(name = "d", number = 2, toUpperCase = true)) +} diff --git a/src/i_introduction/_2_Default_And_Named_Params/JavaCode2.java b/src/i_introduction/_3_Default_Arguments/JavaCode2.java similarity index 91% rename from src/i_introduction/_2_Default_And_Named_Params/JavaCode2.java rename to src/i_introduction/_3_Default_Arguments/JavaCode2.java index cac861051..cc2826c65 100644 --- a/src/i_introduction/_2_Default_And_Named_Params/JavaCode2.java +++ b/src/i_introduction/_3_Default_Arguments/JavaCode2.java @@ -1,4 +1,4 @@ -package i_introduction._2_Default_And_Named_Params; +package i_introduction._3_Default_Arguments; import util.JavaCode; diff --git a/src/i_introduction/_3_Lambdas/JavaCode3.java b/src/i_introduction/_4_Lambdas/JavaCode3.java similarity index 92% rename from src/i_introduction/_3_Lambdas/JavaCode3.java rename to src/i_introduction/_4_Lambdas/JavaCode3.java index 2e68b3c59..f5dc56ba6 100644 --- a/src/i_introduction/_3_Lambdas/JavaCode3.java +++ b/src/i_introduction/_4_Lambdas/JavaCode3.java @@ -1,4 +1,4 @@ -package i_introduction._3_Lambdas; +package i_introduction._4_Lambdas; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; diff --git a/src/i_introduction/_3_Lambdas/Lambdas.kt b/src/i_introduction/_4_Lambdas/Lambdas.kt similarity index 93% rename from src/i_introduction/_3_Lambdas/Lambdas.kt rename to src/i_introduction/_4_Lambdas/Lambdas.kt index 7a429290b..02ee814b6 100644 --- a/src/i_introduction/_3_Lambdas/Lambdas.kt +++ b/src/i_introduction/_4_Lambdas/Lambdas.kt @@ -1,4 +1,4 @@ -package i_introduction._3_Lambdas +package i_introduction._4_Lambdas import util.* diff --git a/src/i_introduction/_4_String_Templates/StringTemplates.kt b/src/i_introduction/_5_String_Templates/StringTemplates.kt similarity index 93% rename from src/i_introduction/_4_String_Templates/StringTemplates.kt rename to src/i_introduction/_5_String_Templates/StringTemplates.kt index 665a7e793..495c2eb9d 100644 --- a/src/i_introduction/_4_String_Templates/StringTemplates.kt +++ b/src/i_introduction/_5_String_Templates/StringTemplates.kt @@ -1,4 +1,4 @@ -package i_introduction._4_String_Templates +package i_introduction._5_String_Templates import java.util.regex.Pattern import util.* diff --git a/src/i_introduction/_7_Data_Classes/DataClasses.kt b/src/i_introduction/_6_Data_Classes/DataClasses.kt similarity index 93% rename from src/i_introduction/_7_Data_Classes/DataClasses.kt rename to src/i_introduction/_6_Data_Classes/DataClasses.kt index 2046af5f8..5cb15d1dc 100644 --- a/src/i_introduction/_7_Data_Classes/DataClasses.kt +++ b/src/i_introduction/_6_Data_Classes/DataClasses.kt @@ -1,4 +1,4 @@ -package i_introduction._7_Data_Classes +package i_introduction._6_Data_Classes import util.* diff --git a/src/i_introduction/_7_Data_Classes/JavaCode7.java b/src/i_introduction/_6_Data_Classes/JavaCode7.java similarity index 91% rename from src/i_introduction/_7_Data_Classes/JavaCode7.java rename to src/i_introduction/_6_Data_Classes/JavaCode7.java index 6c2d3f6cb..f3373399b 100644 --- a/src/i_introduction/_7_Data_Classes/JavaCode7.java +++ b/src/i_introduction/_6_Data_Classes/JavaCode7.java @@ -1,4 +1,4 @@ -package i_introduction._7_Data_Classes; +package i_introduction._6_Data_Classes; import util.JavaCode; diff --git a/src/i_introduction/_5_Nullable_Types/JavaCode5.java b/src/i_introduction/_7_Nullable_Types/JavaCode5.java similarity index 93% rename from src/i_introduction/_5_Nullable_Types/JavaCode5.java rename to src/i_introduction/_7_Nullable_Types/JavaCode5.java index cd41a4014..a536739d3 100644 --- a/src/i_introduction/_5_Nullable_Types/JavaCode5.java +++ b/src/i_introduction/_7_Nullable_Types/JavaCode5.java @@ -1,4 +1,4 @@ -package i_introduction._5_Nullable_Types; +package i_introduction._7_Nullable_Types; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/i_introduction/_5_Nullable_Types/NullableTypes.kt b/src/i_introduction/_7_Nullable_Types/NullableTypes.kt similarity index 94% rename from src/i_introduction/_5_Nullable_Types/NullableTypes.kt rename to src/i_introduction/_7_Nullable_Types/NullableTypes.kt index a4ce50cce..c6a13e5f0 100644 --- a/src/i_introduction/_5_Nullable_Types/NullableTypes.kt +++ b/src/i_introduction/_7_Nullable_Types/NullableTypes.kt @@ -1,4 +1,4 @@ -package i_introduction._5_Nullable_Types +package i_introduction._7_Nullable_Types import util.* diff --git a/src/i_introduction/_6_Smart_Casts/JavaCode6.java b/src/i_introduction/_8_Smart_Casts/JavaCode6.java similarity index 91% rename from src/i_introduction/_6_Smart_Casts/JavaCode6.java rename to src/i_introduction/_8_Smart_Casts/JavaCode6.java index bad89526c..b3ff690ea 100644 --- a/src/i_introduction/_6_Smart_Casts/JavaCode6.java +++ b/src/i_introduction/_8_Smart_Casts/JavaCode6.java @@ -1,4 +1,4 @@ -package i_introduction._6_Smart_Casts; +package i_introduction._8_Smart_Casts; import util.JavaCode; diff --git a/src/i_introduction/_6_Smart_Casts/SmartCasts.kt b/src/i_introduction/_8_Smart_Casts/SmartCasts.kt similarity index 93% rename from src/i_introduction/_6_Smart_Casts/SmartCasts.kt rename to src/i_introduction/_8_Smart_Casts/SmartCasts.kt index b085451f1..df6230b6d 100644 --- a/src/i_introduction/_6_Smart_Casts/SmartCasts.kt +++ b/src/i_introduction/_8_Smart_Casts/SmartCasts.kt @@ -1,4 +1,4 @@ -package i_introduction._6_Smart_Casts +package i_introduction._8_Smart_Casts import util.* diff --git a/src/i_introduction/_8_Extension_Functions/ExtensionFunctions.kt b/src/i_introduction/_9_Extension_Functions/ExtensionFunctions.kt similarity index 88% rename from src/i_introduction/_8_Extension_Functions/ExtensionFunctions.kt rename to src/i_introduction/_9_Extension_Functions/ExtensionFunctions.kt index d2ffeff9c..af2b4a0aa 100644 --- a/src/i_introduction/_8_Extension_Functions/ExtensionFunctions.kt +++ b/src/i_introduction/_9_Extension_Functions/ExtensionFunctions.kt @@ -1,4 +1,4 @@ -package i_introduction._8_Extension_Functions.StringExtensions +package i_introduction._9_Extension_Functions import util.* diff --git a/src/i_introduction/_9_Extensions_On_Collections/ExtensionsOnCollections.kt b/src/i_introduction/_9_Extensions_On_Collections/ExtensionsOnCollections.kt deleted file mode 100644 index e15097d99..000000000 --- a/src/i_introduction/_9_Extensions_On_Collections/ExtensionsOnCollections.kt +++ /dev/null @@ -1,61 +0,0 @@ -package i_introduction._9_Extensions_On_Collections - -import util.TODO - -data class User(val name: String, val lastName: String, val age: Int) - -fun operationsWithCollections() { - val users = listOf( - User("John", "Doe", 19), - User("Jane", "Doe", 22) - ) - - // Iterate over collection: - for (user in users) { - } - - val minors = users.filter { u -> u.age < 21 } - println("${minors.size} user(s) under 21 years old") - - val youngestOver20 = users.filter { u -> u.age > 20 }.minBy { u -> u.age } - println("Youngest over 20: $youngestOver20") -} - -fun operationsWithMaps() { - - val map = hashMapOf(1 to "one", 3 to "three", 42 to "forty two") - - // Iterate over map: - for ((key, value) in map) { - } - - // Convenient way to access elements: - map[43] = map[42] + " plus one" - - // The details on how this code works may be found in the 'Conventions' task, later in this tutorial. - - println(map) -} - -fun main(args: Array) { - operationsWithCollections() - operationsWithMaps() -} - -fun todoTask9(): Nothing = TODO( - """ - Task 9. - The function should behave the same as 'JavaCode9.doSomethingStrangeWithCollection' - Replace all invocations of 'todoTask9()' with the appropriate code. - """, - references = { c: Collection -> JavaCode9().doSomethingStrangeWithCollection(c) } -) - -fun doSomethingStrangeWithCollection(collection: Collection): Collection? { - val groupsByLength = collection. groupBy { s -> todoTask9() } - - val maximumSizeOfGroup = groupsByLength.values.map { group -> todoTask9() }.max() - - return groupsByLength.values.firstOrNull { group -> todoTask9() } -} - diff --git a/src/util/JavaCode.java b/src/util/JavaCode.java index 7d9b084af..ece1f8990 100644 --- a/src/util/JavaCode.java +++ b/src/util/JavaCode.java @@ -7,10 +7,7 @@ public class JavaCode { public static Set set = Sets.newHashSet(); -// private final int i; - public JavaCode() { -// this.getClass() set.add(this.getClass().getName()); } } diff --git a/src/util/LinksToDocumentation.kt b/src/util/LinksToDocumentation.kt index 990ad30fe..afb3fa795 100644 --- a/src/util/LinksToDocumentation.kt +++ b/src/util/LinksToDocumentation.kt @@ -44,6 +44,24 @@ fun doc7() {} */ fun doc8() {} +//https://kotlinlang.org/docs/reference/object-declarations.html + +/** + * @see Object expressions + */ +fun doc10() {} + +/** + * @see SAM-constructors, + * SAM-conversions + */ +fun doc11_1() {} + +/** + * @see Read-only and mutable views on Java collections + */ +fun doc12_1() {} + /** * @see Operator overloading */ diff --git a/src/i_introduction/_9_Extensions_On_Collections/JavaCode9.java b/src/v_collections/LJavaCode9.java similarity index 91% rename from src/i_introduction/_9_Extensions_On_Collections/JavaCode9.java rename to src/v_collections/LJavaCode9.java index 350c432b9..00d985e4e 100644 --- a/src/i_introduction/_9_Extensions_On_Collections/JavaCode9.java +++ b/src/v_collections/LJavaCode9.java @@ -1,4 +1,4 @@ -package i_introduction._9_Extensions_On_Collections; +package v_collections; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -8,7 +8,7 @@ import java.util.List; import java.util.Map; -public class JavaCode9 extends JavaCode { +public class LJavaCode9 extends JavaCode { public Collection doSomethingStrangeWithCollection(Collection collection) { Map> groupsByLength = Maps.newHashMap(); for (String s : collection) { diff --git a/src/v_collections/L_ExtensionsOnCollections.kt b/src/v_collections/L_ExtensionsOnCollections.kt new file mode 100644 index 000000000..334304163 --- /dev/null +++ b/src/v_collections/L_ExtensionsOnCollections.kt @@ -0,0 +1,21 @@ +package v_collections + +import util.TODO + +fun todoTask9() = TODO( + """ + Task 9. + The function should behave the same as 'LJavaCode9.doSomethingStrangeWithCollection' + Replace all invocations of 'todoTask9()' with the appropriate code. + """, + references = { c: Collection -> LJavaCode9().doSomethingStrangeWithCollection(c) } +) + +fun doSomethingStrangeWithCollection(collection: Collection): Collection? { + val groupsByLength = collection. groupBy { s -> todoTask9() } + + val maximumSizeOfGroup = groupsByLength. values(). map { group -> todoTask9() }. max() + + return groupsByLength. values(). firstOrNull { group -> todoTask9() } +} + diff --git a/src/v_collections/todoUtil.kt b/src/v_collections/todoUtil.kt index 310f44580..f93d767d4 100644 --- a/src/v_collections/todoUtil.kt +++ b/src/v_collections/todoUtil.kt @@ -1,6 +1,8 @@ package v_collections -fun todoCollectionTask(): Nothing = util.TODO( +import util.TODO + +fun todoCollectionTask() = TODO( """ Task for working with collections. Look through the 'Shop' API; all tasks are connected with it. diff --git a/test/i_introduction/_10_Object_Expressions/_10_Object_Expressions.kt b/test/i_introduction/_10_Object_Expressions/_10_Object_Expressions.kt index 98fc3c590..271c0b8e9 100644 --- a/test/i_introduction/_10_Object_Expressions/_10_Object_Expressions.kt +++ b/test/i_introduction/_10_Object_Expressions/_10_Object_Expressions.kt @@ -1,19 +1,10 @@ package i_introduction._10_Object_Expressions -import org.junit.Test as test import org.junit.Assert -import java.awt.event.MouseEvent -import java.awt.Component +import org.junit.Test as test class _10_Object_Expressions { - @test fun testStringComparator() { - val mouseEvent = MouseEvent(object : Component() {}, 0, 0L, 0, 0, 0, 1, false) - val result = task10 { mouseListener -> - mouseListener.mouseClicked(mouseEvent) - mouseListener.mouseClicked(mouseEvent) - mouseListener.mouseClicked(mouseEvent) - mouseListener.mouseClicked(mouseEvent) - } - Assert.assertEquals("Mouse clicks should be counted: ", 4, result) + @test fun testSort() { + Assert.assertEquals(listOf(5, 2, 1), task10()) } } diff --git a/test/i_introduction/_11_SAM_Conversions/_11_SAM_Conversions.kt b/test/i_introduction/_11_SAM_Conversions/_11_SAM_Conversions.kt new file mode 100644 index 000000000..058c9da21 --- /dev/null +++ b/test/i_introduction/_11_SAM_Conversions/_11_SAM_Conversions.kt @@ -0,0 +1,10 @@ +package i_introduction._11_SAM_Conversions + +import org.junit.Assert +import org.junit.Test as test + +class _11_SAM_Conversions { + @test fun testSort() { + Assert.assertEquals(listOf(5, 2, 1), task11()) + } +} diff --git a/test/i_introduction/_12_Extensions_On_Collections/_12_Extensions_On_Collections.kt b/test/i_introduction/_12_Extensions_On_Collections/_12_Extensions_On_Collections.kt new file mode 100644 index 000000000..ec2a3c195 --- /dev/null +++ b/test/i_introduction/_12_Extensions_On_Collections/_12_Extensions_On_Collections.kt @@ -0,0 +1,10 @@ +package i_introduction._12_Extensions_On_Collections + +import org.junit.Assert +import org.junit.Test + +class _12_Extensions_On_Collections { + @Test fun testSort() { + Assert.assertEquals(listOf(5, 2, 1), task12()) + } +} diff --git a/test/i_introduction/_1_Functions/_01_Functions.kt b/test/i_introduction/_1_Java_To_Kotlin_Converter/_01_Functions.kt similarity index 81% rename from test/i_introduction/_1_Functions/_01_Functions.kt rename to test/i_introduction/_1_Java_To_Kotlin_Converter/_01_Functions.kt index 7363e5100..0a566968d 100644 --- a/test/i_introduction/_1_Functions/_01_Functions.kt +++ b/test/i_introduction/_1_Java_To_Kotlin_Converter/_01_Functions.kt @@ -1,4 +1,4 @@ -package i_introduction._1_Functions +package i_introduction._1_Java_To_Kotlin_Converter import kotlin.test.* import org.junit.Test as test diff --git a/test/i_introduction/_2_Default_And_Named_Params/_02_Default_And_Named_Params.kt b/test/i_introduction/_2_Default_And_Named_Params/_02_Default_And_Named_Params.kt deleted file mode 100644 index 0c1e6ecc3..000000000 --- a/test/i_introduction/_2_Default_And_Named_Params/_02_Default_And_Named_Params.kt +++ /dev/null @@ -1,17 +0,0 @@ -package i_introduction._2_Default_And_Named_Params - -import kotlin.test.* -import org.junit.Test as test -import org.junit.Assert - -class _02_Default_And_Named_Params() { - - @test fun testDefaultAndNamedParams() { - Assert.assertEquals("a42b1C42D2", task2_1()) - } - - @test fun testJoinToString() { - Assert.assertEquals("{1, 2, 3, 42, 555}", task2_2(listOf(1, 2, 3, 42, 555))) - } - -} \ No newline at end of file diff --git a/test/i_introduction/_2_Named_Arguments/_02_Default_And_Named_Params.kt b/test/i_introduction/_2_Named_Arguments/_02_Default_And_Named_Params.kt new file mode 100644 index 000000000..fb3d91a1e --- /dev/null +++ b/test/i_introduction/_2_Named_Arguments/_02_Default_And_Named_Params.kt @@ -0,0 +1,12 @@ +package i_introduction._2_Named_Arguments + +import org.junit.Assert +import org.junit.Test as test + +class _02_Default_And_Named_Params() { + + @org.junit.Test fun testJoinToString() { + Assert.assertEquals("{1, 2, 3, 42, 555}", task2(listOf(1, 2, 3, 42, 555))) + } + +} \ No newline at end of file diff --git a/test/i_introduction/_3_Default_Arguments/_03_Default_Arguments.kt b/test/i_introduction/_3_Default_Arguments/_03_Default_Arguments.kt new file mode 100644 index 000000000..5a0ace945 --- /dev/null +++ b/test/i_introduction/_3_Default_Arguments/_03_Default_Arguments.kt @@ -0,0 +1,11 @@ +package i_introduction._3_Default_Arguments + +import org.junit.Assert +import org.junit.Test as test + +class _03_Default_Arguments() { + + @test fun testDefaultAndNamedParams() { + Assert.assertEquals("a42b1C42D2", task3_()) + } +} \ No newline at end of file diff --git a/test/i_introduction/_3_Lambdas/_03_Lambdas.kt b/test/i_introduction/_4_Lambdas/_03_Lambdas.kt similarity index 89% rename from test/i_introduction/_3_Lambdas/_03_Lambdas.kt rename to test/i_introduction/_4_Lambdas/_03_Lambdas.kt index fe7099a35..0ffa041bc 100644 --- a/test/i_introduction/_3_Lambdas/_03_Lambdas.kt +++ b/test/i_introduction/_4_Lambdas/_03_Lambdas.kt @@ -1,4 +1,4 @@ -package i_introduction._3_Lambdas +package i_introduction._4_Lambdas import kotlin.test.* import org.junit.Test as test diff --git a/test/i_introduction/_4_String_Templates/_04_String_Templates.kt b/test/i_introduction/_5_String_Templates/_04_String_Templates.kt similarity index 92% rename from test/i_introduction/_4_String_Templates/_04_String_Templates.kt rename to test/i_introduction/_5_String_Templates/_04_String_Templates.kt index 31b7ec906..c11e06a33 100644 --- a/test/i_introduction/_4_String_Templates/_04_String_Templates.kt +++ b/test/i_introduction/_5_String_Templates/_04_String_Templates.kt @@ -1,4 +1,4 @@ -package i_introduction._4_String_Templates +package i_introduction._5_String_Templates import kotlin.test.* import org.junit.Test as test diff --git a/test/i_introduction/_7_Data_Classes/_07_Data_Classes.kt b/test/i_introduction/_6_Data_Classes/_07_Data_Classes.kt similarity index 86% rename from test/i_introduction/_7_Data_Classes/_07_Data_Classes.kt rename to test/i_introduction/_6_Data_Classes/_07_Data_Classes.kt index edbba62af..043b5bee9 100644 --- a/test/i_introduction/_7_Data_Classes/_07_Data_Classes.kt +++ b/test/i_introduction/_6_Data_Classes/_07_Data_Classes.kt @@ -1,4 +1,4 @@ -package i_introduction._7_Data_Classes +package i_introduction._6_Data_Classes import kotlin.test.* import org.junit.Test as test diff --git a/test/i_introduction/_5_Nullable_Types/_05_Nullable_Types.kt b/test/i_introduction/_7_Nullable_Types/_05_Nullable_Types.kt similarity index 97% rename from test/i_introduction/_5_Nullable_Types/_05_Nullable_Types.kt rename to test/i_introduction/_7_Nullable_Types/_05_Nullable_Types.kt index 1f5100a68..ed6d0235b 100644 --- a/test/i_introduction/_5_Nullable_Types/_05_Nullable_Types.kt +++ b/test/i_introduction/_7_Nullable_Types/_05_Nullable_Types.kt @@ -1,4 +1,4 @@ -package i_introduction._5_Nullable_Types +package i_introduction._7_Nullable_Types import org.junit.Test as test import junit.framework.Assert diff --git a/test/i_introduction/_6_Smart_Casts/_06_Smart_Casts.kt b/test/i_introduction/_8_Smart_Casts/_06_Smart_Casts.kt similarity index 92% rename from test/i_introduction/_6_Smart_Casts/_06_Smart_Casts.kt rename to test/i_introduction/_8_Smart_Casts/_06_Smart_Casts.kt index 934585938..d2bd83c9c 100644 --- a/test/i_introduction/_6_Smart_Casts/_06_Smart_Casts.kt +++ b/test/i_introduction/_8_Smart_Casts/_06_Smart_Casts.kt @@ -1,4 +1,4 @@ -package i_introduction._6_Smart_Casts +package i_introduction._8_Smart_Casts import org.junit.Assert import org.junit.Test as test diff --git a/test/i_introduction/_8_Extension_Functions/_08_Extension_Functions.kt b/test/i_introduction/_9_Extension_Functions/_08_Extension_Functions.kt similarity index 81% rename from test/i_introduction/_8_Extension_Functions/_08_Extension_Functions.kt rename to test/i_introduction/_9_Extension_Functions/_08_Extension_Functions.kt index 11561bd1c..97a32725a 100644 --- a/test/i_introduction/_8_Extension_Functions/_08_Extension_Functions.kt +++ b/test/i_introduction/_9_Extension_Functions/_08_Extension_Functions.kt @@ -1,8 +1,7 @@ -package i_introduction._8_Extension_Functions.StringExtensions +package i_introduction._9_Extension_Functions -import kotlin.test.* -import org.junit.Test as test import org.junit.Assert +import org.junit.Test as test class _08_Extension_Functions() { @test fun testIntExtension() { diff --git a/test/util/AdditionalTest.kt b/test/util/AdditionalTest.kt index e8f776b1b..863bfb3bb 100644 --- a/test/util/AdditionalTest.kt +++ b/test/util/AdditionalTest.kt @@ -1,25 +1,25 @@ package util import org.junit.Test as test -import i_introduction._1_Functions._01_Functions +import i_introduction._1_Java_To_Kotlin_Converter._01_Functions import junit.framework.Assert -import i_introduction._2_Default_And_Named_Params._02_Default_And_Named_Params -import i_introduction._3_Lambdas._03_Lambdas -import i_introduction._5_Nullable_Types._05_Nullable_Types -import i_introduction._6_Smart_Casts._06_Smart_Casts -import i_introduction._9_Extensions_On_Collections._09_Extensions_On_Collections +import i_introduction._3_Default_Arguments._03_Default_Arguments +import i_introduction._4_Lambdas._03_Lambdas +import i_introduction._7_Nullable_Types._05_Nullable_Types +import i_introduction._8_Smart_Casts._06_Smart_Casts +import v_collections.L_Extensions_On_Collections class AdditionalTest { @test fun test() { invokeTests( { _01_Functions().collection() }, - { _02_Default_And_Named_Params().testDefaultAndNamedParams() }, + { _03_Default_Arguments().testDefaultAndNamedParams() }, { _03_Lambdas().contains() }, { _05_Nullable_Types().everythingIsOk() }, { _06_Smart_Casts().testNum() }, - { _09_Extensions_On_Collections().testCollectionOfOneElement() } + { L_Extensions_On_Collections().testCollectionOfOneElement() } ) - Assert.assertTrue("${JavaCode.set}", JavaCode.set!!.isEmpty()) + Assert.assertTrue("${JavaCode.set}", JavaCode.set.isEmpty) } private fun invokeTests(vararg tests: () -> Unit) { diff --git a/test/i_introduction/_9_Extensions_On_Collections/_09_Extensions_On_Collections.kt b/test/v_collections/L_Extensions_On_Collections.kt similarity index 63% rename from test/i_introduction/_9_Extensions_On_Collections/_09_Extensions_On_Collections.kt rename to test/v_collections/L_Extensions_On_Collections.kt index cdfc15a41..1e47d37f9 100644 --- a/test/i_introduction/_9_Extensions_On_Collections/_09_Extensions_On_Collections.kt +++ b/test/v_collections/L_Extensions_On_Collections.kt @@ -1,27 +1,26 @@ -package i_introduction._9_Extensions_On_Collections +package v_collections -import kotlin.test.* -import org.junit.Test as test import org.junit.Assert +import org.junit.Test -class _09_Extensions_On_Collections { - @test fun testCollectionOfOneElement() { +class L_Extensions_On_Collections { + @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")) }