Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit e6ef3cc

Browse files
committed
Synchronization with koans in IDE
1 parent 67bc274 commit e6ef3cc

File tree

12 files changed

+53
-34
lines changed

12 files changed

+53
-34
lines changed

kotlin.web.demo.server/examples/Kotlin Koans/Collections/Compound tasks/Test.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ class K_Compound_Tasks {
1515
}
1616

1717
@Test fun testNumberOfTimesEachProductWasOrdered() {
18-
Assert.assertTrue("getNumberOfTimesProductWasOrdered".toMessage(), 3 == shop.getNumberOfTimesProductWasOrdered(reSharper))
18+
Assert.assertTrue(4 == shop.getNumberOfTimesProductWasOrdered(idea))
19+
}
20+
21+
@Test fun testNumberOfTimesEachProductWasOrderedForRepeatedProduct() {
22+
Assert.assertTrue("A customer may order a product for several times",
23+
3 == shop.getNumberOfTimesProductWasOrdered(reSharper))
24+
}
25+
26+
@Test fun testNumberOfTimesEachProductWasOrderedForRepeatedInOrderProduct() {
27+
Assert.assertTrue("An order may contain a particular product more than once",
28+
3 == shop.getNumberOfTimesProductWasOrdered(phpStorm))
1929
}
2030
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
## Fold
22

3-
Implement `Shop.getProductsOrderedByAllCustomers()` using
3+
Implement `Shop.getSetOfProductsOrderedByEveryCustomer()` using
44
[`fold`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/kotlin.-iterable/fold.html).
55

66
```kotlin
77
listOf(1, 2, 3, 4).fold(1, {
88
partProduct, element ->
99
element * partProduct
1010
}) == 24
11-
```
11+
```

kotlin.web.demo.server/examples/Kotlin Koans/Collections/TestShop.kt

+29-20
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ val nathan = "Nathan"
1919
val reka = "Reka"
2020
val bajram = "Bajram"
2121
val asuka = "Asuka"
22+
val riku = "Riku"
2223

2324
//cities
2425
val Canberra = City("Canberra")
@@ -31,38 +32,46 @@ fun customer(name: String, city: City, vararg orders: Order) = Customer(name, ci
3132
fun order(vararg products: Product, isDelivered: Boolean = true) = Order(products.toList(), isDelivered)
3233
fun shop(name: String, vararg customers: Customer) = Shop(name, customers.toList())
3334

34-
val shop = shop("jb test shop",
35-
customer(lucas, Canberra,
36-
order(reSharper),
35+
val shop = shop("jb test shop") {
36+
customer(lucas, Canberra) {
37+
order(reSharper)
3738
order(reSharper, dotMemory, dotTrace)
38-
),
39-
customer(cooper, Canberra),
40-
customer(nathan, Vancouver,
39+
}
40+
customer(cooper, Canberra) {}
41+
customer(nathan, Vancouver) {
4142
order(rubyMine, webStorm)
42-
),
43-
customer(reka, Budapest,
44-
order(idea, isDelivered = false),
45-
order(idea, isDelivered = false),
43+
}
44+
customer(reka, Budapest) {
45+
order(isDelivered = false, products = idea)
46+
order(isDelivered = false, products = idea)
4647
order(idea)
47-
),
48-
customer(bajram, Ankara,
48+
}
49+
customer(bajram, Ankara) {
4950
order(reSharper)
50-
),
51-
customer(asuka, Tokyo,
51+
}
52+
customer(asuka, Tokyo) {
5253
order(idea)
53-
)
54-
)
54+
}
55+
customer(riku, Tokyo) {
56+
order(phpStorm, phpStorm)
57+
order(phpStorm)
58+
}
59+
}
5560

56-
val customers: Map<String, Customer> = shop.customers.map { Pair(it.name, it) }.toMap()
61+
val customers: Map<String, Customer> = shop.customers.fold(hashMapOf<String, Customer>(), {
62+
map, customer ->
63+
map[customer.name] = customer
64+
map
65+
})
5766

58-
val orderedProducts = setOf(idea, reSharper, dotTrace, dotMemory, rubyMine, webStorm)
67+
val orderedProducts = setOf(idea, reSharper, dotTrace, dotMemory, rubyMine, webStorm, phpStorm)
5968

60-
val sortedCustomers = listOf(cooper, nathan, bajram, asuka, lucas, reka).map { customers[it] }
69+
val sortedCustomers = listOf(cooper, nathan, bajram, asuka, lucas, riku, reka).map { customers[it] }
6170

6271
val groupedByCities = mapOf(
6372
Canberra to listOf(lucas, cooper),
6473
Vancouver to listOf(nathan),
6574
Budapest to listOf(reka),
6675
Ankara to listOf(bajram),
67-
Tokyo to listOf(asuka)
76+
Tokyo to listOf(asuka, riku)
6877
).mapValues { it.value.map { name -> customers[name] } }

kotlin.web.demo.server/examples/Kotlin Koans/Conventions/Invoke/Solution.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<answer>class Invokable {
2-
public var numberOfInvocations: Int = 0
2+
var numberOfInvocations: Int = 0
33
private set
4-
operator public fun invoke(): Invokable {
4+
operator fun invoke(): Invokable {
55
numberOfInvocations++
66
return this
77
}

kotlin.web.demo.server/examples/Kotlin Koans/Conventions/Invoke/Task.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Invokable {
2-
public var numberOfInvocations: Int = 0
2+
var numberOfInvocations: Int = 0
33
private set
4-
operator public fun invoke(): Invokable {
4+
operator fun invoke(): Invokable {
55
<taskWindow>TODO()</taskWindow>
66
}
77
}

kotlin.web.demo.server/examples/Kotlin Koans/Conventions/Operators overloading/Task.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fun task1(today: MyDate): MyDate {
1111
}
1212

1313
fun task2(today: MyDate): MyDate {
14-
<taskWindow> TODO("Uncomment") //return today + YEAR * 2 + WEEK * 3 + DAY * 5</taskWindow>
14+
<taskWindow>TODO("Uncomment") //return today + YEAR * 2 + WEEK * 3 + DAY * 5</taskWindow>
1515
}

kotlin.web.demo.server/examples/Kotlin Koans/Conventions/Operators overloading/Test.kt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import org.junit.Assert
22
import org.junit.Test
3-
import TimeInterval.*
43
import koans.util.toMessageInEquals
54

65
class TestOperatorsOverloading {

kotlin.web.demo.server/examples/Kotlin Koans/Generics/Generic functions/Test.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import org.junit.Test
33
import java.util.*
44
import koans.util.toMessageInEquals
55

6-
public class TestGenericFunctions {
6+
class TestGenericFunctions {
77
@Test fun testPartitionWordsAndLines() {
88
partitionWordsAndLines()
99

kotlin.web.demo.server/examples/Kotlin Koans/Introduction/Data classes/Test.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import org.junit.Test
22
import org.junit.Assert
33

44

5-
public class TestDataClasses {
5+
class TestDataClasses {
66
@Test fun testListOfPeople() {
77
Assert.assertEquals("[Person(name=Alice, age=29), Person(name=Bob, age=31)]", getPeople().toString())
88
}

kotlin.web.demo.server/examples/Kotlin Koans/Introduction/Data classes/task.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Person {
2222
}
2323
```
2424

25-
Then add an annotation `data` to the resulting class.
25+
Then add a modifier `data` to the resulting class.
2626
This annotation means the compiler will generate a bunch of useful methods in this class: `equals`/`hashCode`, `toString` and some others.
2727
The `getPeople` function should start to compile.
2828

kotlin.web.demo.server/examples/Kotlin Koans/Introduction/Nullable types/Test.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestNullableTypes {
1111
var invoked = false
1212
val expectedMessage = message
1313
sendMessageToClient(client, message, object : Mailer {
14-
public override fun sendMessage(email: String, message: String) {
14+
override fun sendMessage(email: String, message: String) {
1515
invoked = true
1616
Assert.assertEquals("The message is not as expected:",
1717
expectedMessage, message)

kotlin.web.demo.server/examples/Kotlin Koans/Properties/Delegates how it works/MyDate.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ data class MyDate(val year: Int, val month: Int, val dayOfMonth: Int)
44

55
fun MyDate.toMillis(): Long {
66
val c = Calendar.getInstance()
7-
c.set(year, month, dayOfMonth)
7+
c.set(year, month, dayOfMonth, 0, 0, 0)
8+
c.set(Calendar.MILLISECOND, 0)
89
return c.getTimeInMillis()
910
}
1011

0 commit comments

Comments
 (0)