81 lines
3.2 KiB
Java
81 lines
3.2 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 testReadSurveyDataset() {
|
|
RecipeBook recipeBook = RecipeBookReader.readRecipeBook(new File("data/survey_recipes.xml"));
|
|
assertNotNull(recipeBook);
|
|
assertThat(recipeBook.getSize(), is(equalTo(22)));
|
|
|
|
Recipe recipe = recipeBook.getRecipe(0);
|
|
System.out.println(recipe.getHead().getTitle());
|
|
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 testReadShortSurveyDataset() {
|
|
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));
|
|
}
|
|
}
|