程序代写 package comp1110.exam;

package comp1110.exam;

import comp1110.exam.Q1MealPlan.Food;
import comp1110.exam.Q1MealPlan.Meal;

Copyright By PowCoder代写 加微信 powcoder

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

public class Q1MealPlanTest {
public Timeout globalTimeout = Timeout.millis(1000);

final static Food WAFFLES = new Food(“Waffles”, Meal.BREAKFAST);
final static Food APPLE_PIE = new Food(” “, Meal.DESSERT);
final static Food POTATO_GRATIN = new Food(“Potato Gratin”, Meal.DINNER);
final static Food SUSHI = new Food(“Sushi”, Meal.LUNCH);
final static Food FRIED_RICE = new Food(” “, Meal.LUNCH);
final static Food RISOTTO = new Food(“Risotto”, Meal.DINNER);
final static Food VEGETABLE_SOUP = new Food(“Vegetable Soup”, Meal.LUNCH);
final static Food MEUSLI = new Food(“Meusli”, Meal.BREAKFAST);
final static Food CAKE = new Food(“Cake”, Meal.DESSERT);
final static Food TARTE_TATIN = new Food(” “, Meal.DESSERT);

public void testTrivial() {
checkAllRotations(“”, 1); // no foods
checkAllRotations(“T”, 0); // no meals
checkAllRotations(“T”, 1, “T”); // one food, one meal
checkAllRotations(“T”, 2); // one food, multiple meals

public void testTwoMeals() {
checkAllRotations(“AS”, 2); // no valid succession order
checkAllRotations(“RC”, 2, “RC”);
checkAllRotations(“SP”, 2, “SP”);
checkAllRotations(“WT”, 2, “TW”);
checkAllRotations(“PF”, 2, “FP”);
checkAllRotations(“MV”, 2, “MV”);

public void testFourMeals() {
checkAllRotations(“SVPA”, 4); // only three meals
checkAllRotations(“CVPW”, 4, shuffleComplete(4, new String[]{“WVPC”}));
checkAllRotations(“RMFA”, 4, shuffleComplete(4, new String[]{“MFRA”}));
checkAllRotations(“STWP”, 4, shuffleComplete(4, new String[]{“WSPT”}));

public void testFiveMeals() {
checkAllRotations(“VPRAT”, 5); // only three meals
checkAllRotations(“SPWAT”, 5, “AWSPT”, “TWSPA”);
checkAllRotations(“FRPCM”, 5, “PCMFR”, “RCMFP”);
checkAllRotations(“RTVMW”, 5, “MVRTW”, “WVRTM”);
checkAllRotations(“SPAFW”, 5, “SPAWF”, “FPAWS”);

public void testTwoDays() {
checkAllRotations(“ATSVPRWM”, 8, shuffleComplete(8, new String[]{“PAWSRTMV”, “PAMSRTWV”, “MVRTWSPA”, “PAWVRTMS”, “VRAWSPTM”, “MSPTWVRA”, “TMSRAWVP”, “VPTWSRAM”}));
checkAllRotations(“TCVFRPWM”, 8, shuffleComplete(8, new String[]{“TWFPCMVR”, “MFPCWVRT”, “FPTMVRCW”, “TMFRCWVP”, “MFRTWVPC”, “CMFPTWVR”, “TWFRCMVP”, “FRTMVPCW”}));

private void checkAllRotations(String mealString, int numMeals, String… expectedRotations) {
Set foods = new HashSet<>();
foods.addAll(mealFromString(mealString));
Set> expected = rotationFromStrings(expectedRotations);
Set> result = Q1MealPlan.getAllMealPlans(foods, numMeals);

String expectedString;
if (expected.isEmpty()) {
expectedString = “empty set”;
StringBuilder sb = new StringBuilder();
for (List r : expected) {
sb.append(“- “).append(r).append(“\n”);
expectedString = sb.toString();

assertNotNull(“A null value was returned from Q1MealPlanning.getAllMealPlans(” + foods + “, ” + numMeals + “)\nexpected:\n” + expectedString, result);

String resultString;
if (result.isEmpty()) {
resultString = “empty set”;
StringBuilder sb2 = new StringBuilder();
for (List m : result) {
sb2.append(“- “).append(m).append(“\n”);
resultString = sb2.toString();

nextExpected:
for (List e : expected) {
for (List r : result) {
if (e.equals(r)) {
continue nextExpected;

fail(“An expected valid plan ” + e + ” \nwas not returned from Q1MealPlanning.getAllMealPlans(” + foods + “, ” + numMeals + “)\nexpected:\n” + expectedString + “but got:\n” + resultString);

nextResult:
for (List r : result) {
for (List e : expected) {
if (e.equals(r)) {
continue nextResult;

fail(“Unexpected plan ” + r + “\nwas returned from Q1MealPlanning.getAllMealPlans(” + foods + “, ” + numMeals + “)\nexpected:\n” + expectedString);

private List mealFromString(String m) {
List result = new ArrayList<>();
int i = 0;
for (char c : m.toCharArray()) {
switch (c) {
result.add(APPLE_PIE);
result.add(CAKE);
result.add(FRIED_RICE);
result.add(MEUSLI);
result.add(POTATO_GRATIN);
result.add(RISOTTO);
result.add(SUSHI);
result.add(TARTE_TATIN);
result.add(VEGETABLE_SOUP);
result.add(WAFFLES);
throw new IllegalArgumentException(“Unknown meal character: ” + c);
return result;

private Set> rotationFromStrings(String… rotations) {
Set> result = new HashSet<>();

int i = 0;
for (String s : rotations) {
result.add(mealFromString(s));
return result;

private String[] shuffleComplete(int numMeals, String[] source) {
String[] result = new String[source.length * numMeals];
int i = 0;
for (String s : source) {
for (int j = 0; j < s.length(); j++) { result[i++] = s.substring(j) + s.substring(0, j); return result; 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com