Files
cs6601p2/test/net/woodyfolsom/cs6601/p2/RecipeBookReaderTest.java
Woody Folsom 90874ab065 Merge branch 'master' of woodyfolsom.net:/opt/git/cs6601p2
Conflicts:
	src/net/woodyfolsom/cs6601/p2/BayesChef.java
2012-03-12 15:59:35 -04:00

101 lines
4.0 KiB
Java

package net.woodyfolsom.cs6601.p2;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.*;
import java.io.File;
import net.woodyfolsom.cs6601.p2.Ingredient.TYPE;
import net.woodyfolsom.cs6601.p2.Recipe;
import net.woodyfolsom.cs6601.p2.RecipeBook;
import net.woodyfolsom.cs6601.p2.RecipeBookReader;
import org.junit.Test;
public class RecipeBookReaderTest {
@Test
public void testReadLongRecipeBook() {
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/long_recipebook.xml"));
assertNotNull(recipeBook);
assertThat(recipeBook.getSize(), is(equalTo(25)));
Recipe recipe = recipeBook.getRecipe(0);
assertThat(recipe.getHead().getTitle(), is(equalTo("Honey cake")));
assertTrue(recipe.getIngredients().contains(TYPE.EGGS));
assertTrue(recipe.getIngredients().contains(TYPE.GLUTEN));
assertTrue(recipe.getIngredients().contains(TYPE.SPICE));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POULTRY));
assertFalse(recipe.getIngredients().contains(TYPE.SHELLFISH));
for (int rIndex = 0; rIndex < recipeBook.getSize(); rIndex++) {
System.out.println(recipeBook.getRecipe(rIndex).getHead().getTitle());
}
}
@Test
public void testReadMediumRecipeBook() {
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/medium_recipebook.xml"));
assertNotNull(recipeBook);
assertThat(recipeBook.getSize(), is(equalTo(4)));
Recipe recipe = recipeBook.getRecipe(0);
System.out.println(recipe.getHead().getTitle());
assertThat(recipe.getHead().getTitle(), is(equalTo("Catalan Rice")));
assertFalse(recipe.getIngredients().contains(TYPE.EGGS));
assertFalse(recipe.getIngredients().contains(TYPE.GLUTEN));
assertTrue(recipe.getIngredients().contains(TYPE.SPICE));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POULTRY));
assertFalse(recipe.getIngredients().contains(TYPE.SHELLFISH));
for (int rIndex = 0; rIndex < recipeBook.getSize(); rIndex++) {
System.out.println(recipeBook.getRecipe(rIndex).getHead().getTitle());
}
}
@Test
public void testReadShortRecipeBook() {
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/short_recipebook.xml"));
assertNotNull(recipeBook);
assertThat(recipeBook.getSize(), is(equalTo(4)));
for (int i = 0; i < 4; i++) {
Recipe recipe = recipeBook.getRecipe(i);
System.out.println(i + ": " +recipe.getHead().getTitle());
}
Recipe recipe = recipeBook.getRecipe(0);
assertThat(recipe.getHead().getTitle(), is(equalTo("Catalan Rice")));
assertTrue(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(1);
assertThat(recipe.getHead().getTitle(), is(equalTo("Hamburger Steak")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertTrue(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertFalse(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(2);
assertThat(recipe.getHead().getTitle(), is(equalTo("Potatoes in a Thick Sauce")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertTrue(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
recipe = recipeBook.getRecipe(3);
assertThat(recipe.getHead().getTitle(), is(equalTo("Tomato-Zucchini Casserole")));
assertFalse(recipe.getIngredients().contains(TYPE.PORK));
assertFalse(recipe.getIngredients().contains(TYPE.BEEF));
assertFalse(recipe.getIngredients().contains(TYPE.POTATO));
assertTrue(recipe.getIngredients().contains(TYPE.TOMATO));
}
}