This repository has been archived by the owner on Sep 17, 2019. It is now read-only.
forked from Kotlin/kotlin-koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reordering: made 'collections' the second part
- Loading branch information
Showing
98 changed files
with
429 additions
and
434 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package v_builders | ||
|
||
import org.junit.Test | ||
import v_builders.builders.todoTask40 | ||
import util.questions.Answer.* | ||
import junit.framework.Assert | ||
import v_builders.builders.task40 | ||
|
||
class _40_Builders_How_It_Works { | ||
@Test fun testBuildersQuiz() { | ||
val correctAnswers = mapOf(22 - 20 to b, 1 + 3 to c, 11 - 8 to b, 79 - 78 to c) | ||
Assert.assertEquals("Your answers are incorrect: ", correctAnswers, task40()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/v_collections/A_Introduction_.kt → src/ii_collections/_13_Introduction_.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
import java.util.HashSet | ||
import util.TODO | ||
|
2 changes: 1 addition & 1 deletion
2
src/v_collections/B_FilterMap.kt → src/ii_collections/_14_FilterMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example1(list: List<Int>) { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
...collections/C_AllAnyAndOtherPredicates.kt → ...llections/_15_AllAnyAndOtherPredicates.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example2(list: List<Int>) { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/v_collections/D_FlatMap.kt → src/ii_collections/_16_FlatMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example() { | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/v_collections/E_MaxMin.kt → src/ii_collections/_17_MaxMin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example4() { | ||
val max = listOf(1, 42, 4).max() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example6() { | ||
val sum = listOf(1, 5, 3).sum() | ||
|
2 changes: 1 addition & 1 deletion
2
src/v_collections/H_GroupBy.kt → src/ii_collections/_20_GroupBy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/v_collections/I_Partition_.kt → src/ii_collections/_21_Partition_.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
fun example8() { | ||
val numbers = listOf(1, 3, -4, 2, -11) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
import java.util.HashSet | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
src/v_collections/K_CompoundTasks.kt → src/ii_collections/_23_CompoundTasks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
..._collections/L_ExtensionsOnCollections.kt → ...ollections/_24_ExtensionsOnCollections.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
data class Shop(val name: String, val customers: List<Customer>) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package v_collections | ||
package ii_collections | ||
|
||
import util.TODO | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/ii_conventions/MyDateUtil.kt → src/iii_conventions/MyDateUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
src/ii_conventions/_11_Comparison_.kt → src/iii_conventions/_25_Comparison_.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package ii_conventions | ||
package iii_conventions | ||
|
||
import util.* | ||
|
||
fun todoTask11(): Nothing = TODO( | ||
fun todoTask25() = TODO( | ||
""" | ||
Task 11. | ||
Task 25. | ||
Uncomment the commented line and make it compile. | ||
Add all changes to the file MyDate.kt. | ||
Make class MyDate implement Comparable. | ||
""", | ||
documentation = doc11(), | ||
documentation = doc25(), | ||
references = { date: MyDate, comparable: Comparable<MyDate> -> } | ||
) | ||
|
||
fun task11(date1: MyDate, date2: MyDate): Boolean { | ||
todoTask11() | ||
fun task25(date1: MyDate, date2: MyDate): Boolean { | ||
todoTask25() | ||
// return date1 < date2 | ||
} | ||
|
10 changes: 5 additions & 5 deletions
10
src/ii_conventions/_12_ForLoop.kt → src/iii_conventions/_26_ForLoop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 5 additions & 26 deletions
31
src/ii_conventions/_14_InRange.kt → src/iii_conventions/_28_InRange.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,21 @@ | ||
package ii_conventions | ||
package iii_conventions | ||
|
||
import util.* | ||
|
||
interface Container<E> { | ||
operator fun contains(element: E): Boolean | ||
} | ||
|
||
fun inConvention(container: Container<String>) { | ||
"a" in container | ||
// compiles to | ||
container.contains("a") | ||
} | ||
|
||
fun numericalRange(i: Int, c: Char) { | ||
//'..' resolves to 'rangeTo' function | ||
if (i in 1..10) {} | ||
|
||
if (c in 'a'..'z') {} | ||
} | ||
|
||
fun stringRange(s: String) { | ||
if (s in "island".."isle") {} | ||
} | ||
|
||
fun todoTask14(): Nothing = TODO( | ||
fun todoTask28() = TODO( | ||
""" | ||
Task 14. | ||
Task 28. | ||
Uncomment the commented line. | ||
Right now interval membership is checked with the function 'fun <T> Iterable<T>.contains(T): Boolean' | ||
which is not optimal (you can check the boundaries instead of iterating over the whole range). | ||
Make class DateRange implement kotlin.Range<MyDate>. | ||
Add all changes to the file MyDate.kt. | ||
""", | ||
documentation = doc14(), | ||
documentation = doc28(), | ||
references = { range: Range<Int> -> } | ||
) | ||
|
||
fun checkInRange(date: MyDate, first: MyDate, last: MyDate): Boolean { | ||
todoTask14() | ||
todoTask28() | ||
// return date in first..last | ||
} |
18 changes: 9 additions & 9 deletions
18
...i_conventions/_15_OperatorsOverloading.kt → ...i_conventions/_29_OperatorsOverloading.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
package ii_conventions | ||
package iii_conventions | ||
|
||
import util.* | ||
import ii_conventions.TimeInterval.* | ||
import iii_conventions.TimeInterval.* | ||
|
||
fun todoTask15() = TODO( | ||
fun todoTask29() = TODO( | ||
""" | ||
Task 15. | ||
Task 29. | ||
Implement a kind of date arithmetic. Support adding years, weeks and days to a date. | ||
Use classes MyDate and TimeInterval. | ||
Use a utility function MyDate.addTimeIntervals. | ||
Uncomment the commented line and make it compile. | ||
(1). Add an extension function 'plus()' to MyDate, taking a TimeInterval as an argument. | ||
(2). Support adding several time intervals to a date. Add an extra class. | ||
If you have any problems, see the ii_conventions/_15_Tips.kt file. | ||
If you have any problems, see the iii_conventions/_29_Tips.kt file. | ||
""", | ||
references = { date: MyDate, timeInterval: TimeInterval -> | ||
date.addTimeIntervals(timeInterval, 1) | ||
}) | ||
|
||
fun task15_1(today: MyDate): MyDate { | ||
todoTask15() | ||
fun task29_1(today: MyDate): MyDate { | ||
todoTask29() | ||
// return today + YEAR + WEEK | ||
} | ||
|
||
fun task15_2(today: MyDate): MyDate { | ||
todoTask15() | ||
fun task29_2(today: MyDate): MyDate { | ||
todoTask29() | ||
// return today + YEAR * 2 + WEEK * 3 + DAY * 5 | ||
} | ||
|
8 changes: 3 additions & 5 deletions
8
src/ii_conventions/_15_Tips.kt → src/iii_conventions/_29_Tips.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.