public function testFindRecipeFunction() { $fridge = $this->getFridge(); $idealRecipes = $this->getRecipesData(); $finder = new Finder($fridge); $result1 = $finder->findRecipe($idealRecipes); $this->assertEquals($result1, 'grilled cheese on toast'); $newRecipe2 = array('name' => 'extra cheese and peanut butter on bread', 'ingredients' => array(0 => array('item' => 'bread', 'amount' => '2', 'unit' => 'slices'), 1 => array('item' => 'cheese', 'amount' => '10', 'unit' => 'slices'), 2 => array('item' => 'peanut butter', 'amount' => '250', 'unit' => 'grams'))); $result2 = $finder->findRecipe(array_merge($idealRecipes, array($newRecipe2))); $this->assertEquals($result2, 'extra cheese and peanut butter on bread'); $newRecipe3 = array('name' => 'expired salad', 'ingredients' => array(0 => array('item' => 'mixed salad', 'amount' => '200', 'unit' => 'grams'))); $result3 = $finder->findRecipe(array($newRecipe3)); $this->assertEquals($result3, 'Order Takeout'); }
function main() { $fridge_csv_path = isset($argv[1]) ? $argv[1] : 'fridge.csv'; $recipe_json_path = isset($argv[2]) ? $argv[2] : 'recipes.js'; $ingredients = array_map('str_getcsv', file($fridge_csv_path)); $recipes = json_decode(file_get_contents($recipe_json_path), 1); $fridge = new Fridge(); $fridge->fillFromArray($ingredients); $finder = new Finder($fridge); $recipeToday = $finder->findRecipe($recipes); echo $recipeToday . "\n"; }