Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize project #78

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50,080 changes: 30,489 additions & 19,591 deletions culinaryFrontend/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.jetbrains.kotlin.course.culinary.models.action.Action
internal val actions: MutableList<Action> = ArrayList()

internal fun clearKitchen() {
FridgeImpl.refill()
PotImpl.reset()
SaladBowlImpl.reset()
BlenderImpl.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package org.jetbrains.kotlin.course.culinary.game

import org.jetbrains.kotlin.course.culinary.converters.toItemType
import org.jetbrains.kotlin.course.culinary.game.recipes.NUMBER_OF_TOMATOES
import org.jetbrains.kotlin.course.culinary.game.recipes.NUM_VEGETABLES_FOR_SALAD
import org.jetbrains.kotlin.course.culinary.implementation.storage.FridgeImpl
import org.jetbrains.kotlin.course.culinary.models.ItemType
import org.jetbrains.kotlin.course.culinary.models.Task
import org.jetbrains.kotlin.course.culinary.models.action.Action
import org.jetbrains.kotlin.course.culinary.models.food.VegetableType
import org.springframework.web.bind.annotation.*
Expand Down Expand Up @@ -49,6 +51,11 @@ class CookingFunction(val service: CookingService) {
@GetMapping("/salad-list")
fun cookSaladAsList(): List<Action> {
clearActions()
if (FridgeImpl.vegetables.count{ it.isFresh } < NUM_VEGETABLES_FOR_SALAD) {
// Show an error
return emptyList()
}

service.cookSaladAsList()
clearKitchen()
return actions
Expand All @@ -58,26 +65,26 @@ class CookingFunction(val service: CookingService) {
@GetMapping("/salad-sequence")
fun cookSaladAsSequence(): List<Action> {
clearActions()
if (FridgeImpl.vegetables.count{ it.isFresh } < NUM_VEGETABLES_FOR_SALAD) {
// Show an error
return emptyList()
}

service.cookSaladAsSequence()
clearKitchen()
return actions
}

@CrossOrigin
@GetMapping("/smoothie-list")
@GetMapping("/smoothie")
fun cookSmoothieAsList(): List<Action> {
clearActions()
service.cookSmoothieAsList()
service.cookSmoothie()
clearKitchen()
return actions
}

@CrossOrigin
@GetMapping("/smoothie-sequence")
fun cookSmoothieAsSequence(): List<Action> {
clearActions()
service.cookSmoothieAsSequence()
clearKitchen()
return actions
}
@GetMapping("/current-task")
fun getCurrentTask(): String = Task.SOUP.toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.jetbrains.kotlin.course.culinary.game

import org.jetbrains.kotlin.course.culinary.game.recipes.*
import org.jetbrains.kotlin.course.culinary.models.food.CutVegetable
import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
import org.springframework.stereotype.Service

@Service
class CookingService {
fun cookTomatoSoup() {
val tomatoes = getTomatoesForSoup()
prepareTomatoes(tomatoes)
pot.simmer()
}

fun cookWithSpices() {
val spices = generateSpices()
addSpices(spices)
pot.simmer()
}

fun cookSaladAsList() {
mixVegetablesForSalad(getFreshVegetables().cut())
}

fun cookSaladAsSequence() {
mixVegetablesForSalad(getFreshVegetables().asSequence().cut())
}

private fun Sequence<Vegetable>.cut(): List<CutVegetable> = map { kitchen.put(it) }
.map { kitchen.cut(it) }
.take(NUM_VEGETABLES_FOR_SALAD)
.map { kitchen.take(it) }
.toList()

fun cookSmoothie(){
getFruitsForSmoothie().cookSmoothie()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jetbrains.kotlin.course.culinary.game.recipes

import org.jetbrains.kotlin.course.culinary.models.food.CutVegetable
import org.jetbrains.kotlin.course.culinary.models.food.Vegetable

const val NUM_VEGETABLES_FOR_SALAD = 5

fun getFreshVegetables(): List<Vegetable> = TODO("Not implemented yet")

fun List<Vegetable>.cut(): List<CutVegetable> = TODO("Not implemented yet")

fun mixVegetablesForSalad(cutVegetables: List<CutVegetable>) {
TODO("Not implemented yet")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.jetbrains.kotlin.course.culinary.game.recipes

import org.jetbrains.kotlin.course.culinary.models.food.Fruit

fun getFruitsForSmoothie(): List<Fruit> = TODO("Not implemented yet")

fun List<Fruit>.cookSmoothie() {
TODO("Not implemented yet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,22 @@ import org.jetbrains.kotlin.course.culinary.models.food.Vegetable
import org.jetbrains.kotlin.course.culinary.models.food.VegetableType
import kotlin.random.Random

internal const val NUMBER_OF_TOMATOES = 3
const val NUMBER_OF_TOMATOES = 3

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

// TODO: add tests
// task#1
fun prepareTomatoes(tomatoes: List<Vegetable>) {
tomatoes
.onEach { kitchen.put(it) }
.map { kitchen.cut(it) }
.forEach { pot.put(kitchen.take(it)) }
}

fun cookSoup() {
pot.simmer()
}

// task#2
fun generateSpices(): Sequence<SpiceType> = generateSequence { SpiceType.entries.random() }

// task#2
fun addSpices(spices: Sequence<SpiceType>) {
val howMuchToAdd = Random.nextInt(1, 5)
val howMuchToAdd = Random.nextInt(1, 4)
spices
.map { shelf.getSpice(it) }
.map { pot.put(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ data object KitchenImpl : Kitchen {
require(vegetable in filling) { "Vegetable $vegetable is not on in the kitchen, so can't be cut" }
require(vegetable.isFresh) { "One can't cut rot vegetable $vegetable" }
filling -= vegetable
actions += buildAction(ActionType.CUT_ON_COUNTER, vegetable)
val cut = CutVegetable(vegetable.type)
filling += cut
actions += buildAction(ActionType.SHOW_ON_COUNTER, cut)
Expand All @@ -40,11 +41,6 @@ data object KitchenImpl : Kitchen {
require(basket in filling) { "Basket $basket is not on the kitchen, so can't be accessed" }
require(basket.left > 0) { "There are no fruits left in basket $basket" }
basket.left--

if (basket.left == 0) {
actions += buildAction(ActionType.REMOVE_FROM_COUNTER, basket)
}

return Fruit(basket.type)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,22 @@ data object PotImpl : Pot {
val filling: MutableList<Ingredient> = mutableListOf()
var simmering: Boolean = false

override fun doesTastePerfect(): Boolean = filling.filter{ it is Spice }
.groupingBy{ it }
.eachCount()
.filter{ (_, n) -> n > 2 }
.isEmpty()

override fun <T: Ingredient> put(ingredient: T) {
filling.add(ingredient)
actions.add(buildAction(ActionType.PUT_IN_POT, ingredient))
}

override fun put(vegetable: CutVegetable) {
filling.add(vegetable)
actions.add(buildAction(ActionType.PUT_IN_POT, vegetable))
}

private fun checkIfManySpices() = filling.filter{ it is Spice }
.groupingBy{ it }
.eachCount()
.filter{ (_, n) -> n > 2 }
.isNotEmpty()

private fun checkIfAllVegetablesFresh() = filling.filter{ it is Vegetable }.all{ (it as Vegetable).isFresh }

// task#2
override fun doesTastePerfect(): Boolean = checkIfManySpices() && checkIfAllVegetablesFresh()

override fun simmer() {
check(!simmering) { "You are already simmering" }
simmering = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ import org.jetbrains.kotlin.course.culinary.models.storage.Fridge
import kotlin.random.Random

data object FridgeImpl : Fridge {
private const val RANDOM_VEGETABLES_NUMBER = 7
private const val RANDOM_FRESH_VEGETABLES_NUMBER = 3
const val RANDOM_VEGETABLES_NUMBER = 7
const val RANDOM_FRESH_VEGETABLES_NUMBER = 3

val vegetables: MutableList<Vegetable> = generateRandomVegetables().toMutableList()
val vegetables: MutableList<Vegetable> = mutableListOf()

// TODO: add tests
private fun generateRandomVegetables() = buildList {
addAll(List(RANDOM_VEGETABLES_NUMBER) { Vegetable(VegetableType.entries.random(), Random.nextBoolean()) })
addAll(List(RANDOM_FRESH_VEGETABLES_NUMBER) { Vegetable(VegetableType.entries.random(), true) })
}

// TODO: add tests
// Task#0, student
fun refill() {
vegetables.clear()
vegetables.addAll(generateRandomVegetables())
}

// TODO: add tests
// task#1, student
override fun getVegetable(what: VegetableType): Vegetable {
val vegetable = checkNotNull(vegetables.find { it.type == what && it.isFresh }) { "Fresh vegetable $what not found." }
vegetables.remove(vegetable)
Expand All @@ -43,5 +38,5 @@ data object FridgeImpl : Fridge {
return allVegs
}

override fun getBasketOf(type: FruitType): Basket = Basket(type, Random.nextInt(1, 3))
override fun getBasketOf(type: FruitType): Basket = Basket(type, Random.nextInt(3, 5))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.jetbrains.kotlin.course.culinary.models

enum class Task {
SOUP,
SALAD,
SMOOTHIE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum class ActionType {
BLEND, // null
ADD_TO_BLENDER, // fruits
REMOVE_FROM_COUNTER, // baskets, fruits, vegetables
CUT_ON_COUNTER, // Cut a fruit or a vegetable
}
70 changes: 70 additions & 0 deletions culinaryServer/culinaryServerAddSpices/task-info.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
type: edu
custom_name: Master Chef - Add Spices
files:
- 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
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameService.kt
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/food/IngredientType.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/food/Ingredient.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Fridge.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Shelf.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/Pot.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/storage/Basket.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/SaladBowl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/cooking/Blender.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/storage/FridgeImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/storage/ShelfImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/PotImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/SaladBowlImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Resettable.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/cooking/BlenderImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Kitchen.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/implementation/KitchenImpl.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/GameEnviroment.kt
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
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/ItemType.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/converters/ItemTypeConverter.kt
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/models/Task.kt
visible: false
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/Salad.kt
visible: true
- name: src/main/kotlin/org/jetbrains/kotlin/course/culinary/game/recipes/Smoothie.kt
visible: true
- name: test/FridgeImplTestClass.kt
visible: false
propagatable: false
- name: test/Tests.kt
visible: false
propagatable: false
- name: test/TomatoSoupFunctions.kt
visible: false
propagatable: false
1 change: 1 addition & 0 deletions culinaryServer/culinaryServerAddSpices/task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: coding task, generateSpices and addSpices
27 changes: 27 additions & 0 deletions culinaryServer/culinaryServerAddSpices/test/FridgeImplTestClass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import org.jetbrains.academy.test.system.core.models.TestKotlinType
import org.jetbrains.academy.test.system.core.models.Visibility
import org.jetbrains.academy.test.system.core.models.classes.ClassType
import org.jetbrains.academy.test.system.core.models.classes.TestClass
import org.jetbrains.academy.test.system.core.models.method.TestMethod

internal val generateRandomVegetablesMethod = TestMethod(
"generateRandomVegetables",
TestKotlinType("List", params = listOf("org.jetbrains.kotlin.course.culinary.ingredient.Vegetable")),
visibility = Visibility.PRIVATE,
)

internal val refillMethod = TestMethod(
"refill",
TestKotlinType("Unit"),
returnTypeJava = "void",
)

internal val fridgeImplTestClass = TestClass(
"FridgeImpl",
"org.jetbrains.kotlin.course.culinary.implementation.storage",
classType = ClassType.OBJECT,
customMethods = listOf(
generateRandomVegetablesMethod,
refillMethod
),
)
Loading
Loading