From 5f46c4afdf60b951210a6f4a629c36ac19acc4e3 Mon Sep 17 00:00:00 2001 From: notweezer123 Date: Tue, 5 Dec 2023 21:20:11 -0800 Subject: [PATCH] Made Feature 16 File --- .../test/java/cse/gradle/Feature16Tests.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 app/src/test/java/cse/gradle/Feature16Tests.java diff --git a/app/src/test/java/cse/gradle/Feature16Tests.java b/app/src/test/java/cse/gradle/Feature16Tests.java new file mode 100644 index 0000000..b618e99 --- /dev/null +++ b/app/src/test/java/cse/gradle/Feature16Tests.java @@ -0,0 +1,118 @@ +// package cse.gradle; + +// import org.junit.jupiter.api.Disabled; +// import org.junit.jupiter.api.Test; +// import java.util.List; + +// import static org.junit.jupiter.api.Assertions.assertEquals; + +// import java.util.ArrayList; +// import java.util.Date; + +// public class Feature16Tests extends HTTPServerTests { + +// @Test +// public void sortByDateMethodTest() { +// // Create a new List with 3 recipes +// List recipes = new ArrayList(); + +// recipes.add(new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast", new Date(2023,3,4))); +// recipes.add(new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch")); +// recipes.add(new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes")); + +// Recipe.sortByDate(recipes, false); + +// // Check that the recipes are sorted alphabetically A-Z (not case sensitive) +// assert(recipes.get(0).getName().equals("American breakfast")); +// assert(recipes.get(1).getName().equals("boiled potatoes")); +// assert(recipes.get(2).getName().equals("Healthy Lunch")); + +// Recipe.sortByName(recipes, true); + +// // Check that the recipes are sorted alphabetically Z-A (not case sensitive) +// assert(recipes.get(0).getName().equals("Healthy Lunch")); +// assert(recipes.get(1).getName().equals("boiled potatoes")); +// assert(recipes.get(2).getName().equals("American breakfast")); +// } + +// @Test +// public void getRecipeListAToZTest() { + +// // Create a new List with 3 recipes +// List recipes = new ArrayList(); + +// recipes.add(new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast")); +// recipes.add(new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch")); +// recipes.add(new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes")); + + +// // Create a new Mock Model that accesses test_user in the database +// Model model = new MockModel(); + +// // Add the recipes to the database +// for (Recipe recipe : recipes) { +// model.postRecipe(recipe); +// } + +// // Get all the recipes from the database sorted alphabetically A-Z (not case sensitive) +// String getAllResponse = model.getRecipeList("a-z", ""); + +// // Delete the recipes from the database +// for (Recipe recipe : recipes) { +// model.deleteRecipe(recipe.getId().toString()); +// } + +// // Parse the getAllResponse into a List +// List recipeArrayList = Recipe.parseRecipeListFromString(getAllResponse); + +// System.out.println("recipeArrayList: " + recipeArrayList); + +// // Check that the recieved recipes are sorted alphabetically A-Z (not case sensitive) +// assertEquals(3, recipeArrayList.size()); +// assert(recipeArrayList.get(0).getName().equals("American breakfast")); +// // System.out.println(recipeArrayList.get(1).getName()); +// assert(recipeArrayList.get(1).getName().equals("boiled potatoes")); +// assert(recipeArrayList.get(2).getName().equals("Healthy Lunch")); +// } + +// @Test +// public void getRecipeListZToATest() { + +// // Create a new List with 3 recipes +// List recipes = new ArrayList(); + +// recipes.add(new Recipe("eggs, bacon", "cook for 10 minutes", "breakfast", "American breakfast")); +// recipes.add(new Recipe("salmon, salad", "cook for 20 minutes", "lunch", "Healthy Lunch")); +// recipes.add(new Recipe("potatoes", "boil the potatoes", "brunch", "boiled potatoes")); + + +// // Create a new Mock Model that accesses test_user in the database +// Model model = new MockModel(); + +// // Add the recipes to the database +// for (Recipe recipe : recipes) { +// model.postRecipe(recipe); +// } + +// // Get all the recipes from the database sorted alphabetically A-Z (not case sensitive) +// String getAllResponse = model.getRecipeList("z-a", ""); + +// // Delete the recipes from the database +// for (Recipe recipe : recipes) { +// model.deleteRecipe(recipe.getId().toString()); +// } + +// // Parse the getAllResponse into a List +// List recipeArrayList = Recipe.parseRecipeListFromString(getAllResponse); + +// System.out.println("recipeArrayList: " + recipeArrayList); + +// // Check that the recieved recipes are sorted alphabetically A-Z (not case sensitive) +// assertEquals(3, recipeArrayList.size()); +// assert(recipeArrayList.get(2).getName().equals("American breakfast")); +// // System.out.println(recipeArrayList.get(1).getName()); +// assert(recipeArrayList.get(1).getName().equals("boiled potatoes")); +// assert(recipeArrayList.get(0).getName().equals("Healthy Lunch")); + +// } +// } \ No newline at end of file