Skip to content

Commit

Permalink
#28 sending updated method via master as before discussed
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Nov 26, 2018
1 parent c0a4b56 commit 0a5d7f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
45 changes: 13 additions & 32 deletions src/main/java/verkocht/model/CookingBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public CookingBook() {


// Schnitzel
Recipe schniztelRec = new Recipe("schnitzel");
Recipe schniztelRec = new Recipe("schnitzel", Category.MEAT);
schniztelRec. getIngredients().put(getIngredientByName("Fleisch"),200);
schniztelRec. getIngredients().put(getIngredientByName("Ei"),1);
schniztelRec. getIngredients().put(getIngredientByName("Mehl"),100);
Expand All @@ -48,7 +48,7 @@ public CookingBook() {


// Erdbeermilchshake
Recipe milchshakeRec = new Recipe("milchshake");
Recipe milchshakeRec = new Recipe("milchshake", Category.VEGETARIAN);
milchshakeRec.getIngredients().put(getIngredientByName("Erdbeeren"),200);
milchshakeRec.getIngredients().put(getIngredientByName("Milch"),400);
milchshakeRec.getIngredients().put(getIngredientByName("Zucker"),20);
Expand All @@ -60,7 +60,7 @@ public CookingBook() {
allRecipes.add(milchshakeRec);

// Nudeln mit Tomatensauce
Recipe nudelnMitTomatensoßeRec = new Recipe("nudelnMitTomatensoße");
Recipe nudelnMitTomatensoßeRec = new Recipe("nudelnMitTomatensoße", Category.VEGAN);
nudelnMitTomatensoßeRec.getIngredients().put(getIngredientByName("Nudeln"),200);
nudelnMitTomatensoßeRec.getIngredients().put(getIngredientByName("Salz"),1);
nudelnMitTomatensoßeRec.getIngredients().put(getIngredientByName("Tomatensauce"),100);
Expand All @@ -85,37 +85,18 @@ public Recipe findByName(String name) {
}

/**
*
* This method filters all recipes by their category
* @param category
* @return
* @return list of filtered recipes
*/
public List<Recipe> findByCategory(Category category) {
List<Recipe> a = null;
switch (category) {
case MEAT:
for (int i = 0; i <= allRecipes.size(); i++) {
if(allRecipes.get(i).getCategory() == category.MEAT) {
a.add(allRecipes.get(i));
}
}
return a;
case VEGETARIAN:
for (int i = 0; i <= allRecipes.size(); i++) {
if(allRecipes.get(i).getCategory() == category.VEGETARIAN) {
a.add(allRecipes.get(i));
}
}
return a;
case VEGAN:
for (int i = 0; i <= allRecipes.size(); i++) {
if(allRecipes.get(i).getCategory() == category.VEGAN) {
a.add(allRecipes.get(i));
}
}
return a;
default:
throw new IllegalArgumentException("Unbekannte Kategorie: "+ category);
}
public List<Recipe> findByCategory(Category category) {
List<Recipe> a = new ArrayList<Recipe>();
for (int i = 0; i < allRecipes.size(); i++) {
if(allRecipes.get(i).getCategory() == category) {
a.add(allRecipes.get(i));
}
}
return a;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/verkocht/model/Recipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public class Recipe {
private Category category;
private Map<Ingredient, Integer> ingredientAmounts = new HashMap<Ingredient, Integer> ();


public Recipe(String name) {
this.name = name; }
public Recipe(String name, Category category) {
this.name = name;
this.category = category;
}

public Category getCategory() {
return category;
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/test/CookingBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;


import verkocht.model.CookingBook;
import verkocht.model.*;

public class CookingBookTest {
CookingBook cookingBook = new CookingBook();
Expand All @@ -31,6 +34,19 @@ public void testConstructor() {
assertEquals ("Zuerst wird wird das Mehl auf einen Teller gestreut.", cookingBook.findByName("schnitzel").getSteps().get(0));
assertEquals ("Alle Zutaten mit einem Mixer vermischen.", cookingBook.findByName("milchshake").getSteps().get(1));
assertEquals ("Die Nudeln abgießen und mit der Sauce heiß servieren.", cookingBook.findByName("nudelnMitTomatensoße").getSteps().get(2));

}

@Test
public void testFindByCategory() {
List<Recipe> b = new ArrayList<Recipe>();
b.add(cookingBook.getAllRecipes().get(0));
assertEquals(cookingBook.findByCategory(Category.MEAT),b);
b.clear();
b.add(cookingBook.getAllRecipes().get(1));
assertEquals(cookingBook.findByCategory(Category.VEGETARIAN),b);
b.clear();
b.add(cookingBook.getAllRecipes().get(2));
assertEquals(cookingBook.findByCategory(Category.VEGAN),b);
}

}

0 comments on commit 0a5d7f5

Please sign in to comment.