Skip to content

Commit

Permalink
Fix problems with the tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
nbirillo committed Dec 5, 2024
1 parent 28ebdc1 commit e11f6cf
Show file tree
Hide file tree
Showing 26 changed files with 378 additions and 1,481 deletions.
155 changes: 78 additions & 77 deletions .idea/inspectionProfiles/Custom_Inspections.xml

Large diffs are not rendered by default.

156 changes: 5 additions & 151 deletions culinaryServer/culinaryServerAddSpices/task-info.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
type: edu
custom_name: Master Chef - Add Spices
files:
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/TomatoSoup.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/MasterChefApplication.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameResource.kt
Expand Down Expand Up @@ -43,8 +45,6 @@ files:
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameActions.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/TomatoSoup.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/action/Action.kt
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/action/ActionType.kt
Expand All @@ -68,155 +68,9 @@ files:
- name: test/TomatoSoupFunctions.kt
visible: false
propagatable: false
- name: src/main/resources/static/static/js/2.dbb8f406.chunk.js
visible: false
- name: src/main/resources/static/static/js/3.d8ac33f5.chunk.js
visible: false
- name: src/main/resources/static/static/js/2.dbb8f406.chunk.js.map
visible: false
- name: src/main/resources/static/static/js/3.d8ac33f5.chunk.js.map
visible: false
- name: src/main/resources/static/static/js/runtime~main.35de78a9.js
visible: false
- name: src/main/resources/static/static/js/runtime~main.35de78a9.js.map
visible: false
- name: src/main/resources/static/static/css/main.f33027e0.chunk.css
visible: false
- name: src/main/resources/static/static/css/main.f33027e0.chunk.css.map
visible: false
- name: src/main/resources/static/static/media/bg.159aeebb.svg
visible: false
- name: src/main/resources/static/static/media/logo.af49c77d.svg
visible: false
- name: src/main/resources/static/static/media/salt.f614ace5.svg
visible: false
- name: src/main/resources/static/static/media/berry.a2d5625f.svg
visible: false
- name: src/main/resources/static/static/media/action.1a49790c.svg
visible: false
- name: src/main/resources/static/static/media/citrus.ac3d6e5e.svg
visible: false
- name: src/main/resources/static/static/media/pepper.09265644.svg
visible: false
- name: src/main/resources/static/static/media/blender.9da42019.svg
visible: false
- name: src/main/resources/static/static/media/oregano.12aa7403.svg
visible: false
- name: src/main/resources/static/static/media/bg_white.177e2c94.svg
visible: false
- name: src/main/resources/static/static/media/pot-back.37963222.svg
visible: false
- name: src/main/resources/static/static/media/pot-salt.1369c9ed.svg
visible: false
- name: src/main/resources/static/static/media/pot-soup.78375db2.svg
visible: false
- name: src/main/resources/static/static/media/pot-water.0b6c498f.svg
visible: false
- name: src/main/resources/static/static/media/carrot-raw.d0c2dde4.svg
visible: false
- name: src/main/resources/static/static/media/carrow-cut.96dcc6dc.svg
visible: false
- name: src/main/resources/static/static/media/pot-carrot.c8704838.svg
visible: false
- name: src/main/resources/static/static/media/pot-pepper.47999214.svg
visible: false
- name: src/main/resources/static/static/media/pot-tomato.3f8e1060.svg
visible: false
- name: src/main/resources/static/static/media/salad-bowl.a7f5f34a.svg
visible: false
- name: src/main/resources/static/static/media/tomato-cut.6836153a.svg
visible: false
- name: src/main/resources/static/static/media/tomato-raw.12298a6e.svg
visible: false
- name: src/main/resources/static/static/media/action_wide.df8afed0.svg
visible: false
- name: src/main/resources/static/static/media/back_button.467450b5.svg
visible: false
- name: src/main/resources/static/static/media/basket-back.1e958b40.svg
visible: false
- name: src/main/resources/static/static/media/fridge-open.0aaed28d.svg
visible: false
- name: src/main/resources/static/static/media/play_button.07c3d73d.svg
visible: false
- name: src/main/resources/static/static/media/pot-oregano.8d384419.svg
visible: false
- name: src/main/resources/static/static/media/action_hover.143a84b0.svg
visible: false
- name: src/main/resources/static/static/media/basket-front.10970fd7.svg
visible: false
- name: src/main/resources/static/static/media/blender-full.83a112bd.svg
visible: false
- name: src/main/resources/static/static/media/cucumber-cut.3b775d75.svg
visible: false
- name: src/main/resources/static/static/media/cucumber-raw.c77241ee.svg
visible: false
- name: src/main/resources/static/static/media/pot-cucumber.8b6ffe73.svg
visible: false
- name: src/main/resources/static/static/media/salad-carrot.5d12e03b.svg
visible: false
- name: src/main/resources/static/static/media/salad-tomato.e7fb9ea2.svg
visible: false
- name: src/main/resources/static/static/media/spices-shelf.55a86836.svg
visible: false
- name: src/main/resources/static/static/media/blender-berry.a2f7c947.svg
visible: false
- name: src/main/resources/static/static/media/basket-berry-1.2c5e06bc.svg
visible: false
- name: src/main/resources/static/static/media/basket-berry-2.9a0242a2.svg
visible: false
- name: src/main/resources/static/static/media/basket-berry-3.710f5b43.svg
visible: false
- name: src/main/resources/static/static/media/basket-berry-4.eb6382b0.svg
visible: false
- name: src/main/resources/static/static/media/basket-berry-5.e0f70176.svg
visible: false
- name: src/main/resources/static/static/media/blender-citrus.b243136a.svg
visible: false
- name: src/main/resources/static/static/media/carrot-spoiled.b907b470.svg
visible: false
- name: src/main/resources/static/static/media/salad-cucumber.9e799204.svg
visible: false
- name: src/main/resources/static/static/media/tomato-spoiled.bace9bce.svg
visible: false
- name: src/main/resources/static/static/media/basket-citrus-1.dc10cdb2.svg
visible: false
- name: src/main/resources/static/static/media/basket-citrus-2.9b185241.svg
visible: false
- name: src/main/resources/static/static/media/basket-citrus-3.2af70816.svg
visible: false
- name: src/main/resources/static/static/media/basket-citrus-4.25542618.svg
visible: false
- name: src/main/resources/static/static/media/basket-citrus-5.a54bc4d1.svg
visible: false
- name: src/main/resources/static/static/media/cucumber-spoiled.e5037e35.svg
visible: false
- name: src/main/resources/static/static/media/salad-bowl-mixed.8c29d2b9.svg
visible: false
- name: src/main/resources/static/static/media/action_wide_hover.851872eb.svg
visible: false
- name: src/main/resources/static/static/media/back_button_hover.c7d14fd4.svg
visible: false
- name: src/main/resources/static/static/media/salad-bowl-mixed-carrot.b3f374bb.svg
visible: false
- name: src/main/resources/static/static/media/salad-bowl-mixed-tomato.7b272701.svg
visible: false
- name: src/main/resources/static/static/media/salad-bowl-mixed-cucumber.7992dcf2.svg
visible: false
- name: src/main/resources/static/index.html
visible: false
- name: src/main/resources/static/robots.txt
visible: false
- name: src/main/resources/static/favicon.ico
visible: false
- name: src/main/resources/static/manifest.json
visible: false
- name: src/main/resources/static/service-worker.js
visible: false
- name: src/main/resources/static/asset-manifest.json
visible: false
- name: src/main/resources/static/static/js/main.2934fd44.chunk.js.map
visible: false
visible: true
- name: src/main/resources/static/static/js/main.2934fd44.chunk.js
visible: false
visible: true
- name: src/main/resources/static/precache-manifest.57de0f1ef141f1222d900c3dbd9fb46b.js
visible: false
visible: true
20 changes: 19 additions & 1 deletion culinaryServer/culinaryServerAddSpices/task.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Let's practice and add spices to our soup! In this task we will practice with sequences.
In this task we will make the `Spice` and `Taste` buttons live.

In this task, you need to implement two functions in the `TomatoSoup.kt` file:
You need to implement two functions in the `TomatoSoup.kt` file:

- `generateSpices` - which generates a _sequence_ of random spices
- `addSpices` - that accept a _sequence_ of spices, and do the following with each item from the sequence:
Expand All @@ -11,8 +11,26 @@ In this task, you need to implement two functions in the `TomatoSoup.kt` file:

Afterward you need to _take_ a random number from 1 to 4 of spices from the sequence and perform the described actions.

**Note that if you see the terrible taste message in the application, it does not mean that you have done something wrong.
It means that the number of spices generated was too high.**

<div class="hint" title="Click me to view the expected state of the application after completing this task">

![Current state](../../utils/src/main/resources/images/master/chef/states/spice.gif)

</div>

If you have any difficulties, **hints will help you solve this task**.

----

### Hints

<div class="hint" title="Click me to learn how to use API functions">

The game has the `GameEnviroment.kt` file which contains _instances_ of all possible objects, e.g.
it has `shelf` variable for `ShelfImpl` and to use `ShelfImpl` API you need to call it with `shelf`:
```kotlin
shelf.getSpice(...)
```
</div>
30 changes: 22 additions & 8 deletions culinaryServer/culinaryServerAddSpices/test/Tests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
import org.jetbrains.kotlin.course.culinary.models.food.VegetableType
import org.junit.jupiter.api.Test
import java.lang.reflect.InvocationTargetException
import java.lang.reflect.Method

class Test {
private fun handleInvocationException(e: InvocationTargetException, method: Method) {
val errorMessage = e.targetException.message
errorMessage?.let { m ->
if ("An operation is not implemented" in m) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
}
}
val messageForStudent = errorMessage?.let{ ": $it" } ?: ""
assert(false) { "Ooops! Something went wrong during invocation ${method.name} method$messageForStudent" }
}

@Test
fun generateSpicesMethodTest() {
val spicesSizes = mutableListOf<Int>()
Expand All @@ -40,7 +52,7 @@ class Test {
return try {
method.invokeWithoutArgs(clazz = clazz) as Sequence<SpiceType>
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
emptySequence()
}
}
Expand All @@ -52,12 +64,14 @@ class Test {
val method = clazz.declaredMethods.findMethod(addSpicesMethod)

try {
method.invoke(clazz, generateSpices())
val spices = generateSpices()
clearActions()
method.invoke(clazz, spices)
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
}

assert(actions.isNotEmpty() && actions.all{ it.type == ActionType.PUT_IN_POT }) { "The ${method.name} should generate spices and add them into the pot." }
assert(actions.isNotEmpty() && actions.all{ it.type == ActionType.PUT_IN_POT }) { "The ${method.name} should accepts a sequence of spices and add them into the pot. Don't forget about the terminal function in the end!" }
}

@Test
Expand All @@ -69,7 +83,7 @@ class Test {
val vegetables: List<Vegetable> = try {
method.invokeWithoutArgs(clazz = clazz) as List<Vegetable>
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
emptyList()
}

Expand All @@ -86,7 +100,7 @@ class Test {
try {
method.invoke(clazz, generateTomatoesForSoup())
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
}

val expectedActions = buildList {
Expand Down Expand Up @@ -123,7 +137,7 @@ class Test {
return try {
fridgeImplTestClass.invokeMethodWithoutArgs(clazz, instance, method, true) as List<Vegetable>
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
emptyList()
}
}
Expand All @@ -142,7 +156,7 @@ class Test {
try {
method.invoke(instance)
} catch(e: InvocationTargetException) {
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
handleInvocationException(e, method)
}

val vegetablesNumAfterRefill = FridgeImpl.vegetables.size
Expand Down
Loading

0 comments on commit e11f6cf

Please sign in to comment.