Skip to content

Commit

Permalink
Upgrade kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
nbirillo committed Sep 8, 2023
1 parent 8d9acd5 commit 8d33bc8
Show file tree
Hide file tree
Showing 54 changed files with 89 additions and 101 deletions.
3 changes: 2 additions & 1 deletion .courseignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
backToTheFutureFrontend
duckShopFrontend
oldSchoolFrontend
oldSchoolFrontend
kotlin-js-store
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fun properties(key: String) = project.findProperty(key).toString()
@Suppress("DSL_SCOPE_VIOLATION") // "libs" produces a false-positive warning, see https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
java
val kotlinVersion = "1.7.10"
val kotlinVersion = "1.9.0"
id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply false
id("org.springframework.boot") version "2.7.3" apply false
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
val kotlinVersion = "1.7.10"
val kotlinVersion = "1.9.0"
kotlin("multiplatform") version kotlinVersion
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GameModeService {
fun generateSetOfDucks() = getRandomDucks().toSet()

// It is better to move common code into a separated function
private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS)
private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS)

fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Test {
@Test
fun generateMapOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<Map<Duck, String>>()
repeat(100) {
try {
Expand All @@ -34,7 +34,7 @@ class Test {
@Test
fun generateSetOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<Set<Duck>>()
repeat(100) {
try {
Expand Down Expand Up @@ -73,7 +73,7 @@ class Test {
@Test
fun generateListOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<List<Duck>>()
repeat(100) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GameModeService {
// but this way demonstrates different approaches to work with collections
fun generateListOfDucks() = List(MAX_NUMBER_OF_DUCKS) { generateRandomDuck() }

fun generateSetOfDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet()
fun generateSetOfDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet()

fun generateMapOfDucks(): Map<Duck, String> = TODO("Not implemented yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
6 changes: 3 additions & 3 deletions duckShopServer/DuckShopServerDuckSetInitialization/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ If you have any difficulties, **hints will help you solve this task**.

If you need to shuffle a list of elements, you can use the built-in function [`shuffled`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/shuffled.html).

Since `Duck.values()` returns [`kotlin.Array`](https://kotlinlang.org/docs/arrays.html), by default you cannot invoke the `shuffled` function, you need to convert the result into a list:
Since `Duck.entries()` returns [`kotlin.Array`](https://kotlinlang.org/docs/arrays.html), by default you cannot invoke the `shuffled` function, you need to convert the result into a list:
```kotlin
Duck.values().shuffled() // ERROR
Duck.entries().shuffled() // ERROR

Duck.values().toList().shuffled() // OK
Duck.entries().toList().shuffled() // OK
```

We will not consider the detailed difference between lists and arrays in this project, you can follow to the documentation to get more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import org.jetbrains.academy.test.system.core.findMethod
import org.jetbrains.academy.test.system.core.models.method.TestMethodInvokeData
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.utils.MAX_NUMBER_OF_DUCKS
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.lang.reflect.InvocationTargetException

class Test {
@Test
fun generateSetOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<Set<Duck>>()
repeat(100) {
try {
Expand Down Expand Up @@ -49,7 +48,7 @@ class Test {
@Test
fun generateListOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<List<Duck>>()
repeat(100) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.jetbrains.academy.test.system.core.findMethod
import org.jetbrains.academy.test.system.core.models.method.TestMethodInvokeData
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.utils.MAX_NUMBER_OF_DUCKS
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import java.lang.reflect.InvocationTargetException

Expand All @@ -27,7 +26,7 @@ class Test {
@Test
fun generateListOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<List<Duck>>()
repeat(100) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GameModeService {

fun generateSetOfDucks() = getRandomDucks().toSet()

private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS)
private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS)

fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
2 changes: 0 additions & 2 deletions duckShopServer/DuckShopServerFinishApp/task-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ files:
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/DuckShopApplication.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/duck/shop/tmp.kt
visible: true
- name: src/main/resources/static/precache-manifest.70fad1423aecd2cc1dc8df1c8a51ab6a.js
visible: true
- name: src/main/resources/static/precache-manifest.79d5bbf541fc215a96f9bc662f0e090b.js
Expand Down
9 changes: 0 additions & 9 deletions duckShopServer/DuckShopServerFinishApp/test/Tests.kt
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
import org.junit.Assert
import org.junit.Test

class Test {
@Test fun testSolution() {
//TODO: implement your test here
Assert.assertTrue("Tests not implemented for the task", false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GameModeService {
// but this way demonstrates different approaches to work with collections
fun generateListOfDucks() = List(MAX_NUMBER_OF_DUCKS) { generateRandomDuck() }

fun generateSetOfDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet()
fun generateSetOfDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS).toSet()

fun generateMapOfDucks(): Map<Duck, String> = TODO("Not implemented yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
class GameChangeFunctionsService {
fun List<Duck>.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) }

fun Collection<Duck>.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random()
fun Collection<Duck>.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random()

fun Set<Duck>.addRandomDuck() = getNewRandomDuck().also {
toMutableSet().add(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GameModeService {
fun generateSetOfDucks() = getRandomDucks().toSet()

// It is better to move common code into a separated function
private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS)
private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS)

fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import duck.shop.JsDuck
import org.jetbrains.kotlin.course.duck.shop.duck.Duck
import org.jetbrains.kotlin.course.duck.shop.functions.common.Body

fun String.toDuck() = Duck.values().find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")
fun String.toDuck() = Duck.entries.find { it.name == this || it.customName == this } ?: error("Can not find the duck $this")

fun String.toGameMode() = GameMode.valueOf(this)

Expand Down
16 changes: 8 additions & 8 deletions duckShopServer/duckShopServerAddElements/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Test {
val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, testMethod)
val errorPrefix = "The method ${testMethod.name} should add a random duck to a $collectionName of ducks, but "
val addedDucks = mutableListOf<Duck>()
val possibleDucks = Duck.values().toList()
val possibleDucks = Duck.entries.toList()
repeat(100) {
val currentDucks = toCollection(possibleDucks)
try {
Expand Down Expand Up @@ -57,7 +57,7 @@ class Test {
val invokeData = TestMethodInvokeData(gameChangeFunctionsServiceTestClass, addRandomDuckMapMethod)
val errorPrefix = "The method ${addRandomDuckMapMethod.name} should add a random duck to a map of ducks, but "
val addedDucks = mutableListOf<Pair<Duck, String>>()
val possibleDucks = Duck.values().toList()
val possibleDucks = Duck.entries.toList()
repeat(100) {
val currentDucks = possibleDucks.shuffled().take(MAX_NUMBER_OF_DUCKS).associateWith { it.getDescription() }
try {
Expand Down Expand Up @@ -116,7 +116,7 @@ class Test {
@Test
fun removeRandomDuckFromListMethodTest() {
testRemoveDuckFromCollection(
gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.values().toList().shuffled()
gameChangeFunctionsServiceTestClass, removeRandomDuckListMethod, "list", Duck.entries.toList().shuffled()
) { output, errorPrefix, currentDucks ->
(output as? List<Duck>) ?: run {
assert(false) { "$errorPrefix for the list $currentDucks it returns $output" }
Expand All @@ -131,7 +131,7 @@ class Test {
gameChangeFunctionsServiceTestClass,
removeRandomDuckSetMethod,
"set",
Duck.values().toList().shuffled().toSet()
Duck.entries.toList().shuffled().toSet()
) { output, errorPrefix, currentDucks ->
(output as? Set<Duck>) ?: run {
assert(false) { "$errorPrefix for the set $currentDucks it returns $output" }
Expand All @@ -146,7 +146,7 @@ class Test {
val errorPrefix =
"The method ${removeRandomDuckMapMethod.name} should remove a random duck from a map of ducks, but "
val removedDucks = mutableListOf<Pair<Duck, String>>()
val possibleDucks = Duck.values().toList()
val possibleDucks = Duck.entries.toList()
repeat(100) {
val currentDucks = possibleDucks.shuffled().associateWith { it.getDescription() }
try {
Expand Down Expand Up @@ -174,7 +174,7 @@ class Test {
@Test
fun generateMapOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateMapOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<Map<Duck, String>>()
repeat(100) {
try {
Expand All @@ -198,7 +198,7 @@ class Test {
@Test
fun generateSetOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateSetOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<Set<Duck>>()
repeat(100) {
try {
Expand Down Expand Up @@ -237,7 +237,7 @@ class Test {
@Test
fun generateListOfDucksMethodTest() {
val invokeData = TestMethodInvokeData(gameModeServiceTestClass, generateListOfDucksMethod)
val possibleDucks = Duck.values()
val possibleDucks = Duck.entries
val generatedDucks = mutableSetOf<List<Duck>>()
repeat(100) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ enum class Accessory(val price: Int = 0) {
;
}

fun generateRandomDuck() = Duck.values().random()
fun generateRandomDuck() = Duck.entries.random()

fun Duck.getDescription() = this.customName ?: this.name
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service
class GameChangeFunctionsService {
fun List<Duck>.addRandomDuck() = generateRandomDuck().also { toMutableList().add(it) }

fun Collection<Duck>.getNewRandomDuck() = Duck.values().toList().minus(toSet()).shuffled().random()
fun Collection<Duck>.getNewRandomDuck() = Duck.entries.toList().minus(toSet()).shuffled().random()

fun Set<Duck>.addRandomDuck() = getNewRandomDuck().also {
toMutableSet().add(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GameModeService {
fun generateSetOfDucks() = getRandomDucks().toSet()

// It is better to move common code into a separated function
private fun getRandomDucks() = Duck.values().toList().shuffled().take(MAX_NUMBER_OF_DUCKS)
private fun getRandomDucks() = Duck.entries.toList().shuffled().take(MAX_NUMBER_OF_DUCKS)

fun generateMapOfDucks() = getRandomDucks().associateWith { it.getDescription() }
}
Loading

0 comments on commit 8d33bc8

Please sign in to comment.