forked from XINLA9/COMP1110-Exam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ3GetMaxRecipesInCategoryTest.java
135 lines (111 loc) · 4.6 KB
/
Q3GetMaxRecipesInCategoryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package comp1110.exam;
import org.junit.Before;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* COMP1110 Exam, Question 3.2
*/
@TestMethodOrder(MethodOrderer.MethodName.class)
@org.junit.jupiter.api.Timeout(value = 500, unit = TimeUnit.MILLISECONDS)
public class Q3GetMaxRecipesInCategoryTest {
// FIXME add one or more JUnit tests for the getMaxRecipesInCategory() method of the Q3Recipes class
Q3Recipes recipes;
String[] quickRef = new String[]{
"Choc67",
"Praw82",
"Toff67",
"Tuna88",
"Duck66",
"Spag70",
};
String[] recipeNames = new String[]{
"Chocolate Fudge",
"Prawn Skewers",
"Toffee Apple",
"Tuna Mornay",
"Duck Salad",
"Spaghetti",
};
String[] categories = new String[]{
"Dessert",
"Entree",
"Dessert",
"Main",
"Entree",
"Main",
};
String[][] ingredients = new String[][]{
new String[]{"Sugar", "Chocolate"},
new String[]{"Seafood"},
new String[]{"Fruit", "Sugar"},
new String[]{"Seafood"},
new String[]{"Meat", "Fruit"},
new String[]{"Vegetable", "Meat", "Pasta"},
};
/**
* For example, if there are four ---recipes---- in this collection:
* * - "Fudg67" (category: Dessert) contains "Sugar", "Butter"
* * - "Praw77" (category: Entree) contains "Seafood"
* * - "Toff67" (category: Dessert) contains "Fruit" and "Sugar"
* * - "Tuna76" (category: Main) contains "Seafood"
* * then getMaxRecipesInCategory() == 2 (for the category "Dessert")
*/
@Before
public void setup() {
recipes = new Q3Recipes();
addInitialRecipes(false);
}
private void addInitialRecipes(boolean duplicate) {
for (int i = 0; i < quickRef.length; i++) {
assertNotEquals("Q3VariantRecipes.addRecipe expected to return " + !duplicate + (duplicate ? " when adding a duplicate recipe " : " adding a recipe for the first time"),
duplicate, recipes.addRecipe(quickRef[i], recipeNames[i], categories[i], Set.of(ingredients[i])));
}
}
private void addMoreRecipes1() {
recipes.addRecipe(quickRef[0],recipeNames[0],categories[0],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[1],recipeNames[1],categories[1],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[2],recipeNames[1],categories[2],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[3],recipeNames[1],categories[3],Set.of(ingredients[0]));
}
private void addMoreRecipes2() {
recipes.addRecipe(quickRef[0],recipeNames[0],categories[0],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[3],recipeNames[1],categories[2],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[1],recipeNames[1],categories[2],Set.of(ingredients[0]));
}
private void addMoreRecipes3() {
recipes.addRecipe(quickRef[0],recipeNames[0],categories[0],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[1],recipeNames[1],categories[0],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[2],recipeNames[1],categories[1],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[3],recipeNames[1],categories[1],Set.of(ingredients[0]));
recipes.addRecipe(quickRef[4],recipeNames[1],categories[0],Set.of(ingredients[0]));
}
@Test
public void test1Empty(){
Q3Recipes recipes = new Q3Recipes();
assertEquals("getMaxRecipesInCategory() expected to return ", 0, recipes.getMaxRecipesInCategory());
}
@Test
public void test2(){
Q3Recipes recipes = new Q3Recipes();
addMoreRecipes1();
assertEquals("getMaxRecipesInCategory() expected to return ", 1, recipes.getMaxRecipesInCategory());
}
@Test
public void test3(){
Q3Recipes recipes = new Q3Recipes();
addMoreRecipes2();
assertEquals("getMaxRecipesInCategory() expected to return ", 2, recipes.getMaxRecipesInCategory());
}
@Test
public void test4(){
Q3Recipes recipes = new Q3Recipes();
addMoreRecipes3();
assertEquals("getMaxRecipesInCategory() expected to return ", 3, recipes.getMaxRecipesInCategory());
}
}