diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index e51b03e6ce0..a83a5e66927 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -313,30 +313,37 @@ Shows the calendar filled with all deadlines in the month. The calendar will be `calendar` //end::deadline[] +//@@author keiteo +=== Test mode: `start` +==== Start command: `start [category]` +This command starts the flashcard test mode. If no parameter is supplied, the application will test all +available FlashCards. +E.g. `start` -=== Test mode +image::StartEmptyParam.png[width="600"] -==== Start command -This command starts the flashcard test mode. +If tag(s) are entered, this command starts the FlashCard test from any specific category. Only relevant FlashCards from the tag(s) will +be tested. -`start` +E.g. `start [category]` -Starts the flashcard test from any specific category -`start [category]` +image::StartWithTagParam.png[width="600"] -==== See flashcard answer +==== See flashcard answer: `ans` This command allows you to check the answer of the flashcard question. -`ans` - -==== Rate flashcard +==== Rate flashcard: `rate [easy/good/hard]` This command rates the flashcard, depending on how well you answered the question i.e. easy, good, hard. `rate [rating]`, e.g. `rate hard` -==== End test +==== Skip question: `skip` +If you would like to manually filter and skip questions, the `skip` command helps you to skip FlashCards, +saving you extra time. + +==== End test: `end` You can stop the test any time simply by typing `end`. //@@author LeowWB diff --git a/docs/images/StartEmptyParam.png b/docs/images/StartEmptyParam.png new file mode 100644 index 00000000000..3c4de45816b Binary files /dev/null and b/docs/images/StartEmptyParam.png differ diff --git a/docs/images/StartWithTagParam.png b/docs/images/StartWithTagParam.png new file mode 100644 index 00000000000..679f9ffe0a1 Binary files /dev/null and b/docs/images/StartWithTagParam.png differ diff --git a/src/main/java/seedu/address/logic/commands/EndTestCommand.java b/src/main/java/seedu/address/logic/commands/EndTestCommand.java index 3b1afb6c41a..89fe09000bc 100644 --- a/src/main/java/seedu/address/logic/commands/EndTestCommand.java +++ b/src/main/java/seedu/address/logic/commands/EndTestCommand.java @@ -2,28 +2,39 @@ import static java.util.Objects.requireNonNull; +import java.util.logging.Level; +import java.util.logging.Logger; + import seedu.address.logic.parser.KeyboardFlashCardsParser; import seedu.address.model.Model; //@@author keiteo /** - * Ends the current flashcard test. + * Instantiates an EndTestcommand that allows users to end the current flashcard test. */ public class EndTestCommand extends Command { public static final String COMMAND_WORD = "end"; + private static Logger logger = Logger.getLogger("Foo"); private KeyboardFlashCardsParser keyboardFlashCardsParser; public EndTestCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) { requireNonNull(keyboardFlashCardsParser); + this.keyboardFlashCardsParser = keyboardFlashCardsParser; } @Override public CommandResult execute(Model model) { + requireNonNull(model); + model.updatePerformance(model); + logger.log(Level.INFO, "Updating performance"); + keyboardFlashCardsParser.endTestMode(); + logger.log(Level.INFO, "Enabling KeyboardFlashCardsParser to accept normal commands"); + CommandResult result = new CommandResult("Test ended"); result.setTestMode(false, true); return result; diff --git a/src/main/java/seedu/address/logic/commands/NextQuestionCommand.java b/src/main/java/seedu/address/logic/commands/NextQuestionCommand.java index 7978e6caf97..b3d29c80b96 100644 --- a/src/main/java/seedu/address/logic/commands/NextQuestionCommand.java +++ b/src/main/java/seedu/address/logic/commands/NextQuestionCommand.java @@ -2,17 +2,21 @@ import static java.util.Objects.requireNonNull; +import java.util.logging.Level; +import java.util.logging.Logger; + import seedu.address.logic.parser.KeyboardFlashCardsParser; import seedu.address.model.Model; //@@author keiteo /** - * Represents a NextQuestionCommand to skip questions. + * This class provides a skeletal implementation for commands that fetch the next FlashCard from the test model. */ abstract class NextQuestionCommand extends Command { - private static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!"; + public static final String MESSAGE_SUCCESS_END_OF_TEST = "End of test!"; + private static Logger logger = Logger.getLogger("Foo"); private final KeyboardFlashCardsParser keyboardFlashCardsParser; private final String messageSuccess; @@ -24,17 +28,25 @@ abstract class NextQuestionCommand extends Command { @Override public CommandResult execute(Model model) { requireNonNull(model); + if (!model.hasTestFlashCard()) { + logger.log(Level.INFO, "No more flashcards left to test!"); + keyboardFlashCardsParser.endTestMode(); + logger.log(Level.INFO, "Enabling KeyboardFlashCardsParser to accept normal commands"); + model.updatePerformance(model); + logger.log(Level.INFO, "Updating performance"); + CommandResult result = new CommandResult(MESSAGE_SUCCESS_END_OF_TEST); result.setTestMode(false, true); return result; } - //String nextQuestion = model.getTestQuestion(); model.setTestFlashCard(); keyboardFlashCardsParser.setAwaitingAnswer(true); + logger.log(Level.INFO, "Getting the next flashcard"); + return new CommandResult( messageSuccess, model.getTestFlashCardPanel()); diff --git a/src/main/java/seedu/address/logic/commands/RateQuestionCommand.java b/src/main/java/seedu/address/logic/commands/RateQuestionCommand.java index 1a5734085fb..3a818254d95 100644 --- a/src/main/java/seedu/address/logic/commands/RateQuestionCommand.java +++ b/src/main/java/seedu/address/logic/commands/RateQuestionCommand.java @@ -25,7 +25,9 @@ public class RateQuestionCommand extends NextQuestionCommand { public RateQuestionCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, Rating rating) { super(keyboardFlashCardsParser, MESSAGE_SUCCESS); + requireNonNull(rating); + this.keyboardFlashCardsParser = keyboardFlashCardsParser; this.rating = rating; } @@ -33,6 +35,7 @@ public RateQuestionCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, Ra @Override public CommandResult execute(Model model) { requireNonNull(model); + updateModelStatistics(model); updateFlashCardRating(model); return super.execute(model); @@ -50,28 +53,39 @@ public boolean equals(Object other) { /** Updates statistics in the model. */ private void updateModelStatistics(Model model) { assert model != null; + String rating = this.rating.toString(); assert rating.equals("good") || rating.equals("hard") || rating.equals("easy"); - if (rating.equals("good")) { + + switch (rating) { + case "good": model.editStats(0); - } else if (rating.equals("hard")) { + break; + case "hard": model.editStats(1); - } else { // rating.equals("easy") + break; + case "easy": model.editStats(2); + break; + default: + // should not reach this stage } } /** Updates the rating of a flashcard. */ private void updateFlashCardRating(Model model) { assert model != null; + FlashCard flashCardToUpdate = model.getCurrentTestFlashCard(); assert flashCardToUpdate != null; + model.setFlashCard(flashCardToUpdate, createUpdatedFlashCard(flashCardToUpdate)); } /** Creates a new immutable flashcard with the updated rating. */ private FlashCard createUpdatedFlashCard(FlashCard flashCardToUpdate) { assert flashCardToUpdate != null; + return new FlashCard(flashCardToUpdate.getQuestion(), flashCardToUpdate.getAnswer(), rating, flashCardToUpdate.getCategories()); diff --git a/src/main/java/seedu/address/logic/commands/ShowAnswerCommand.java b/src/main/java/seedu/address/logic/commands/ShowAnswerCommand.java index 128e3cecb3f..469be97a817 100644 --- a/src/main/java/seedu/address/logic/commands/ShowAnswerCommand.java +++ b/src/main/java/seedu/address/logic/commands/ShowAnswerCommand.java @@ -14,21 +14,24 @@ public class ShowAnswerCommand extends Command { public static final String COMMAND_WORD = "ans"; public static final String ERROR_MESSAGE = "Answer has already been displayed!\n" + "Next available command: rate, end"; + private static final String MESSAGE_SHOW_ANSWER_SUCCESS = "Answer displayed! " + + "Please rate the FlashCard easy/good/hard."; private final KeyboardFlashCardsParser keyboardFlashCardsParser; public ShowAnswerCommand(KeyboardFlashCardsParser keyboardFlashCardsParser) { requireNonNull(keyboardFlashCardsParser); + this.keyboardFlashCardsParser = keyboardFlashCardsParser; } @Override public CommandResult execute(Model model) { requireNonNull(model); - model.showAnswer(); + model.showAnswer(); keyboardFlashCardsParser.setAwaitingAnswer(false); - return new CommandResult("To be change: better feedback message"); + return new CommandResult(MESSAGE_SHOW_ANSWER_SUCCESS); } @Override diff --git a/src/main/java/seedu/address/logic/commands/StartCommand.java b/src/main/java/seedu/address/logic/commands/StartCommand.java index ba118385da8..033bd004535 100644 --- a/src/main/java/seedu/address/logic/commands/StartCommand.java +++ b/src/main/java/seedu/address/logic/commands/StartCommand.java @@ -5,6 +5,8 @@ import java.util.Arrays; import java.util.LinkedList; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import seedu.address.logic.parser.KeyboardFlashCardsParser; import seedu.address.model.Model; @@ -13,8 +15,9 @@ //@@author keiteo /** - * Starts the flashcard test by going through the cards in the specified deck. - * If no deck name is supplied, a random deck will be chosen. + * Instantiates a StartCommand to allow users to start the flashcard test + * by going through the cards in the specified tag(s). + * If no tags are supplied, all FlashCards will be used. */ public class StartCommand extends Command { @@ -22,12 +25,14 @@ public class StartCommand extends Command { public static final String MESSAGE_USAGE = COMMAND_WORD + ": Starts the FlashCard test by going through the cards in the specified deck.\n" - + "Parameters: DECK NAME. If no argument is supplied, a random deck will be chosen.\n" + + "Parameters: tag(s). If no argument is supplied, all FlashCards will be used.\n" + "Example: " + COMMAND_WORD + " physics"; - public static final String MESSAGE_NO_FLASHCARDS = "No FlashCard to test!"; + public static final String MESSAGE_NO_FLASHCARDS = "No FlashCards to test!"; - public static final String MESSAGE_START_TEST_SUCCESS = "Starting test...\n"; + private static final String MESSAGE_START_TEST_SUCCESS = "Starting test..."; + + private static Logger logger = Logger.getLogger("Foo"); private final KeyboardFlashCardsParser keyboardFlashCardsParser; @@ -37,25 +42,31 @@ public StartCommand(KeyboardFlashCardsParser keyboardFlashCardsParser, String ta requireNonNull(keyboardFlashCardsParser); this.keyboardFlashCardsParser = keyboardFlashCardsParser; this.tagName = tagName; + logger.log(Level.INFO, String.format("StartCommand created with the following tags: %s", tagName)); } @Override public CommandResult execute(Model model) { requireNonNull(model); + List testList = searchTag(model); model.initializeTestModel(testList); + if (!model.hasTestFlashCard()) { + logger.log(Level.WARNING, String.format("No flashcards found with the following tag(s):\n%s", tagName)); return new CommandResult(MESSAGE_NO_FLASHCARDS); } + keyboardFlashCardsParser.startTestMode(); model.setTestFlashCard(); - //String question = model.getTestQuestion(); keyboardFlashCardsParser.setAwaitingAnswer(true); + logger.log(Level.INFO, "Initialising test mode in ModelManager and KeyboardFlashCardParser"); CommandResult result = new CommandResult( MESSAGE_START_TEST_SUCCESS, model.getTestFlashCardPanel()); result.setTestMode(true, false); + return result; } @@ -71,12 +82,14 @@ public boolean equals(Object other) { /** Searches the list of flashcard to fetch the relevant tags. */ private List searchTag(Model model) { assert model != null; + if (tagName.isEmpty()) { return new LinkedList<>(model.getFlashCardList()); } + CategoryContainsAnyKeywordsPredicate predicate = getSearchTermPredicate(); - model.updateFilteredFlashCardList(predicate); - return new LinkedList<>(model.getFilteredFlashCardList()); + logger.log(Level.INFO, "Getting a list of flashcards to test"); + return new LinkedList<>(model.getFilteredFlashCardListNoCommit(predicate)); } /** Converts tagName to a CategoryContainsAnyKeywordsPredicate for searchTag(). */ diff --git a/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java b/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java index 6e4e91b03f3..41ae782ecad 100644 --- a/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java +++ b/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java @@ -4,6 +4,8 @@ import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_TEST_COMMAND; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -47,6 +49,8 @@ public class KeyboardFlashCardsParser { private static final Pattern BASIC_COMMAND_FORMAT = Pattern.compile("(?\\S+)(?.*)"); //@@author keiteo + private static Logger logger = Logger.getLogger("Foo"); + private boolean isRunningFlashcardTest = false; private boolean isAwaitingAnswer = false; @@ -71,20 +75,33 @@ public Command parseCommand(String userInput) throws ParseException { } //@@author keiteo + + /** + * Sets test mode to be true to disable parsing of non-test commands. + */ public void startTestMode() { isRunningFlashcardTest = true; } + /** + * Sets test mode to be false to enable parsing of non-test commands. + */ public void endTestMode() { isRunningFlashcardTest = false; } + /** + * Sets the answer status in test mode to further restrict inappropriate test commands. + * + * @param isAwaitingAnswer True if the program is waiting for user input to show answer, otherwise false. + */ public void setAwaitingAnswer(boolean isAwaitingAnswer) { this.isAwaitingAnswer = isAwaitingAnswer; } /** Parses test specific commands. */ private Command parseTestCommand(Matcher matcher) throws ParseException { + logger.log(Level.INFO, "Parsing test command"); final String commandWord = matcher.group("commandWord"); final String arguments = matcher.group("arguments"); switch (commandWord) { @@ -110,9 +127,10 @@ private Command parseTestCommand(Matcher matcher) throws ParseException { } } - //@@author + //@@author keiteo-reused /** Parses commands outside test mode i.e. list, add etc. */ private Command parseNormalCommand(Matcher matcher) throws ParseException { + logger.log(Level.INFO, "Parsing normal command"); final String commandWord = matcher.group("commandWord"); final String arguments = matcher.group("arguments"); switch (commandWord) { diff --git a/src/main/java/seedu/address/logic/parser/RateQuestionCommandParser.java b/src/main/java/seedu/address/logic/parser/RateQuestionCommandParser.java index 9cca38d35f7..abdf01cf011 100644 --- a/src/main/java/seedu/address/logic/parser/RateQuestionCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/RateQuestionCommandParser.java @@ -3,19 +3,23 @@ import static java.util.Objects.requireNonNull; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import java.util.logging.Level; +import java.util.logging.Logger; + import seedu.address.logic.commands.RateQuestionCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.flashcard.Rating; //@@author keiteo /** - * Parses input arguments and creates a new RateQuestionCommand object. + * This class parses input arguments and creates a new RateQuestionCommand object. */ public class RateQuestionCommandParser implements Parser { + private static Logger logger = Logger.getLogger("Foo"); private final KeyboardFlashCardsParser keyboardFlashCardsParser; - public RateQuestionCommandParser(KeyboardFlashCardsParser keyboardFlashCardsParser) { + RateQuestionCommandParser(KeyboardFlashCardsParser keyboardFlashCardsParser) { requireNonNull(keyboardFlashCardsParser); this.keyboardFlashCardsParser = keyboardFlashCardsParser; } @@ -25,15 +29,14 @@ public RateQuestionCommandParser(KeyboardFlashCardsParser keyboardFlashCardsPars * and returns a RateQuestionCommand object for execution. */ public RateQuestionCommand parse(String args) throws ParseException { - String getFirstWord = args.trim().split("\\s+")[0]; - - switch (getFirstWord) { - case Rating.EASY: - case Rating.GOOD: - case Rating.HARD: - return new RateQuestionCommand(keyboardFlashCardsParser, new Rating(getFirstWord)); - default: + String rating = args.trim().split("\\s+")[0]; + logger.log(Level.INFO, String.format("Parsing RateCommand with the following rating: %s", rating)); + if (!rating.equals(Rating.EASY) + && !rating.equals(Rating.GOOD) + && !rating.equals(Rating.HARD)) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, RateQuestionCommand.MESSAGE_USAGE)); } + + return new RateQuestionCommand(keyboardFlashCardsParser, new Rating(rating)); } } diff --git a/src/main/java/seedu/address/logic/parser/StartCommandParser.java b/src/main/java/seedu/address/logic/parser/StartCommandParser.java index c09c23a4e82..f45d8742d41 100644 --- a/src/main/java/seedu/address/logic/parser/StartCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/StartCommandParser.java @@ -3,13 +3,16 @@ import static java.util.Objects.requireNonNull; import seedu.address.logic.commands.StartCommand; +import seedu.address.logic.parser.exceptions.ParseException; //@@author keiteo /** - * Parses input arguments and creates a new StartCommand object. + * This class parses input arguments and creates a new StartCommand object. */ public class StartCommandParser implements Parser { + public static final String BAD_ARGUMENTS = "Please make sure your tags are alphanumeric!"; + private final KeyboardFlashCardsParser keyboardFlashCardsParser; StartCommandParser(KeyboardFlashCardsParser keyboardFlashCardsParser) { @@ -20,7 +23,12 @@ public class StartCommandParser implements Parser { * Parses the given {@code String} of arguments in the context of the StartCommand * and returns a StartCommand object for execution. */ - public StartCommand parse(String args) { + public StartCommand parse(String args) throws ParseException { + String alphaNumericWithSpacesRegex = "^[a-zA-Z0-9\\s+]+$"; + if (!args.matches(alphaNumericWithSpacesRegex) && !args.isEmpty()) { + throw new ParseException(BAD_ARGUMENTS); + } + String trimmedArgs = args.trim(); return new StartCommand(keyboardFlashCardsParser, trimmedArgs); } diff --git a/src/main/java/seedu/address/model/FlashCardTestModel.java b/src/main/java/seedu/address/model/FlashCardTestModel.java index 875d971a2f1..2c1f96eed7a 100644 --- a/src/main/java/seedu/address/model/FlashCardTestModel.java +++ b/src/main/java/seedu/address/model/FlashCardTestModel.java @@ -2,7 +2,6 @@ import static java.util.Objects.requireNonNull; -import java.util.LinkedList; import java.util.List; import seedu.address.model.flashcard.FlashCard; @@ -10,28 +9,31 @@ //@@author keiteo /** - * Creates a test model to contain relevant flashcards to test users. + * Instantiates a test model to contain relevant flashcards to test users. */ public class FlashCardTestModel { - private static FlashCard currentFlashCard; - + private FlashCard currentFlashCard; private List testList; - private List testListOld = new LinkedList<>(); // placeholder for previous function private TestFlashCardPanel testFlashCardPanel; public FlashCardTestModel(List testList) { this.testList = testList; } + /** + * Checks if the test list is empty. + */ public boolean isEmpty() { return testList.isEmpty(); } + /** + * Removes a FlashCard from the head of the test list and sets it as the current FlashCard. + */ public void setFlashcard() { assert !testList.isEmpty(); currentFlashCard = testList.remove(0); - testListOld.add(currentFlashCard); } //@@author shutingy @@ -42,6 +44,7 @@ private void setTestFlashCardPanel() { public TestFlashCardPanel getTestFlashCardPanel() { requireNonNull(currentFlashCard); + setTestFlashCardPanel(); return testFlashCardPanel; } @@ -55,17 +58,27 @@ public void showAnswer() { } //@@author keiteo + + /** + * Gets the question of the current FlashCard. + */ public String getQuestion() { requireNonNull(currentFlashCard); return currentFlashCard.getQuestion().toString(); } + /** + * Gets the answer of the current FlashCard. + */ public String getAnswer() { requireNonNull(currentFlashCard); return currentFlashCard.getAnswer().toString(); } - public static FlashCard getCurrentFlashCard() { + /** + * Gets the current FlashCard. + */ + FlashCard getCurrentFlashCard() { return currentFlashCard; } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 9b8aa50b99d..6f9c9239c69 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -155,19 +155,50 @@ public interface Model { void updateFilteredCategoryList(Predicate predicate); //@@author keiteo + + /** + * Returns an entire list of FlashCards in the system. + * @return An ObservableList of FlashCards + */ ObservableList getFlashCardList(); + + /** + * Initializes the test mode model with a list of FlashCards. + * + * @param testList List of FlashCards to be tested. + */ void initializeTestModel(List testList); + /** + * Checks if the list of FlashCards in the test model is fully expended. + * + * @return A boolean to indicate if the test model still has FlashCards. + */ boolean hasTestFlashCard(); + /** + * Sets the current FlashCard in the TestFlashCardPanel GUI. + */ void setTestFlashCard(); + /** + * Gets the test FlashCard question. + */ String getTestQuestion(); + /** + * Gets the test FlashCard answer. + */ String getTestAnswer(); + /** + * Gets the TestFlashCardPanel GUI class. + */ TestFlashCardPanel getTestFlashCardPanel(); + /** + * Gets the current FlashCard in test mode. + */ FlashCard getCurrentTestFlashCard(); //@@author shutingy diff --git a/src/test/java/seedu/address/logic/commands/RateQuestionCommandTest.java b/src/test/java/seedu/address/logic/commands/RateQuestionCommandTest.java new file mode 100644 index 00000000000..13ebaaf4e4c --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/RateQuestionCommandTest.java @@ -0,0 +1,55 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.parser.KeyboardFlashCardsParser; +import seedu.address.model.KeyboardFlashCards; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.flashcard.FlashCard; +import seedu.address.model.flashcard.Rating; +import seedu.address.model.flashcard.exceptions.FlashCardNotFoundException; +import seedu.address.testutil.FlashCardTestListBuilder; + +//@@author keiteo +public class RateQuestionCommandTest { + + private KeyboardFlashCardsParser keyboardFlashCardsParser = new KeyboardFlashCardsParser(); + + @Test + public void execute_flashCardDoesNotExist_exceptionThrown() { + String[] ratings = {"good", "hard", "easy"}; + for (String rate : ratings) { + Model model = initModel(new ModelManager()); + Command cmd = new RateQuestionCommand(keyboardFlashCardsParser, new Rating(rate)); + assertThrows(FlashCardNotFoundException.class, () -> cmd.execute(model)); + } + } + + @Test + public void execute_goodRatingFlashCardExists_success() { + KeyboardFlashCards keyboardFlashCards = new KeyboardFlashCards(); + FlashCard fc = new FlashCardTestListBuilder().buildOne().get(0); + keyboardFlashCards.addFlashcard(fc); + Model model = initModel(new ModelManager(keyboardFlashCards, new UserPrefs())); + try { + Command cmd = new RateQuestionCommand(keyboardFlashCardsParser, new Rating("good")); + CommandResult result = new CommandResult(NextQuestionCommand.MESSAGE_SUCCESS_END_OF_TEST); + assertEquals(result, cmd.execute(model)); + } catch (Exception e) { + fail(); + } + } + + /** Loads the model with a prebuilt list of test FlashCards. */ + private Model initModel(Model model) { + model.initializeTestModel(new FlashCardTestListBuilder().buildOne()); + model.setTestFlashCard(); + return model; + } +} diff --git a/src/test/java/seedu/address/testutil/FlashCardTestListBuilder.java b/src/test/java/seedu/address/testutil/FlashCardTestListBuilder.java index 829277e3426..1ee0c2d1eed 100644 --- a/src/test/java/seedu/address/testutil/FlashCardTestListBuilder.java +++ b/src/test/java/seedu/address/testutil/FlashCardTestListBuilder.java @@ -15,13 +15,14 @@ */ public class FlashCardTestListBuilder { - private List testList = new LinkedList<>(); + private List testList; private final String[] tagList = {"cs2100", "cs1101s", "cs2040"}; /** - * Returns an ArrayList containing 10000 simple flashcards. + * Returns an ArrayList containing 10000 simple FlashCards. */ public List build() { + testList = new LinkedList<>(); final int constant = 10; for (int i = 0; i < 10000; i++) { String question = i + " + " + constant; @@ -32,4 +33,14 @@ public List build() { } return testList; } + + /** + * Returns an ArrayList containing only 1 FlashCard. + */ + public List buildOne() { + testList = new LinkedList<>(); + testList.add(new FlashCard(new Question("1+1"), new Answer("2"), new Rating("good"), + SampleDataUtil.getCategorySet("test"))); + return testList; + } }