Skip to content

Commit 7a097a7

Browse files
committed
Add more project steps
1 parent 462428e commit 7a097a7

File tree

293 files changed

+4800
-1659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+4800
-1659
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.jetbrains.kotlin.course.culinary.game
22

33
import org.jetbrains.kotlin.course.culinary.converters.toItemType
4-
import org.jetbrains.kotlin.course.culinary.game.CookingService.Companion.NUM_VEGETABLES_FOR_SALAD
54
import org.jetbrains.kotlin.course.culinary.game.recipes.NUMBER_OF_TOMATOES
5+
import org.jetbrains.kotlin.course.culinary.game.recipes.NUM_VEGETABLES_FOR_SALAD
66
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl
77
import org.jetbrains.kotlin.course.culinary.models.ItemType
88
import org.jetbrains.kotlin.course.culinary.models.Task
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.jetbrains.kotlin.course.culinary.game
2+
3+
import org.jetbrains.kotlin.course.culinary.game.recipes.*
4+
import org.jetbrains.kotlin.course.culinary.models.food.CutVegetable
5+
import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
6+
import org.springframework.stereotype.Service
7+
8+
@Service
9+
class CookingService {
10+
fun cookTomatoSoup() {
11+
val tomatoes = getTomatoesForSoup()
12+
prepareTomatoes(tomatoes)
13+
pot.simmer()
14+
}
15+
16+
fun cookWithSpices() {
17+
val spices = generateSpices()
18+
addSpices(spices)
19+
pot.simmer()
20+
}
21+
22+
fun cookSaladAsList() {
23+
mixVegetablesForSalad(getFreshVegetables().cut())
24+
}
25+
26+
fun cookSaladAsSequence() {
27+
mixVegetablesForSalad(getFreshVegetables().asSequence().cut())
28+
}
29+
30+
private fun Sequence<Vegetable>.cut(): List<CutVegetable> = map { kitchen.put(it) }
31+
.map { kitchen.cut(it) }
32+
.take(NUM_VEGETABLES_FOR_SALAD)
33+
.map { kitchen.take(it) }
34+
.toList()
35+
36+
fun cookSmoothie(){
37+
getFruitsForSmoothie().cookSmoothie()
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.jetbrains.kotlin.course.culinary.game.recipes
2+
3+
import org.jetbrains.kotlin.course.culinary.models.food.CutVegetable
4+
import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
5+
6+
const val NUM_VEGETABLES_FOR_SALAD = 5
7+
8+
fun getFreshVegetables(): List<Vegetable> = TODO("Not implemented yet")
9+
10+
fun List<Vegetable>.cut(): List<CutVegetable> = TODO("Not implemented yet")
11+
12+
fun mixVegetablesForSalad(cutVegetables: List<CutVegetable>) {
13+
TODO("Not implemented yet")
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.jetbrains.kotlin.course.culinary.game.recipes
2+
3+
import org.jetbrains.kotlin.course.culinary.models.food.Fruit
4+
5+
fun getFruitsForSmoothie(): List<Fruit> = TODO("Not implemented yet")
6+
7+
fun List<Fruit>.cookSmoothie() {
8+
TODO("Not implemented yet")
9+
}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,20 @@ import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
1111
import org.jetbrains.kotlin.course.culinary.models.food.VegetableType
1212
import kotlin.random.Random
1313

14-
internal const val NUMBER_OF_TOMATOES = 3
14+
const val NUMBER_OF_TOMATOES = 3
1515

16-
// TODO: add tests
17-
// task#1
1816
fun getTomatoesForSoup(): List<Vegetable> =
1917
List(NUMBER_OF_TOMATOES) { fridge.getVegetable(what = VegetableType.Tomato) }
2018

21-
// TODO: add tests
22-
// task#1
2319
fun prepareTomatoes(tomatoes: List<Vegetable>) {
2420
tomatoes
2521
.onEach { kitchen.put(it) }
2622
.map { kitchen.cut(it) }
2723
.forEach { pot.put(kitchen.take(it)) }
2824
}
2925

30-
fun cookSoup() {
31-
pot.simmer()
32-
}
33-
34-
// task#2
3526
fun generateSpices(): Sequence<SpiceType> = generateSequence { SpiceType.entries.random() }
3627

37-
// task#2
3828
fun addSpices(spices: Sequence<SpiceType>) {
3929
val howMuchToAdd = Random.nextInt(1, 4)
4030
spices
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ data object PotImpl : Pot {
1111
val filling: MutableList<Ingredient> = mutableListOf()
1212
var simmering: Boolean = false
1313

14+
override fun doesTastePerfect(): Boolean = filling.filter{ it is Spice }
15+
.groupingBy{ it }
16+
.eachCount()
17+
.filter{ (_, n) -> n > 2 }
18+
.isEmpty()
19+
1420
override fun <T: Ingredient> put(ingredient: T) {
1521
filling.add(ingredient)
1622
actions.add(buildAction(ActionType.PUT_IN_POT, ingredient))
@@ -21,13 +27,6 @@ data object PotImpl : Pot {
2127
actions.add(buildAction(ActionType.PUT_IN_POT, vegetable))
2228
}
2329

24-
// task#2
25-
override fun doesTastePerfect(): Boolean = filling.filter{ it is Spice }
26-
.groupingBy{ it }
27-
.eachCount()
28-
.filter{ (_, n) -> n > 2 }
29-
.isEmpty()
30-
3130
override fun simmer() {
3231
check(!simmering) { "You are already simmering" }
3332
simmering = true
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,21 @@ import org.jetbrains.kotlin.course.culinary.models.storage.Fridge
1010
import kotlin.random.Random
1111

1212
data object FridgeImpl : Fridge {
13-
private const val RANDOM_VEGETABLES_NUMBER = 7
14-
private const val RANDOM_FRESH_VEGETABLES_NUMBER = 3
13+
const val RANDOM_VEGETABLES_NUMBER = 7
14+
const val RANDOM_FRESH_VEGETABLES_NUMBER = 3
1515

1616
val vegetables: MutableList<Vegetable> = mutableListOf()
1717

18-
// TODO: add tests
1918
private fun generateRandomVegetables() = buildList {
2019
addAll(List(RANDOM_VEGETABLES_NUMBER) { Vegetable(VegetableType.entries.random(), Random.nextBoolean()) })
2120
addAll(List(RANDOM_FRESH_VEGETABLES_NUMBER) { Vegetable(VegetableType.entries.random(), true) })
2221
}
2322

24-
// TODO: add tests
25-
// Task#0, student
2623
fun refill() {
2724
vegetables.clear()
2825
vegetables.addAll(generateRandomVegetables())
2926
}
3027

31-
// TODO: add tests
32-
// task#1, student
3328
override fun getVegetable(what: VegetableType): Vegetable {
3429
val vegetable = checkNotNull(vegetables.find { it.type == what && it.isFresh }) { "Fresh vegetable $what not found." }
3530
vegetables.remove(vegetable)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
type: edu
2+
custom_name: Master Chef - Add Spices
3+
files:
4+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/MasterChefApplication.kt
5+
visible: true
6+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameResource.kt
7+
visible: false
8+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameService.kt
9+
visible: false
10+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/food/IngredientType.kt
11+
visible: true
12+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/food/Ingredient.kt
13+
visible: true
14+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Fridge.kt
15+
visible: true
16+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Shelf.kt
17+
visible: true
18+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/Pot.kt
19+
visible: true
20+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Basket.kt
21+
visible: true
22+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/SaladBowl.kt
23+
visible: true
24+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/Blender.kt
25+
visible: true
26+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/storage/FridgeImpl.kt
27+
visible: true
28+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/storage/ShelfImpl.kt
29+
visible: true
30+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/PotImpl.kt
31+
visible: true
32+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/SaladBowlImpl.kt
33+
visible: true
34+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Resettable.kt
35+
visible: true
36+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/BlenderImpl.kt
37+
visible: true
38+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Kitchen.kt
39+
visible: true
40+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/KitchenImpl.kt
41+
visible: true
42+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameEnviroment.kt
43+
visible: true
44+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameActions.kt
45+
visible: true
46+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/TomatoSoup.kt
47+
visible: true
48+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/action/Action.kt
49+
visible: false
50+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/action/ActionType.kt
51+
visible: false
52+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/ItemType.kt
53+
visible: true
54+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/converters/ItemTypeConverter.kt
55+
visible: false
56+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Task.kt
57+
visible: false
58+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/Salad.kt
59+
visible: true
60+
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/Smoothie.kt
61+
visible: true
62+
- name: test/FridgeImplTestClass.kt
63+
visible: false
64+
propagatable: false
65+
- name: test/Tests.kt
66+
visible: false
67+
propagatable: false
68+
- name: test/TomatoSoupFunctions.kt
69+
visible: false
70+
propagatable: false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO: coding task, generateSpices and addSpices
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import org.jetbrains.academy.test.system.core.models.TestKotlinType
2+
import org.jetbrains.academy.test.system.core.models.Visibility
3+
import org.jetbrains.academy.test.system.core.models.classes.ClassType
4+
import org.jetbrains.academy.test.system.core.models.classes.TestClass
5+
import org.jetbrains.academy.test.system.core.models.method.TestMethod
6+
7+
internal val generateRandomVegetablesMethod = TestMethod(
8+
"generateRandomVegetables",
9+
TestKotlinType("List", params = listOf("org.jetbrains.kotlin.course.culinary.ingredient.Vegetable")),
10+
visibility = Visibility.PRIVATE,
11+
)
12+
13+
internal val refillMethod = TestMethod(
14+
"refill",
15+
TestKotlinType("Unit"),
16+
returnTypeJava = "void",
17+
)
18+
19+
internal val fridgeImplTestClass = TestClass(
20+
"FridgeImpl",
21+
"org.jetbrains.kotlin.course.culinary.implementation.storage",
22+
classType = ClassType.OBJECT,
23+
customMethods = listOf(
24+
generateRandomVegetablesMethod,
25+
refillMethod
26+
),
27+
)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import org.jetbrains.academy.test.system.core.findMethod
2+
import org.jetbrains.academy.test.system.core.invokeWithArgs
3+
import org.jetbrains.academy.test.system.core.invokeWithoutArgs
4+
import org.jetbrains.academy.test.system.core.models.classes.ConstructorGetter
5+
import org.jetbrains.kotlin.course.culinary.game.actions
6+
import org.jetbrains.kotlin.course.culinary.game.clearActions
7+
import org.jetbrains.kotlin.course.culinary.game.recipes.NUMBER_OF_TOMATOES
8+
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl
9+
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl.RANDOM_FRESH_VEGETABLES_NUMBER
10+
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl.RANDOM_VEGETABLES_NUMBER
11+
import org.jetbrains.kotlin.course.culinary.models.ItemType
12+
import org.jetbrains.kotlin.course.culinary.models.action.Action
13+
import org.jetbrains.kotlin.course.culinary.models.action.ActionType
14+
import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
15+
import org.jetbrains.kotlin.course.culinary.models.food.VegetableType
16+
import org.junit.jupiter.api.Test
17+
import java.lang.reflect.InvocationTargetException
18+
19+
class Test {
20+
// TODO: add tests for the current task
21+
22+
@Test
23+
fun getTomatoesForSoupMethodTest() {
24+
val clazz = tomatoSoupKtTestClass.checkBaseDefinition()
25+
val method = clazz.declaredMethods.findMethod(getTomatoesForSoupMethod)
26+
FridgeImpl.vegetables.addAll(generateTomatoesForSoup())
27+
28+
val vegetables: List<Vegetable> = try {
29+
method.invokeWithoutArgs(clazz = clazz) as List<Vegetable>
30+
} catch(e: InvocationTargetException) {
31+
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
32+
emptyList()
33+
}
34+
35+
assert(vegetables.all{ it.type == VegetableType.Tomato && it.isFresh }) { "Method ${method.name} should generate only fresh tomatoes" }
36+
assert(vegetables.size == NUMBER_OF_TOMATOES) { "Method ${method.name} should generate ${NUMBER_OF_TOMATOES} tomatoes, currently it generates ${vegetables.size} tomatoes" }
37+
}
38+
39+
@Test
40+
fun prepareTomatoesMethodTest() {
41+
clearActions()
42+
val clazz = tomatoSoupKtTestClass.checkBaseDefinition()
43+
val method = clazz.declaredMethods.findMethod(prepareTomatoesMethod)
44+
45+
try {
46+
method.invoke(clazz, generateTomatoesForSoup())
47+
} catch(e: InvocationTargetException) {
48+
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
49+
}
50+
51+
val expectedActions = buildList {
52+
addAll(List(NUMBER_OF_TOMATOES) { Action(ActionType.SHOW_ON_COUNTER, ItemType.FRESH_TOMATO) })
53+
repeat(NUMBER_OF_TOMATOES) {
54+
addAll(listOf(
55+
Action(ActionType.CUT_ON_COUNTER, ItemType.FRESH_TOMATO),
56+
Action(ActionType.SHOW_ON_COUNTER, ItemType.CUT_TOMATO)
57+
))
58+
}
59+
repeat(NUMBER_OF_TOMATOES) {
60+
addAll(listOf(
61+
Action(ActionType.REMOVE_FROM_COUNTER, ItemType.CUT_TOMATO),
62+
Action(ActionType.PUT_IN_POT, ItemType.CUT_TOMATO)
63+
))
64+
}
65+
}
66+
67+
assert(actions == expectedActions) { "The ${method.name} should cook a tomato soup in the following algorithm: put each tomato into the kitchen, then cut each tomato, then take each cut tomato and put each tomato into the pot." }
68+
}
69+
70+
private fun generateTomatoesForSoup() = List(NUMBER_OF_TOMATOES) { Vegetable(VegetableType.Tomato, true) }
71+
72+
@Test
73+
fun generateRandomVegetablesMethodTest() {
74+
val vegetables = generateRandomVegetables()
75+
val expectedNumOfVegetables = RANDOM_VEGETABLES_NUMBER + RANDOM_FRESH_VEGETABLES_NUMBER
76+
assert(vegetables.size == expectedNumOfVegetables) { "You need to generate $expectedNumOfVegetables vegetables" }
77+
assert(vegetables.toSet().size > 1) { "You need to generate different random vegetables!" }
78+
assert(vegetables.filter{ it.isFresh }.size >= RANDOM_FRESH_VEGETABLES_NUMBER) { "You need to generate at least $RANDOM_FRESH_VEGETABLES_NUMBER fresh vegetables" }
79+
}
80+
81+
private fun generateRandomVegetables(): List<Vegetable> {
82+
val clazz = fridgeImplTestClass.checkBaseDefinition()
83+
val method = clazz.declaredMethods.findMethod(generateRandomVegetablesMethod)
84+
val instance = clazz.fields.find { it.name == "INSTANCE" }?.get(null)
85+
86+
return try {
87+
fridgeImplTestClass.invokeMethodWithoutArgs(clazz, instance, method, true) as List<Vegetable>
88+
} catch(e: InvocationTargetException) {
89+
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
90+
emptyList()
91+
}
92+
}
93+
94+
@Test
95+
fun refillMethodTest() {
96+
val clazz = fridgeImplTestClass.checkBaseDefinition()
97+
val method = clazz.declaredMethods.findMethod(refillMethod)
98+
val instance = clazz.fields.find { it.name == "INSTANCE" }?.get(null)
99+
100+
val vegetablesNumInitial = FridgeImpl.vegetables.size
101+
FridgeImpl.vegetables.addAll(generateRandomVegetables())
102+
val vegetablesNumBeforeRefill = FridgeImpl.vegetables.size
103+
assert(vegetablesNumBeforeRefill - vegetablesNumInitial > 0) { "Method ${generateRandomVegetablesMethod.name} should generate random vegetables!" }
104+
105+
try {
106+
method.invoke(instance)
107+
} catch(e: InvocationTargetException) {
108+
assert(false) { "Can not invoke method ${method.name}. Please, add an implementation!" }
109+
}
110+
111+
val vegetablesNumAfterRefill = FridgeImpl.vegetables.size
112+
val expectedNumOfVegetables = RANDOM_VEGETABLES_NUMBER + RANDOM_FRESH_VEGETABLES_NUMBER
113+
assert(vegetablesNumAfterRefill == expectedNumOfVegetables) { "Method ${method.name} should add $expectedNumOfVegetables vegetables into the fridge!" }
114+
}
115+
}

0 commit comments

Comments
 (0)