diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 64a5be0291b..167dddd08b8 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -48,7 +48,7 @@ public class MainApp extends Application { @Override public void init() throws Exception { - logger.info("=============================[ Initializing AddressBook ]==========================="); + logger.info("=============================[ Initializing Revision Tool ]==========================="); super.init(); AppParameters appParameters = AppParameters.parse(getParameters()); diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index 476bc0d169e..b4c4ee15a39 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -4,7 +4,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY; import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -21,14 +20,12 @@ public class AddCommand extends Command { + "Parameters: " + PREFIX_QUESTION + "QUESTION " + PREFIX_DIFFICULTY + "DIFFICULTY " - + PREFIX_CATEGORY + "CATEGORY " - + "[" + PREFIX_TAG + "category]...\n" + + "[" + PREFIX_CATEGORY + "category]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_QUESTION + "Which of the following is a valid sequence diagram? " + PREFIX_DIFFICULTY + "3 " + PREFIX_CATEGORY + "UML " - + PREFIX_TAG + "UML " - + PREFIX_TAG + "graphical"; + + PREFIX_CATEGORY + "graphical"; public static final String MESSAGE_SUCCESS = "New question added: %1$s"; public static final String MESSAGE_DUPLICATE_ANSWERABLE = "This question already exists in the test bank"; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 76a010a0fb2..cff1c376ca5 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -4,7 +4,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY; import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_ANSWERABLE; import java.util.Collections; @@ -22,7 +21,6 @@ import seedu.address.model.answerable.Answerable; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Mcq; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.category.Category; @@ -40,7 +38,7 @@ public class EditCommand extends Command { + "[" + PREFIX_QUESTION + "QUESTION] " + "[" + PREFIX_DIFFICULTY + "DIFFICULTY] " + "[" + PREFIX_CATEGORY + "ADDRESS] " - + "[" + PREFIX_TAG + "category]...\n" + + "[" + PREFIX_CATEGORY + "category]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_DIFFICULTY + "91234567 "; @@ -92,14 +90,17 @@ private static Answerable createEditedAnswerable(Answerable answerableToEdit, Ed assert answerableToEdit != null; Question updatedQuestion = editAnswerableDescriptor.getQuestion().orElse(answerableToEdit.getQuestion()); - AnswerSet updatedAnswerSet = editAnswerableDescriptor.getAnswerSet().orElse(answerableToEdit.getAnswerSet()); - Difficulty updatedDifficulty = editAnswerableDescriptor.getDifficulty().orElse(answerableToEdit.getDifficulty()); - Set updatedCategories = editAnswerableDescriptor.getCategories().orElse(answerableToEdit.getCategories()); - - - AnswerSet mcqAnswer = (AnswerSet) updatedAnswerSet; - - return new Mcq(updatedQuestion, mcqAnswer, updatedDifficulty, updatedCategories); + Set updatedCorrectAnswerSet = editAnswerableDescriptor.getCorrectAnswerSet() + .orElse(answerableToEdit.getCorrectAnswerSet()); + Set updatedWrongAnswerSet = editAnswerableDescriptor.getWrongAnswerSet() + .orElse(answerableToEdit.getWrongAnswerSet()); + Difficulty updatedDifficulty = editAnswerableDescriptor.getDifficulty().orElse(answerableToEdit + .getDifficulty()); + Set updatedCategories = editAnswerableDescriptor.getCategories().orElse(answerableToEdit + .getCategories()); + + return new Mcq(updatedQuestion, updatedCorrectAnswerSet, updatedWrongAnswerSet, updatedDifficulty, + updatedCategories); } @Override @@ -126,12 +127,12 @@ public boolean equals(Object other) { */ public static class EditAnswerableDescriptor { private Question question; - private AnswerSet answerSet; + private Set correctAnswerSet; + private Set wrongAnswerSet; private Difficulty difficulty; private Set categories; public EditAnswerableDescriptor() { -// answerSet = new AnswerSet(); } /** @@ -140,7 +141,8 @@ public EditAnswerableDescriptor() { */ public EditAnswerableDescriptor(EditAnswerableDescriptor toCopy) { setQuestion(toCopy.question); - setAnswerSet(toCopy.answerSet); + setCorrectAnswerSet(toCopy.correctAnswerSet); + setWrongAnswerSet(toCopy.wrongAnswerSet); setDifficulty(toCopy.difficulty); setCategories(toCopy.categories); } @@ -149,7 +151,7 @@ public EditAnswerableDescriptor(EditAnswerableDescriptor toCopy) { * Returns true if at least one field is edited. */ public boolean isAnyFieldEdited() { - return CollectionUtil.isAnyNonNull(question, answerSet, difficulty, categories); + return CollectionUtil.isAnyNonNull(question, correctAnswerSet, wrongAnswerSet, difficulty, categories); } public void setQuestion(Question question) { @@ -160,30 +162,20 @@ public Optional getQuestion() { return Optional.ofNullable(question); } - public void setAnswerSet(AnswerSet answerSet) { - this.answerSet = answerSet; + public void setCorrectAnswerSet(Set correctAnswerSet) { + this.correctAnswerSet = correctAnswerSet; } - public void setCorrectAnswerSet(Set correctAnswerSet) { - if (answerSet == null) { - this.answerSet = new AnswerSet(); - this.answerSet.setCorrectAnswerSet(correctAnswerSet); - } else { - this.answerSet.setCorrectAnswerSet(correctAnswerSet); - } + public Optional> getCorrectAnswerSet() { + return Optional.ofNullable(correctAnswerSet); } public void setWrongAnswerSet(Set wrongAnswerSet) { - if (answerSet == null) { - this.answerSet = new AnswerSet(); - this.answerSet.setWrongAnswerSet(wrongAnswerSet); - } else { - this.answerSet.setWrongAnswerSet(wrongAnswerSet); - } + this.wrongAnswerSet = wrongAnswerSet; } - public Optional getAnswerSet() { - return Optional.ofNullable(answerSet); + public Optional> getWrongAnswerSet() { + return Optional.ofNullable(wrongAnswerSet); } public void setDifficulty(Difficulty difficulty) { @@ -224,7 +216,8 @@ public boolean equals(Object other) { EditAnswerableDescriptor e = (EditAnswerableDescriptor) other; return getQuestion().equals(e.getQuestion()) - && getAnswerSet().equals(e.getAnswerSet()) + && getCorrectAnswerSet().equals(e.getCorrectAnswerSet()) + && getWrongAnswerSet().equals(e.getWrongAnswerSet()) && getDifficulty().equals(e.getDifficulty()) && getCategories().equals(e.getCategories()); } diff --git a/src/main/java/seedu/address/logic/commands/ListCommand.java b/src/main/java/seedu/address/logic/commands/ListCommand.java index 74980d240ac..e3a3b75553e 100644 --- a/src/main/java/seedu/address/logic/commands/ListCommand.java +++ b/src/main/java/seedu/address/logic/commands/ListCommand.java @@ -32,17 +32,23 @@ public class ListCommand extends Command { + PREFIX_CATEGORY + "UML " + PREFIX_DIFFICULTY + "2 "; - public static final String MESSAGE_SUCCESS = "Listed all answerables"; - private final CategoryPredicate categoryPredicate; - private final DifficultyPredicate difficultyPredicate; + private CategoryPredicate categoryPredicate; + private DifficultyPredicate difficultyPredicate; public ListCommand(CategoryPredicate categoryPredicate, DifficultyPredicate difficultyPredicate) { this.categoryPredicate = categoryPredicate; this.difficultyPredicate = difficultyPredicate; } + public ListCommand(CategoryPredicate categoryPredicate) { + this.categoryPredicate = categoryPredicate; + } + + public ListCommand(DifficultyPredicate difficultyPredicate) { + this.difficultyPredicate = difficultyPredicate; + } @Override public CommandResult execute(Model model) { diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index b7c51428fe8..5d822a475b6 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -6,7 +6,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION_TYPE; import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_WRONG; import java.util.Set; @@ -18,7 +17,6 @@ import seedu.address.model.answerable.Answerable; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Mcq; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.category.Category; @@ -35,7 +33,7 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_QUESTION_TYPE, PREFIX_QUESTION, PREFIX_CORRECT, PREFIX_WRONG, - PREFIX_DIFFICULTY, PREFIX_CATEGORY, PREFIX_TAG); + PREFIX_DIFFICULTY, PREFIX_CATEGORY); if (!arePrefixesPresent(argMultimap, PREFIX_QUESTION, PREFIX_CORRECT, PREFIX_WRONG, PREFIX_CATEGORY, PREFIX_DIFFICULTY) || !argMultimap.getPreamble().isEmpty()) { @@ -47,19 +45,17 @@ public AddCommand parse(String args) throws ParseException { Set correctAnswerSet = ParserUtil.parseAnswers(argMultimap.getAllValues(PREFIX_CORRECT)); Set wrongAnswerSetSet = ParserUtil.parseAnswers(argMultimap.getAllValues(PREFIX_WRONG)); Difficulty difficulty = ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get()); - Set categoryList = ParserUtil.parseCategories(argMultimap.getAllValues(PREFIX_CATEGORY)); + Set categories = ParserUtil.parseCategories(argMultimap.getAllValues(PREFIX_CATEGORY)); Answerable answerable; switch (questionType.getType()) { case "mcq": - AnswerSet mcqAnswers = new AnswerSet(correctAnswerSet, wrongAnswerSetSet); - answerable = new Mcq(question, mcqAnswers, difficulty, categoryList); + answerable = new Mcq(question, correctAnswerSet, wrongAnswerSetSet, difficulty, categories); return new AddCommand(answerable); // case "saq": // //TODO: Implement Saq -// AnswerSet saqAnswers = new AnswerSet(); //stub -// answerable = new Saq(question, saqAnswers, difficulty, category, tagList); +// answerable = new Saq(question, correctAnsweSet, difficulty, category, tagList); // return new AddCommand(answerable); default: throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index e5b8004d1f9..23884535fcc 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -12,6 +12,5 @@ public class CliSyntax { public static final Prefix PREFIX_WRONG = new Prefix("x/"); public static final Prefix PREFIX_DIFFICULTY = new Prefix("diff/"); public static final Prefix PREFIX_CATEGORY = new Prefix("cat/"); - public static final Prefix PREFIX_TAG = new Prefix("t/"); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 6332eec05bf..517f1b5e671 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -57,7 +57,6 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_DIFFICULTY).isPresent()) { editAnswerableDescriptor.setDifficulty(ParserUtil.parseDifficulty(argMultimap.getValue(PREFIX_DIFFICULTY).get())); } - parseCategoriesForEdit(argMultimap.getAllValues(PREFIX_CATEGORY)).ifPresent(editAnswerableDescriptor::setCategories); @@ -79,8 +78,7 @@ private Optional> parseCategoriesForEdit(Collection catego if (categories.isEmpty()) { return Optional.empty(); } - Collection categorySet = categories.size() == 1 && categories.contains("") ? Collections.emptySet() : categories; - return Optional.of(ParserUtil.parseCategories(categorySet)); + return Optional.of(ParserUtil.parseCategories(categories)); } } diff --git a/src/main/java/seedu/address/model/answerable/AnswerSet.java b/src/main/java/seedu/address/model/answerable/AnswerSet.java deleted file mode 100644 index 9d115ff3ddc..00000000000 --- a/src/main/java/seedu/address/model/answerable/AnswerSet.java +++ /dev/null @@ -1,80 +0,0 @@ -package seedu.address.model.answerable; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class AnswerSet { - - //TODO: Might change to multiple response - public static final String MESSAGE_CONSTRAINTS = "MCQ answers should only be a, b, c or d"; - - public Set correctAnswerSet; - public Set wrongAnswerSet; - - /** - * Default Constructor for Answer. - */ - public AnswerSet() { - this.correctAnswerSet = new HashSet<>(); - this.wrongAnswerSet = new HashSet<>(); - } - - public AnswerSet(Set correctAnswerSet, Set wrongAnswerSet) { - this.correctAnswerSet = correctAnswerSet; - this.wrongAnswerSet = wrongAnswerSet; - } - - public boolean isCorrect(String answer) { - //TODO: Implement isCorrect method - return true; - } - - public Set getCorrectAnswerSet() { - return correctAnswerSet; - } - - public Set getWrongAnswerSet() { - return wrongAnswerSet; - } - - public void setCorrectAnswerSet(Set correctAnswerSet) { - this.correctAnswerSet = correctAnswerSet; - } - - public void setWrongAnswerSet(Set wrongAnswerSet) { - this.wrongAnswerSet = wrongAnswerSet; - } - - @Override - public String toString() { - return "Correct Answers: " + Arrays.toString(correctAnswerSet.toArray()) - + "Wrong Answers: " + Arrays.toString(wrongAnswerSet.toArray()); - } - - /** - * Returns true if both AnswerSets have the same correct and wrong answers - * This defines a stronger notion of equality between two AnswerSets. - */ - @Override - public boolean equals(Object other) { - if (other == this) { - return true; - } - - if (!(other instanceof AnswerSet)) { - return false; - } - - AnswerSet otherAnswerSet = (AnswerSet) other; - return otherAnswerSet.getCorrectAnswerSet().equals(getCorrectAnswerSet()) - && otherAnswerSet.getWrongAnswerSet().equals(getWrongAnswerSet()); - } - - @Override - public int hashCode() { - // use this method for custom fields hashing instead of implementing your own - return Objects.hash(correctAnswerSet, wrongAnswerSet); - } -} diff --git a/src/main/java/seedu/address/model/answerable/Answerable.java b/src/main/java/seedu/address/model/answerable/Answerable.java index db877ca1108..2e17fa0b2d4 100644 --- a/src/main/java/seedu/address/model/answerable/Answerable.java +++ b/src/main/java/seedu/address/model/answerable/Answerable.java @@ -2,6 +2,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Objects; @@ -18,17 +19,19 @@ public abstract class Answerable { private final Question question; private final Difficulty difficulty; - // Data fields - private final AnswerSet answerSet; + private final Set correctAnswerSet; + private final Set wrongAnswerSet; private final Set categories = new HashSet<>(); /** * Every field must be present and not null. */ - public Answerable(Question question, AnswerSet answerSet, Difficulty difficulty, Set categories) { + public Answerable(Question question, Set correctAnswerSet, Set wrongAnswerSet, + Difficulty difficulty, Set categories) { requireAllNonNull(question, difficulty, categories); this.question = question; - this.answerSet = answerSet; + this.correctAnswerSet = correctAnswerSet; + this.wrongAnswerSet = wrongAnswerSet; this.difficulty = difficulty; this.categories.addAll(categories); } @@ -37,8 +40,12 @@ public Question getQuestion() { return question; } - public AnswerSet getAnswerSet() { - return answerSet; + public Set getCorrectAnswerSet() { + return correctAnswerSet; + } + + public Set getWrongAnswerSet() { + return wrongAnswerSet; } public Difficulty getDifficulty() { @@ -61,7 +68,8 @@ public boolean isSameAnswerable(Answerable otherAnswerable) { return otherAnswerable != null && otherAnswerable.getQuestion().equals(getQuestion()) - && otherAnswerable.getAnswerSet().equals(getAnswerSet()) + && otherAnswerable.getCorrectAnswerSet().equals(getCorrectAnswerSet()) + && otherAnswerable.getWrongAnswerSet().equals(getWrongAnswerSet()) && otherAnswerable.getDifficulty().equals(getDifficulty()); } @@ -81,7 +89,8 @@ public boolean equals(Object other) { Answerable otherAnswerable = (Answerable) other; return otherAnswerable.getQuestion().equals(getQuestion()) - && otherAnswerable.getAnswerSet().equals(getAnswerSet()) + && otherAnswerable.getCorrectAnswerSet().equals(getCorrectAnswerSet()) + && otherAnswerable.getWrongAnswerSet().equals(getWrongAnswerSet()) && otherAnswerable.getDifficulty().equals(getDifficulty()) && otherAnswerable.getCategories().equals(getCategories()); } @@ -89,7 +98,7 @@ public boolean equals(Object other) { @Override public int hashCode() { // use this method for custom fields hashing instead of implementing your own - return Objects.hash(question, answerSet, difficulty, categories); + return Objects.hash(question, correctAnswerSet, wrongAnswerSet, difficulty, categories); } @Override @@ -98,7 +107,8 @@ public String toString() { builder.append("Question: ") .append(getQuestion()) .append(" Answers: ") - .append(getAnswerSet()) + .append("Correct Answers: " + getCorrectAnswerSet()) + .append("Wrong Answers: " + getWrongAnswerSet()) .append(" Difficulty: ") .append(getDifficulty()) .append(" Categories: "); diff --git a/src/main/java/seedu/address/model/answerable/Mcq.java b/src/main/java/seedu/address/model/answerable/Mcq.java index febcb58cecc..4e5c27e975c 100644 --- a/src/main/java/seedu/address/model/answerable/Mcq.java +++ b/src/main/java/seedu/address/model/answerable/Mcq.java @@ -15,7 +15,8 @@ public class Mcq extends Answerable { /** * Every field must be present and not null. */ - public Mcq(Question question, AnswerSet answer, Difficulty difficulty, Set categories) { - super(question, answer, difficulty, categories); + public Mcq(Question question, Set correctAnswerSet, Set wrongAnswerSet, + Difficulty difficulty, Set categories) { + super(question, correctAnswerSet, wrongAnswerSet, difficulty, categories); } } diff --git a/src/main/java/seedu/address/model/answerable/Saq.java b/src/main/java/seedu/address/model/answerable/Saq.java index 3a5ff990e0a..610521584a8 100644 --- a/src/main/java/seedu/address/model/answerable/Saq.java +++ b/src/main/java/seedu/address/model/answerable/Saq.java @@ -13,7 +13,8 @@ public class Saq extends Answerable { /** * Every field must be present and not null. */ - public Saq(Question question, AnswerSet answers, Difficulty difficulty, Set categories) { - super(question, answers, difficulty, categories); + public Saq(Question question, Set correctAnswerSet, Set wrongAnswerSet, Difficulty difficulty, + Set categories) { + super(question, correctAnswerSet, wrongAnswerSet, difficulty, categories); } } diff --git a/src/main/java/seedu/address/model/category/Category.java b/src/main/java/seedu/address/model/category/Category.java index 519fb28b33a..9029b26da28 100644 --- a/src/main/java/seedu/address/model/category/Category.java +++ b/src/main/java/seedu/address/model/category/Category.java @@ -9,8 +9,8 @@ */ public class Category { - public static final String MESSAGE_CONSTRAINTS = "Category names should be alphanumeric"; - public static final String VALIDATION_REGEX = "\\p{Alnum}+"; + public static final String MESSAGE_CONSTRAINTS = "Category names should not be blank"; + public static final String VALIDATION_REGEX = "^(?=\\s*\\S).*$"; public final String categoryName; diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 13121a937b9..6e992130169 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -11,7 +11,6 @@ import seedu.address.model.answerable.Answerable; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Mcq; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.category.Category; @@ -21,22 +20,25 @@ */ public class SampleDataUtil { public static Answerable[] getSampleAnswerables() { - AnswerSet defaultAnswerSet = new AnswerSet(new HashSet<>(), new HashSet<>()); + Answer defaultCorrectAnswer = new Answer("CORRECT"); + Set defaultCorrectAnswerSet = new HashSet<>(Arrays.asList(defaultCorrectAnswer)); + Answer defaultWrongAnswer = new Answer("WRONG"); + Set defaultWrongAnswerSet = new HashSet<>(Arrays.asList(defaultWrongAnswer)); //TODO: Implement actual answerable return new Answerable[] { - new Mcq(new Question("What is being shown?"), defaultAnswerSet, new Difficulty("3"), - getCategorySet("Math")), - new Mcq(new Question("Bernice Yu"), defaultAnswerSet, new Difficulty("99272758"), - getCategorySet("colleagues", "friends")), - new Mcq(new Question("Charlotte Oliveiro"), defaultAnswerSet, new Difficulty("93210283"), - getCategorySet("neighbours")), - new Mcq(new Question("David Li"), defaultAnswerSet, new Difficulty("91031282"), - getCategorySet("family")), - new Mcq(new Question("Irfan Ibrahim"), defaultAnswerSet, new Difficulty("92492021"), - getCategorySet("classmates")), - new Mcq(new Question("Roy Balakrishnan"), defaultAnswerSet, new Difficulty("92624417"), - getCategorySet("colleagues")) + new Mcq(new Question("What is being shown?"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("3"), getCategorySet("Math")), + new Mcq(new Question("Bernice Yu"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("99272758"), getCategorySet("colleagues", "friends")), + new Mcq(new Question("Charlotte Oliveiro"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("93210283"), getCategorySet("neighbours")), + new Mcq(new Question("David Li"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("91031282"), getCategorySet("family")), + new Mcq(new Question("Irfan Ibrahim"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("92492021"), getCategorySet("classmates")), + new Mcq(new Question("Roy Balakrishnan"), defaultCorrectAnswerSet, defaultWrongAnswerSet, + new Difficulty("92624417"), getCategorySet("colleagues")) }; } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAnswer.java b/src/main/java/seedu/address/storage/JsonAdaptedAnswer.java new file mode 100644 index 00000000000..a1039dacde5 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedAnswer.java @@ -0,0 +1,47 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.answerable.Answer; + +/** + * Jackson-friendly version of {@link Answer}. + */ +class JsonAdaptedAnswer { + + private final String answer; + + /** + * Constructs a {@code JsonAdaptedAnswer} with the given {@code answerDescription}. + */ + @JsonCreator + public JsonAdaptedAnswer(String answer) { + this.answer = answer; + } + + /** + * Converts a given {@code answer} into this class for Jackson use. + */ + public JsonAdaptedAnswer(Answer source) { + answer = source.answer; + } + + @JsonValue + public String getAnswer() { + return answer; + } + + /** + * Converts this Jackson-friendly adapted category object into the model's {@code category} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted category. + */ + public Answer toModelType() throws IllegalValueException { + if (!Answer.isValidAnswer(answer)) { + throw new IllegalValueException(Answer.MESSAGE_CONSTRAINTS); + } + return new Answer(answer); + } + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAnswerable.java b/src/main/java/seedu/address/storage/JsonAdaptedAnswerable.java index 7ed5795fab2..46a922b030d 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedAnswerable.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedAnswerable.java @@ -10,11 +10,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.answerable.Answer; import seedu.address.model.answerable.Answerable; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Mcq; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.category.Category; @@ -26,7 +26,8 @@ class JsonAdaptedAnswerable { public static final String MISSING_FIELD_MESSAGE_FORMAT = "Answerable's %s field is missing!"; private final String question; - private final AnswerSet answerSet; + private final List correctAnswerSet = new ArrayList<>(); + private final List wrongAnswerSet = new ArrayList<>(); private final String difficulty; private final List categories = new ArrayList<>(); @@ -34,11 +35,18 @@ class JsonAdaptedAnswerable { * Constructs a {@code JsonAdaptedAnswerable} with the given answerable details. */ @JsonCreator - public JsonAdaptedAnswerable(@JsonProperty("question") String question, @JsonProperty("answerSet") AnswerSet answerSet, - @JsonProperty("difficulty") String difficulty, - @JsonProperty("tagged") List categories) { + public JsonAdaptedAnswerable(@JsonProperty("question") String question, + @JsonProperty("correctAnswerSet") List correctAnswerSet, + @JsonProperty("wrongAnswerSet") List wrongAnswerSet, + @JsonProperty("difficulty") String difficulty, + @JsonProperty("categories") List categories) { this.question = question; - this.answerSet = answerSet; + if (correctAnswerSet != null) { + this.correctAnswerSet.addAll(correctAnswerSet); + } + if (wrongAnswerSet != null) { + this.wrongAnswerSet.addAll(wrongAnswerSet); + } this.difficulty = difficulty; if (categories != null) { this.categories.addAll(categories); @@ -51,7 +59,12 @@ public JsonAdaptedAnswerable(@JsonProperty("question") String question, @JsonPro public JsonAdaptedAnswerable(Answerable source) { question = source.getQuestion().fullQuestion; difficulty = source.getDifficulty().value; - answerSet = source.getAnswerSet(); + correctAnswerSet.addAll(source.getCorrectAnswerSet().stream() + .map(JsonAdaptedAnswer::new) + .collect(Collectors.toList())); + wrongAnswerSet.addAll(source.getWrongAnswerSet().stream() + .map(JsonAdaptedAnswer::new) + .collect(Collectors.toList())); categories.addAll(source.getCategories().stream() .map(JsonAdaptedCategory::new) .collect(Collectors.toList())); @@ -68,6 +81,16 @@ public Answerable toModelType() throws IllegalValueException { answerableTags.add(category.toModelType()); } + final List correctAnswers = new ArrayList<>(); + for (JsonAdaptedAnswer correctAnswer : correctAnswerSet) { + correctAnswers.add(correctAnswer.toModelType()); + } + + final List wrongAnswers = new ArrayList<>(); + for (JsonAdaptedAnswer wrongAnswer : wrongAnswerSet) { + wrongAnswers.add(wrongAnswer.toModelType()); + } + if (question == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Question.class.getSimpleName())); } @@ -76,11 +99,9 @@ public Answerable toModelType() throws IllegalValueException { } final Question modelQuestion = new Question(question); - //TODO: isValidAnswer always returns true - if (answerSet == null) { - throw new IllegalValueException(AnswerSet.MESSAGE_CONSTRAINTS); - } - final AnswerSet modelAnswer = answerSet; + final Set modelCorrectAnswerSet = new HashSet<>(correctAnswers); + + final Set modelWrongAnswerSet = new HashSet<>(wrongAnswers); if (difficulty == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Difficulty.class.getSimpleName())); @@ -93,6 +114,6 @@ public Answerable toModelType() throws IllegalValueException { final Set modelCategories = new HashSet<>(answerableTags); //TODO: Implement Answerable - return new Mcq(modelQuestion, modelAnswer, modelDifficulty, modelCategories); + return new Mcq(modelQuestion, modelCorrectAnswerSet, modelWrongAnswerSet, modelDifficulty, modelCategories); } } diff --git a/src/test/data/JsonAddressBookStorageTest/invalidAnswerableTestBank.json b/src/test/data/JsonAddressBookStorageTest/invalidAnswerableTestBank.json index f7d5c4d1c1d..e467b638395 100644 --- a/src/test/data/JsonAddressBookStorageTest/invalidAnswerableTestBank.json +++ b/src/test/data/JsonAddressBookStorageTest/invalidAnswerableTestBank.json @@ -9,6 +9,5 @@ { "answer": "WRONG" } ] }, "difficulty": "9482424", - "category": "4th street" } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicateAnswerableTestBank.json b/src/test/data/JsonSerializableAddressBookTest/duplicateAnswerableTestBank.json index 8dd7922354f..f68989f77e3 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicateAnswerableTestBank.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicateAnswerableTestBank.json @@ -1,26 +1,15 @@ { "answerables": [ { "question": "Alice Pauline", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty": "1", - "category": "123, Jurong West Ave 6, #08-111", - "tagged": [ "friends" ] + "categories": [ "friends" ] }, { "question": "Alice Pauline", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty": "1", - "category": "4th street" + "categories": [ "friends" ] } ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalAnswerableTestBank.json b/src/test/data/JsonSerializableAddressBookTest/typicalAnswerableTestBank.json index 7a5224cd7e3..a361691792d 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalAnswerableTestBank.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalAnswerableTestBank.json @@ -1,64 +1,34 @@ { "_comment": "Revision Tool save file which contains the same Answerable values as in TypicalAnswerables#getTypicalAddressBook()", "answerables" : [ { - "question" : "Is this a Question?", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "question" : "If a subclass imposes more restrictive conditions than its parent class, it violates Liskov Substitution Principle.", + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty" : "1", - "category" : "Category A", - "tagged" : [ "important" ] + "categories" : [ "LSP", "SOLID", "Week 9" ] }, { "question" : "Brownfield or Greenfield?", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, - "difficulty" : "2", - "category" : "Requirements", - "tagged" : [ "field", "introduction" ] + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], + "difficulty" : "1", + "categories" : [ "field", "introduction" ] }, { "question" : "Carl Kurz", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty" : "1", - "category" : "wall street", - "tagged" : [ ] + "categories" : [ "CATEGORY" ] }, { "question" : "Elle Meyer", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty" : "1", - "category" : "michegan ave", - "tagged" : [ ] + "categories" : [ "CATEGORY" ] }, { "question" : "Fiona Kunz", - "answerSet": { - "correctAnswerSet": [ - { "answer": "CORRECT" } - ], - "wrongAnswerSet": [ - { "answer": "WRONG" } - ] }, + "correctAnswerSet": [ "CORRECT" ], + "wrongAnswerSet": [ "WRONG" ], "difficulty" : "1", - "category" : "little tokyo", - "tagged" : [ ] + "categories" : [ "CATEGORY" ] } ] } diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 0c2fd82fd79..e18a7af9566 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -3,11 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_ANSWERABLE_DISPLAYED_INDEX; import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_AMY; +import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_UML; import static seedu.address.logic.commands.CommandTestUtil.CORRECT_ANSWER_DESC; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_ALPHA; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_MCQ; import static seedu.address.logic.commands.CommandTestUtil.WRONG_ANSWER_DESC; import static seedu.address.testutil.Assert.assertThrows; @@ -82,9 +81,9 @@ public void execute_storageThrowsIoException_throwsCommandException() { logic = new LogicManager(model, storage); // Execute add command - String addCommand = AddCommand.COMMAND_WORD + QUESTION_TYPE_MCQ + QUESTION_DESC_AMY + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC - + DIFFICULTY_DESC_AMY + CATEGORY_DESC_AMY; - Answerable expectedAnswerable = new AnswerableBuilder(ALPHA).withTags().build(); + String addCommand = AddCommand.COMMAND_WORD + QUESTION_TYPE_MCQ + QUESTION_DESC_AMY + CORRECT_ANSWER_DESC + + CATEGORY_DESC_UML + WRONG_ANSWER_DESC + DIFFICULTY_DESC_ALPHA; + Answerable expectedAnswerable = new AnswerableBuilder(ALPHA).withCategories("UML").build(); ModelManager expectedModel = new ModelManager(); expectedModel.addAnswerable(expectedAnswerable); String expectedMessage = LogicManager.FILE_OPS_ERROR_MESSAGE + DUMMY_IO_EXCEPTION; diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index db1b7b361ee..708bad99859 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -7,7 +7,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION_TYPE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_WRONG; import static seedu.address.testutil.Assert.assertThrows; @@ -22,7 +21,6 @@ import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.answerable.Answer; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.predicates.QuestionContainsKeywordsPredicate; import seedu.address.model.answerable.Answerable; import seedu.address.testutil.EditAnswerableDescriptorBuilder; @@ -32,53 +30,49 @@ */ public class CommandTestUtil { - public static final String VALID_QUESTION_AMY = "Amy Bee"; - public static final String VALID_QUESTION_BOB = "Bob Choo"; + public static final String VALID_QUESTION_ALPHA = "Amy Bee"; + public static final String VALID_QUESTION_BETA = "Bob Choo"; public static final String VALID_QUESTION_TYPE = "mcq"; - public static final String VALID_DIFFICULTY_AMY = "1"; - public static final String VALID_DIFFICULTY_BOB = "2"; - public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; - public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; - public static final String VALID_TAG_HUSBAND = "husband"; - public static final String VALID_TAG_FRIEND = "friend"; + public static final String VALID_DIFFICULTY_ALPHA = "1"; + public static final String VALID_DIFFICULTY_BETA = "3"; + public static final String VALID_CATEGORY_ALPHA = "Block 312, Amy Street 1"; + public static final String VALID_CATEGORY_BETA = "Block 123, Bobby Street 3"; + public static final String VALID_CATEGORY_GREENFIELD = "greenfield"; + public static final String VALID_CATEGORY_UML = "UML"; public static final String QUESTION_TYPE_MCQ = " " + PREFIX_QUESTION_TYPE + "mcq"; - public static final String QUESTION_DESC_AMY = " " + PREFIX_QUESTION + VALID_QUESTION_AMY; - public static final String QUESTION_DESC_BOB = " " + PREFIX_QUESTION + VALID_QUESTION_BOB; + public static final String QUESTION_DESC_AMY = " " + PREFIX_QUESTION + VALID_QUESTION_ALPHA; + public static final String QUESTION_DESC_BETA = " " + PREFIX_QUESTION + VALID_QUESTION_BETA; public static final String CORRECT_ANSWER_DESC = " " + PREFIX_CORRECT + "CORRECT"; public static final String WRONG_ANSWER_DESC = " " + PREFIX_WRONG + "WRONG"; public static final String QUESTION_TYPE_DESC = " " + PREFIX_QUESTION_TYPE + VALID_QUESTION_TYPE; - public static final String DIFFICULTY_DESC_AMY = " " + PREFIX_DIFFICULTY + VALID_DIFFICULTY_AMY; - public static final String DIFFICULTY_DESC_BOB = " " + PREFIX_DIFFICULTY + VALID_DIFFICULTY_BOB; - public static final String CATEGORY_DESC_AMY = " " + PREFIX_CATEGORY + VALID_ADDRESS_AMY; - public static final String CATEGORY_DESC_BOB = " " + PREFIX_CATEGORY + VALID_ADDRESS_BOB; - public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND; - public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND; - - public static final String INVALID_QUESTION_DESC = " " + PREFIX_QUESTION + " "; // empty string not allowed for questions + public static final String DIFFICULTY_DESC_ALPHA = " " + PREFIX_DIFFICULTY + VALID_DIFFICULTY_ALPHA; + public static final String DIFFICULTY_DESC_BETA = " " + PREFIX_DIFFICULTY + VALID_DIFFICULTY_BETA; + public static final String CATEGORY_DESC_UML = " " + PREFIX_CATEGORY + VALID_CATEGORY_UML; + public static final String CATEGORY_DESC_GREENFIELD = " " + PREFIX_CATEGORY + VALID_CATEGORY_GREENFIELD; + + public static final String INVALID_QUESTION_DESC = " " + PREFIX_QUESTION + ""; // empty string not allowed for questions public static final String INVALID_DIFFICULTY_DESC = " " + PREFIX_DIFFICULTY + "911a"; // 'a' not allowed in difficulty - public static final String INVALID_ADDRESS_DESC = " " + PREFIX_CATEGORY; // empty string not allowed for addresses - public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags + public static final String INVALID_CATEGORY_DESC = " " + PREFIX_CATEGORY + ""; // category cannot just be whitespace public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; - public static final EditCommand.EditAnswerableDescriptor DESC_AMY; - public static final EditCommand.EditAnswerableDescriptor DESC_BOB; + public static final EditCommand.EditAnswerableDescriptor DESC_ALPHA; + public static final EditCommand.EditAnswerableDescriptor DESC_BETA; private static final Answer correctAnswer = new Answer("CORRECT"); - private static final Set correctAnswerSet = new HashSet<>(Arrays.asList(correctAnswer)); + private static final Set defaultCorrectAnswerSet = new HashSet<>(Arrays.asList(correctAnswer)); private static final Answer wrongAnswer = new Answer("WRONG"); - private static final Set wrongAnswerSet = new HashSet<>(Arrays.asList(wrongAnswer)); - private static final AnswerSet defaultAnswerSet = new AnswerSet(correctAnswerSet, wrongAnswerSet); + private static final Set defaultWrongAnswerSet = new HashSet<>(Arrays.asList(wrongAnswer)); static { - DESC_AMY = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_AMY) - .withAnswerSet(defaultAnswerSet).withDifficulty(VALID_DIFFICULTY_AMY).withCategory(VALID_ADDRESS_AMY) - .withTags(VALID_TAG_FRIEND).build(); - DESC_BOB = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BOB) - .withAnswerSet(defaultAnswerSet).withDifficulty(VALID_DIFFICULTY_BOB).withCategory(VALID_ADDRESS_BOB) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + DESC_ALPHA = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_ALPHA) + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet) + .withDifficulty(VALID_DIFFICULTY_ALPHA).withCategories(VALID_CATEGORY_UML).build(); + DESC_BETA = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BETA) + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet) + .withDifficulty(VALID_DIFFICULTY_BETA).withCategories(VALID_CATEGORY_GREENFIELD, VALID_CATEGORY_UML).build(); } /** diff --git a/src/test/java/seedu/address/logic/commands/EditAnswerableDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditAnswerableDescriptorTest.java index cadf8490a4c..3212db538f5 100644 --- a/src/test/java/seedu/address/logic/commands/EditAnswerableDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditAnswerableDescriptorTest.java @@ -2,12 +2,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.DESC_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.DESC_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import org.junit.jupiter.api.Test; @@ -19,35 +18,31 @@ public class EditAnswerableDescriptorTest { @Test public void equals() { // same values -> returns true - EditCommand.EditAnswerableDescriptor descriptorWithSameValues = new EditAnswerableDescriptor(DESC_AMY); - assertTrue(DESC_AMY.equals(descriptorWithSameValues)); + EditCommand.EditAnswerableDescriptor descriptorWithSameValues = new EditAnswerableDescriptor(DESC_ALPHA); + assertTrue(DESC_ALPHA.equals(descriptorWithSameValues)); // same object -> returns true - assertTrue(DESC_AMY.equals(DESC_AMY)); + assertTrue(DESC_ALPHA.equals(DESC_ALPHA)); // null -> returns false - assertFalse(DESC_AMY.equals(null)); + assertFalse(DESC_ALPHA.equals(null)); // different types -> returns false - assertFalse(DESC_AMY.equals(5)); + assertFalse(DESC_ALPHA.equals(5)); // different values -> returns false - assertFalse(DESC_AMY.equals(DESC_BOB)); + assertFalse(DESC_ALPHA.equals(DESC_BETA)); // different name -> returns false - EditCommand.EditAnswerableDescriptor editedAmy = new EditAnswerableDescriptorBuilder(DESC_AMY).withQuestion(VALID_QUESTION_BOB).build(); - assertFalse(DESC_AMY.equals(editedAmy)); + EditCommand.EditAnswerableDescriptor editedAmy = new EditAnswerableDescriptorBuilder(DESC_ALPHA).withQuestion(VALID_QUESTION_BETA).build(); + assertFalse(DESC_ALPHA.equals(editedAmy)); // different difficulty -> returns false - editedAmy = new EditAnswerableDescriptorBuilder(DESC_AMY).withDifficulty(VALID_DIFFICULTY_BOB).build(); - assertFalse(DESC_AMY.equals(editedAmy)); + editedAmy = new EditAnswerableDescriptorBuilder(DESC_ALPHA).withDifficulty(VALID_DIFFICULTY_BETA).build(); + assertFalse(DESC_ALPHA.equals(editedAmy)); - // different address -> returns false - editedAmy = new EditAnswerableDescriptorBuilder(DESC_AMY).withCategory(VALID_ADDRESS_BOB).build(); - assertFalse(DESC_AMY.equals(editedAmy)); - - // different tags -> returns false - editedAmy = new EditAnswerableDescriptorBuilder(DESC_AMY).withTags(VALID_TAG_HUSBAND).build(); - assertFalse(DESC_AMY.equals(editedAmy)); + // different categories -> returns false + editedAmy = new EditAnswerableDescriptorBuilder(DESC_ALPHA).withCategories(VALID_CATEGORY_GREENFIELD).build(); + assertFalse(DESC_ALPHA.equals(editedAmy)); } } diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 66edbc28eca..86d7929be7d 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -2,11 +2,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.DESC_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.DESC_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showAnswerableAtIndex; @@ -54,11 +54,11 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { Answerable lastAnswerable = model.getFilteredAnswerableList().get(indexLastAnswerable.getZeroBased()); AnswerableBuilder answerableInList = new AnswerableBuilder(lastAnswerable); - Answerable editedAnswerable = answerableInList.withQuestion(VALID_QUESTION_BOB).withDifficulty(VALID_DIFFICULTY_BOB) - .withTags(VALID_TAG_HUSBAND).build(); + Answerable editedAnswerable = answerableInList.withQuestion(VALID_QUESTION_BETA).withDifficulty(VALID_DIFFICULTY_BETA) + .withCategories(VALID_CATEGORY_GREENFIELD).build(); - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BOB) - .withDifficulty(VALID_DIFFICULTY_BOB).withTags(VALID_TAG_HUSBAND).build(); + EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BETA) + .withDifficulty(VALID_DIFFICULTY_BETA).withCategories(VALID_CATEGORY_GREENFIELD).build(); EditCommand editCommand = new EditCommand(indexLastAnswerable, descriptor); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_ANSWERABLE_SUCCESS, editedAnswerable); @@ -86,9 +86,9 @@ public void execute_filteredList_success() { showAnswerableAtIndex(model, INDEX_FIRST_ANSWERABLE); Answerable answerableInFilteredList = model.getFilteredAnswerableList().get(INDEX_FIRST_ANSWERABLE.getZeroBased()); - Answerable editedAnswerable = new AnswerableBuilder(answerableInFilteredList).withQuestion(VALID_QUESTION_BOB).build(); + Answerable editedAnswerable = new AnswerableBuilder(answerableInFilteredList).withQuestion(VALID_QUESTION_BETA).build(); EditCommand editCommand = new EditCommand(INDEX_FIRST_ANSWERABLE, - new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BOB).build()); + new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BETA).build()); String expectedMessage = String.format(EditCommand.MESSAGE_EDIT_ANSWERABLE_SUCCESS, editedAnswerable); @@ -122,7 +122,7 @@ public void execute_duplicateAnswerableFilteredList_failure() { @Test public void execute_invalidAnswerableIndexUnfilteredList_failure() { Index outOfBoundIndex = Index.fromOneBased(model.getFilteredAnswerableList().size() + 1); - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BOB).build(); + EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BETA).build(); EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor); assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_ANSWERABLE_DISPLAYED_INDEX); @@ -140,17 +140,17 @@ public void execute_invalidAnswerableIndexFilteredList_failure() { assertTrue(outOfBoundIndex.getZeroBased() < model.getAddressBook().getAnswerableList().size()); EditCommand editCommand = new EditCommand(outOfBoundIndex, - new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BOB).build()); + new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_BETA).build()); assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_ANSWERABLE_DISPLAYED_INDEX); } @Test public void equals() { - final EditCommand standardCommand = new EditCommand(INDEX_FIRST_ANSWERABLE, DESC_AMY); + final EditCommand standardCommand = new EditCommand(INDEX_FIRST_ANSWERABLE, DESC_ALPHA); // same values -> returns true - EditAnswerableDescriptor copyDescriptor = new EditAnswerableDescriptor(DESC_AMY); + EditAnswerableDescriptor copyDescriptor = new EditAnswerableDescriptor(DESC_ALPHA); EditCommand commandWithSameValues = new EditCommand(INDEX_FIRST_ANSWERABLE, copyDescriptor); assertTrue(standardCommand.equals(commandWithSameValues)); @@ -164,10 +164,10 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different index -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_ANSWERABLE, DESC_AMY))); + assertFalse(standardCommand.equals(new EditCommand(INDEX_SECOND_ANSWERABLE, DESC_ALPHA))); // different descriptor -> returns false - assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_ANSWERABLE, DESC_BOB))); + assertFalse(standardCommand.equals(new EditCommand(INDEX_FIRST_ANSWERABLE, DESC_BETA))); } } diff --git a/src/test/java/seedu/address/logic/commands/ListCommandTest.java b/src/test/java/seedu/address/logic/commands/ListCommandTest.java index ff84ce9af2b..33fb4eb6546 100644 --- a/src/test/java/seedu/address/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListCommandTest.java @@ -11,6 +11,10 @@ import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.answerable.Difficulty; +import seedu.address.model.answerable.predicates.CategoryPredicate; +import seedu.address.model.answerable.predicates.DifficultyPredicate; +import seedu.address.model.category.Category; /** * Contains integration tests (interaction with the Model) and unit tests for ListCommand. @@ -19,6 +23,9 @@ public class ListCommandTest { private Model model; private Model expectedModel; + //TODO: Make into actual stub + private static CategoryPredicate CATEGORY_PREDICATE_STUB = new CategoryPredicate(new Category("CATEGORY")); + private static DifficultyPredicate DIFFICULTY_PREDICATE_STUB = new DifficultyPredicate(new Difficulty("1")); @BeforeEach public void setUp() { @@ -28,12 +35,12 @@ public void setUp() { @Test public void execute_listIsNotFiltered_showsSameList() { - assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel); + assertCommandSuccess(new ListCommand(CATEGORY_PREDICATE_STUB, DIFFICULTY_PREDICATE_STUB), model, ListCommand.MESSAGE_SUCCESS, expectedModel); } @Test public void execute_listIsFiltered_showsEverything() { showAnswerableAtIndex(model, INDEX_FIRST_ANSWERABLE); - assertCommandSuccess(new ListCommand(), model, ListCommand.MESSAGE_SUCCESS, expectedModel); + assertCommandSuccess(new ListCommand(CATEGORY_PREDICATE_STUB, DIFFICULTY_PREDICATE_STUB), model, ListCommand.MESSAGE_SUCCESS, expectedModel); } } diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 3d3caaebba0..fec34ada8a6 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -1,39 +1,31 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.CORRECT_ANSWER_DESC; -import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_QUESTION_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_DIFFICULTY_DESC; -import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.QUESTION_DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.QUESTION_DESC_BETA; +import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_BETA; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_WHITESPACE; -import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_DESC; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_MCQ; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_UML; +import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_GREENFIELD; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_UML; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.logic.commands.CommandTestUtil.WRONG_ANSWER_DESC; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; -import static seedu.address.testutil.TypicalAnswerables.ALPHA; import static seedu.address.testutil.TypicalAnswerables.BETA; import org.junit.jupiter.api.Test; import seedu.address.logic.commands.AddCommand; import seedu.address.model.answerable.Answerable; -import seedu.address.model.category.Category; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Question; import seedu.address.testutil.AnswerableBuilder; @@ -43,58 +35,49 @@ public class AddCommandParserTest { @Test public void parse_allFieldsPresent_success() { - Answerable expectedAnswerable = new AnswerableBuilder(BETA).withTags(VALID_TAG_FRIEND).build(); + Answerable expectedAnswerable = new AnswerableBuilder(BETA).withCategories(VALID_CATEGORY_UML).build(); // whitespace only preamble - assertParseSuccess(parser, PREAMBLE_WHITESPACE + QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_BOB + TAG_DESC_FRIEND, + String userInput = (PREAMBLE_WHITESPACE + QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_UML); + assertParseSuccess(parser, PREAMBLE_WHITESPACE + QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + + DIFFICULTY_DESC_BETA + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_UML, new AddCommand(expectedAnswerable)); // multiple names - last name accepted - assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_AMY + QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedAnswerable)); + assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_AMY + QUESTION_DESC_BETA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_UML, new AddCommand(expectedAnswerable)); // multiple difficulty - last difficulty accepted - assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + DIFFICULTY_DESC_AMY + DIFFICULTY_DESC_BOB - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedAnswerable)); + assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + DIFFICULTY_DESC_ALPHA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_UML, new AddCommand(expectedAnswerable)); // multiple addresses - last address accepted - assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB + CATEGORY_DESC_AMY - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_BOB + TAG_DESC_FRIEND, new AddCommand(expectedAnswerable)); + assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_UML, new AddCommand(expectedAnswerable)); // multiple tags - all accepted - Answerable expectedAnswerableMultipleTags = new AnswerableBuilder(BETA).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND) + Answerable expectedAnswerableMultipleTags = new AnswerableBuilder(BETA).withCategories(VALID_CATEGORY_UML, VALID_CATEGORY_GREENFIELD) .build(); - assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB + CATEGORY_DESC_BOB - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, new AddCommand(expectedAnswerableMultipleTags)); + assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_GREENFIELD + CATEGORY_DESC_UML, new AddCommand(expectedAnswerableMultipleTags)); } - @Test - public void parse_optionalFieldsMissing_success() { - // zero tags - Answerable expectedAnswerable = new AnswerableBuilder(ALPHA).withTags().build(); - assertParseSuccess(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_AMY + CORRECT_ANSWER_DESC + - WRONG_ANSWER_DESC + DIFFICULTY_DESC_AMY + CATEGORY_DESC_AMY, new AddCommand(expectedAnswerable)); - } @Test public void parse_compulsoryFieldMissing_failure() { String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE); // missing name prefix - assertParseFailure(parser, VALID_QUESTION_BOB + DIFFICULTY_DESC_BOB + CATEGORY_DESC_BOB, + assertParseFailure(parser, VALID_QUESTION_BETA + DIFFICULTY_DESC_BETA, expectedMessage); // missing difficulty prefix - assertParseFailure(parser, QUESTION_DESC_BOB + VALID_DIFFICULTY_BOB + CATEGORY_DESC_BOB, - expectedMessage); - - // missing address prefix - assertParseFailure(parser, QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB + VALID_ADDRESS_BOB, + assertParseFailure(parser, QUESTION_DESC_BETA + VALID_DIFFICULTY_BETA, expectedMessage); // all prefixes missing - assertParseFailure(parser, VALID_QUESTION_BOB + VALID_DIFFICULTY_BOB + VALID_ADDRESS_BOB, + assertParseFailure(parser, VALID_QUESTION_BETA + VALID_DIFFICULTY_BETA, expectedMessage); } @@ -102,23 +85,15 @@ public void parse_compulsoryFieldMissing_failure() { public void parse_invalidValue_failure() { // invalid name assertParseFailure(parser, QUESTION_TYPE_MCQ + INVALID_QUESTION_DESC + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC - + DIFFICULTY_DESC_BOB + CATEGORY_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Question.MESSAGE_CONSTRAINTS); + + DIFFICULTY_DESC_BETA + CATEGORY_DESC_GREENFIELD + CATEGORY_DESC_UML, Question.MESSAGE_CONSTRAINTS); // invalid difficulty - assertParseFailure(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC - + INVALID_DIFFICULTY_DESC + CATEGORY_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Difficulty.MESSAGE_CONSTRAINTS); - - // invalid address - assertParseFailure(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC - + DIFFICULTY_DESC_BOB + INVALID_ADDRESS_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Category.MESSAGE_CONSTRAINTS); - - // two invalid values, only first invalid value reported - assertParseFailure(parser, QUESTION_TYPE_MCQ + INVALID_QUESTION_DESC + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC - + DIFFICULTY_DESC_BOB + INVALID_ADDRESS_DESC, Question.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + + INVALID_DIFFICULTY_DESC + CATEGORY_DESC_GREENFIELD + CATEGORY_DESC_UML, Difficulty.MESSAGE_CONSTRAINTS); // non-empty preamble - assertParseFailure(parser, PREAMBLE_NON_EMPTY + QUESTION_TYPE_MCQ + QUESTION_DESC_BOB + DIFFICULTY_DESC_BOB - + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + assertParseFailure(parser, PREAMBLE_NON_EMPTY + QUESTION_TYPE_MCQ + QUESTION_DESC_BETA + DIFFICULTY_DESC_BETA + + CORRECT_ANSWER_DESC + WRONG_ANSWER_DESC + CATEGORY_DESC_GREENFIELD + CATEGORY_DESC_UML, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/address/logic/parser/ArgumentTokenizerTest.java b/src/test/java/seedu/address/logic/parser/ArgumentTokenizerTest.java index cfd7f9dfdc4..b672a16d1a9 100644 --- a/src/test/java/seedu/address/logic/parser/ArgumentTokenizerTest.java +++ b/src/test/java/seedu/address/logic/parser/ArgumentTokenizerTest.java @@ -55,7 +55,7 @@ private void assertArgumentAbsent(ArgumentMultimap argMultimap, Prefix prefix) { @Test public void tokenize_noPrefixes_allTakenAsPreamble() { - String argsString = " some random string /t tag with leading and trailing spaces "; + String argsString = " some random string /cat category with leading and trailing spaces "; ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(argsString); // Same string expected as preamble, but leading/trailing spaces should be trimmed diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 594ae6fc86d..4a1e4cf52c3 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -1,29 +1,24 @@ package seedu.address.logic.parser; import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.CORRECT_ANSWER_DESC; -import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_QUESTION_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_DIFFICULTY_DESC; -import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_CATEGORY_DESC; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_AMY; -import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_BOB; -import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_DESC; +import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.DIFFICULTY_DESC_BETA; import static seedu.address.logic.commands.CommandTestUtil.QUESTION_TYPE_MCQ; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_UML; +import static seedu.address.logic.commands.CommandTestUtil.CATEGORY_DESC_GREENFIELD; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_UML; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.logic.commands.CommandTestUtil.WRONG_ANSWER_DESC; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CATEGORY; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_ANSWERABLE; @@ -42,7 +37,7 @@ public class EditCommandParserTest { - private static final String TAG_EMPTY = " " + PREFIX_TAG; + private static final String CATEGORY_EMPTY = " " + PREFIX_CATEGORY; private static final String MESSAGE_INVALID_FORMAT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); @@ -52,7 +47,7 @@ public class EditCommandParserTest { @Test public void parse_missingParts_failure() { // no index specified - assertParseFailure(parser, VALID_QUESTION_AMY, MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, VALID_QUESTION_ALPHA, MESSAGE_INVALID_FORMAT); // no field specified assertParseFailure(parser, "1", EditCommand.MESSAGE_NOT_EDITED); @@ -80,36 +75,34 @@ public void parse_invalidPreamble_failure() { public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + INVALID_QUESTION_DESC, Question.MESSAGE_CONSTRAINTS); // invalid question assertParseFailure(parser, "1" + INVALID_DIFFICULTY_DESC, Difficulty.MESSAGE_CONSTRAINTS); // invalid difficulty - assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Category.MESSAGE_CONSTRAINTS); // invalid address - assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag + assertParseFailure(parser, "1" + INVALID_CATEGORY_DESC, Category.MESSAGE_CONSTRAINTS); // invalid category // invalid difficultty assertParseFailure(parser, "1" + INVALID_DIFFICULTY_DESC, Difficulty.MESSAGE_CONSTRAINTS); // valid difficulty followed by invalid difficulty. The test case for invalid difficulty followed by valid difficulty // is tested at {@code parse_invalidValueFollowedByValidValue_success()} - assertParseFailure(parser, "1" + DIFFICULTY_DESC_BOB + INVALID_DIFFICULTY_DESC, Difficulty.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + DIFFICULTY_DESC_BETA + INVALID_DIFFICULTY_DESC, Difficulty.MESSAGE_CONSTRAINTS); - // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Answerable} being edited, - // parsing it together with a valid tag results in error - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); + // while parsing {@code PREFIX_CATEGORY} alone will reset the categories of the {@code Answerable} being edited, + // parsing it together with a valid category results in error + assertParseFailure(parser, "1" + CATEGORY_DESC_UML + CATEGORY_DESC_GREENFIELD + CATEGORY_EMPTY, Category.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + CATEGORY_DESC_UML + CATEGORY_EMPTY + CATEGORY_DESC_GREENFIELD, Category.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, "1" + CATEGORY_EMPTY + CATEGORY_DESC_UML + CATEGORY_DESC_GREENFIELD, Category.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured assertParseFailure(parser, "1" + INVALID_QUESTION_DESC + QUESTION_TYPE_MCQ + CORRECT_ANSWER_DESC - + WRONG_ANSWER_DESC + VALID_ADDRESS_AMY + VALID_DIFFICULTY_AMY, Question.MESSAGE_CONSTRAINTS); + + WRONG_ANSWER_DESC + VALID_CATEGORY_ALPHA + VALID_DIFFICULTY_ALPHA, Question.MESSAGE_CONSTRAINTS); } @Test public void parse_allFieldsSpecified_success() { Index targetIndex = INDEX_SECOND_ANSWERABLE; - String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_BOB + TAG_DESC_HUSBAND - + CATEGORY_DESC_AMY + QUESTION_DESC_AMY + TAG_DESC_FRIEND; + String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_BETA + CATEGORY_DESC_GREENFIELD + + QUESTION_DESC_AMY + CATEGORY_DESC_UML; - EditCommand.EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_AMY) - .withDifficulty(VALID_DIFFICULTY_BOB).withCategory(VALID_ADDRESS_AMY) - .withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build(); + EditCommand.EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_ALPHA) + .withDifficulty(VALID_DIFFICULTY_BETA).withCategories(VALID_CATEGORY_GREENFIELD, VALID_CATEGORY_UML).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -118,9 +111,9 @@ public void parse_allFieldsSpecified_success() { @Test public void parse_someFieldsSpecified_success() { Index targetIndex = INDEX_FIRST_ANSWERABLE; - String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_BOB; + String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_BETA; - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BOB).build(); + EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BETA).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -131,25 +124,19 @@ public void parse_oneFieldSpecified_success() { // name Index targetIndex = INDEX_THIRD_ANSWERABLE; String userInput = targetIndex.getOneBased() + QUESTION_DESC_AMY; - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_AMY).build(); + EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withQuestion(VALID_QUESTION_ALPHA).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // difficulty - userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_AMY; - descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_AMY).build(); - expectedCommand = new EditCommand(targetIndex, descriptor); - assertParseSuccess(parser, userInput, expectedCommand); - - // address - userInput = targetIndex.getOneBased() + CATEGORY_DESC_AMY; - descriptor = new EditAnswerableDescriptorBuilder().withCategory(VALID_ADDRESS_AMY).build(); + userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_ALPHA; + descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_ALPHA).build(); expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // tags - userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND; - descriptor = new EditAnswerableDescriptorBuilder().withTags(VALID_TAG_FRIEND).build(); + userInput = targetIndex.getOneBased() + CATEGORY_DESC_UML; + descriptor = new EditAnswerableDescriptorBuilder().withCategories(VALID_CATEGORY_UML).build(); expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } @@ -157,12 +144,12 @@ public void parse_oneFieldSpecified_success() { @Test public void parse_multipleRepeatedFields_acceptsLast() { Index targetIndex = INDEX_FIRST_ANSWERABLE; - String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_AMY + CATEGORY_DESC_AMY - + TAG_DESC_FRIEND + DIFFICULTY_DESC_AMY + CATEGORY_DESC_AMY + TAG_DESC_FRIEND - + DIFFICULTY_DESC_BOB + CATEGORY_DESC_BOB + TAG_DESC_HUSBAND; + String userInput = targetIndex.getOneBased() + DIFFICULTY_DESC_ALPHA + CATEGORY_DESC_UML + + DIFFICULTY_DESC_ALPHA + CATEGORY_DESC_UML + DIFFICULTY_DESC_BETA + + CATEGORY_DESC_GREENFIELD; - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BOB) - .withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_FRIEND, VALID_TAG_HUSBAND).build(); + EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BETA) + .withCategories(VALID_CATEGORY_UML, VALID_CATEGORY_GREENFIELD).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -172,28 +159,16 @@ public void parse_multipleRepeatedFields_acceptsLast() { public void parse_invalidValueFollowedByValidValue_success() { // no other valid values specified Index targetIndex = INDEX_FIRST_ANSWERABLE; - String userInput = targetIndex.getOneBased() + INVALID_DIFFICULTY_DESC + DIFFICULTY_DESC_BOB; - EditCommand.EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BOB).build(); + String userInput = targetIndex.getOneBased() + INVALID_DIFFICULTY_DESC + DIFFICULTY_DESC_BETA; + EditCommand.EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BETA).build(); EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // other valid values specified - userInput = targetIndex.getOneBased() + INVALID_DIFFICULTY_DESC + CATEGORY_DESC_BOB - + DIFFICULTY_DESC_BOB; - descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BOB) - .withCategory(VALID_ADDRESS_BOB).build(); + userInput = targetIndex.getOneBased() + INVALID_DIFFICULTY_DESC + DIFFICULTY_DESC_BETA; + descriptor = new EditAnswerableDescriptorBuilder().withDifficulty(VALID_DIFFICULTY_BETA).build(); expectedCommand = new EditCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); } - @Test - public void parse_resetTags_success() { - Index targetIndex = INDEX_THIRD_ANSWERABLE; - String userInput = targetIndex.getOneBased() + TAG_EMPTY; - - EditAnswerableDescriptor descriptor = new EditAnswerableDescriptorBuilder().withTags().build(); - EditCommand expectedCommand = new EditCommand(targetIndex, descriptor); - - assertParseSuccess(parser, userInput, expectedCommand); - } } diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 7f85b808691..7458a76643f 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -21,12 +21,10 @@ public class ParserUtilTest { private static final String INVALID_QUESTION = ""; private static final String INVALID_DIFFICULTY = "+651234"; - private static final String INVALID_ADDRESS = " "; - private static final String INVALID_CATEGORY = " #UML"; + private static final String INVALID_CATEGORY = ""; private static final String VALID_QUESTION = "Rachel Walker"; private static final String VALID_DIFFICULTY = "1"; - private static final String VALID_ADDRESS = "123 Main Street #0505"; private static final String VALID_CATEGORY_1 = "OOP"; private static final String VALID_CATEGORY_2 = "git"; @@ -98,29 +96,6 @@ public void parseDifficulty_validValueWithWhitespace_returnsTrimmedDifficulty() assertEquals(expectedDifficulty, ParserUtil.parseDifficulty(difficultyWithWhitespace)); } - @Test - public void parseAddress_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> ParserUtil.parseCategory((String) null)); - } - - @Test - public void parseAddress_invalidValue_throwsParseException() { - assertThrows(ParseException.class, () -> ParserUtil.parseCategory(INVALID_ADDRESS)); - } - - @Test - public void parseAddress_validValueWithoutWhitespace_returnsAddress() throws Exception { - Category expectedCategory = new Category(VALID_ADDRESS); - assertEquals(expectedCategory, ParserUtil.parseCategory(VALID_ADDRESS)); - } - - @Test - public void parseAddress_validValueWithWhitespace_returnsTrimmedAddress() throws Exception { - String addressWithWhitespace = WHITESPACE + VALID_ADDRESS + WHITESPACE; - Category expectedCategory = new Category(VALID_ADDRESS); - assertEquals(expectedCategory, ParserUtil.parseCategory(addressWithWhitespace)); - } - @Test public void parseCategory_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> ParserUtil.parseCategory(null)); diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 5b0fab6a525..06433912e10 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -3,8 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalAnswerables.A_ANSWERABLE; import static seedu.address.testutil.TypicalAnswerables.getTypicalAddressBook; @@ -46,7 +45,7 @@ public void resetData_withValidReadOnlyAddressBook_replacesData() { @Test public void resetData_withDuplicateAnswerable_throwsDuplicateAnswerableException() { // Two answerables with the same identity fields - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD) .build(); List newAnswerables = Arrays.asList(A_ANSWERABLE, editedAlice); AddressBookStub newData = new AddressBookStub(newAnswerables); @@ -70,14 +69,6 @@ public void hasAnswerable_answerableInAddressBook_returnsTrue() { assertTrue(addressBook.hasAnswerable(A_ANSWERABLE)); } - @Test - public void hasAnswerable_answerableWithSameIdentityFieldsInAddressBook_returnsTrue() { - addressBook.addAnswerable(A_ANSWERABLE); - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) - .build(); - assertTrue(addressBook.hasAnswerable(editedAlice)); - } - @Test public void getAnswerableList_modifyList_throwsUnsupportedOperationException() { assertThrows(UnsupportedOperationException.class, () -> addressBook.getAnswerableList().remove(0)); diff --git a/src/test/java/seedu/address/model/answerable/AnswerableTest.java b/src/test/java/seedu/address/model/answerable/AnswerableTest.java index 024ef960952..044ba90523a 100644 --- a/src/test/java/seedu/address/model/answerable/AnswerableTest.java +++ b/src/test/java/seedu/address/model/answerable/AnswerableTest.java @@ -2,10 +2,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalAnswerables.A_ANSWERABLE; import static seedu.address.testutil.TypicalAnswerables.BETA; @@ -19,7 +18,7 @@ public class AnswerableTest { @Test public void asObservableList_modifyList_throwsUnsupportedOperationException() { Answerable answerable = new AnswerableBuilder().build(); - assertThrows(UnsupportedOperationException.class, () -> answerable.getTags().remove(0)); + assertThrows(UnsupportedOperationException.class, () -> answerable.getCategories().remove(0)); } @Test @@ -32,17 +31,16 @@ public void isSamePerson() { // different question -> returns false - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withDifficulty(VALID_DIFFICULTY_BOB).build(); - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withQuestion(VALID_QUESTION_BOB).build(); + Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withDifficulty(VALID_DIFFICULTY_BETA).build(); + editedAlice = new AnswerableBuilder(A_ANSWERABLE).withQuestion(VALID_QUESTION_BETA).build(); assertFalse(A_ANSWERABLE.isSameAnswerable(editedAlice)); // same question, same difficulty, different attributes -> returns true - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB) - .withTags(VALID_TAG_HUSBAND).build(); + editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD).build(); assertTrue(A_ANSWERABLE.isSameAnswerable(editedAlice)); // same question, same difficulty, different attributes -> returns true - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND).build(); + editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD).build(); assertTrue(A_ANSWERABLE.isSameAnswerable(editedAlice)); } @@ -65,19 +63,15 @@ public void equals() { assertFalse(A_ANSWERABLE.equals(BETA)); // different question -> returns false - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withQuestion(VALID_QUESTION_BOB).build(); + Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withQuestion(VALID_QUESTION_BETA).build(); assertFalse(A_ANSWERABLE.equals(editedAlice)); // different difficulty -> returns false - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withDifficulty(VALID_DIFFICULTY_BOB).build(); + editedAlice = new AnswerableBuilder(A_ANSWERABLE).withDifficulty(VALID_DIFFICULTY_BETA).build(); assertFalse(A_ANSWERABLE.equals(editedAlice)); - // different address -> returns false - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).build(); - assertFalse(A_ANSWERABLE.equals(editedAlice)); - - // different tags -> returns false - editedAlice = new AnswerableBuilder(A_ANSWERABLE).withTags(VALID_TAG_HUSBAND).build(); + // different categories -> returns false + editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD).build(); assertFalse(A_ANSWERABLE.equals(editedAlice)); } } diff --git a/src/test/java/seedu/address/model/answerable/CategoryTest.java b/src/test/java/seedu/address/model/answerable/CategoryTest.java deleted file mode 100644 index 30c29320157..00000000000 --- a/src/test/java/seedu/address/model/answerable/CategoryTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package seedu.address.model.answerable; - -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.testutil.Assert.assertThrows; - -import org.junit.jupiter.api.Test; - -public class CategoryTest { - - @Test - public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Category(null)); - } - - @Test - public void constructor_invalidAddress_throwsIllegalArgumentException() { - String invalidAddress = ""; - assertThrows(IllegalArgumentException.class, () -> new Category(invalidAddress)); - } - - @Test - public void isValidAddress() { - // null address - assertThrows(NullPointerException.class, () -> Category.isValidCategory(null)); - - // invalid addresses - assertFalse(Category.isValidCategory("")); // empty string - assertFalse(Category.isValidCategory(" ")); // spaces only - - // valid addresses - assertTrue(Category.isValidCategory("Blk 456, Den Road, #01-355")); - assertTrue(Category.isValidCategory("-")); // one character - assertTrue(Category.isValidCategory("Leng Inc; 1234 Market St; San Francisco CA 2349879; USA")); // long address - } -} diff --git a/src/test/java/seedu/address/model/answerable/QuestionContainsKeywordsPredicateTest.java b/src/test/java/seedu/address/model/answerable/QuestionContainsKeywordsPredicateTest.java index b735650daa4..7609942d19a 100644 --- a/src/test/java/seedu/address/model/answerable/QuestionContainsKeywordsPredicateTest.java +++ b/src/test/java/seedu/address/model/answerable/QuestionContainsKeywordsPredicateTest.java @@ -70,7 +70,6 @@ public void test_questionDoesNotContainKeywords_returnsFalse() { // Keywords match difficulty and address, but does not match name predicate = new QuestionContainsKeywordsPredicate(Arrays.asList("12345", "Main", "Street")); - assertFalse(predicate.test(new AnswerableBuilder().withQuestion("Alice").withDifficulty("1") - .withCategory("Main Street").build())); + assertFalse(predicate.test(new AnswerableBuilder().withQuestion("Alice").withDifficulty("1").build())); } } diff --git a/src/test/java/seedu/address/model/answerable/UniqueAnswerableListTest.java b/src/test/java/seedu/address/model/answerable/UniqueAnswerableListTest.java index ee7a0a784bb..de865a9fa9f 100644 --- a/src/test/java/seedu/address/model/answerable/UniqueAnswerableListTest.java +++ b/src/test/java/seedu/address/model/answerable/UniqueAnswerableListTest.java @@ -3,8 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalAnswerables.A_ANSWERABLE; import static seedu.address.testutil.TypicalAnswerables.BETA; @@ -42,7 +41,7 @@ public void contains_personInList_returnsTrue() { @Test public void contains_personWithSameIdentityFieldsInList_returnsTrue() { uniqueAnswerableList.add(A_ANSWERABLE); - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD) .build(); assertTrue(uniqueAnswerableList.contains(editedAlice)); } @@ -85,7 +84,7 @@ public void setAnswerable_editedAnswerableIsSameAnswerable_success() { @Test public void setAnswerable_editedAnswerableHasSameIdentity_success() { uniqueAnswerableList.add(A_ANSWERABLE); - Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND) + Answerable editedAlice = new AnswerableBuilder(A_ANSWERABLE).withCategories(VALID_CATEGORY_GREENFIELD) .build(); uniqueAnswerableList.setAnswerable(A_ANSWERABLE, editedAlice); UniqueAnswerableList expectedUniqueAnswerableList = new UniqueAnswerableList(); diff --git a/src/test/java/seedu/address/storage/JsonAdaptedAnswerableTest.java b/src/test/java/seedu/address/storage/JsonAdaptedAnswerableTest.java index 819794becbf..b8d1111e67a 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedAnswerableTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedAnswerableTest.java @@ -12,43 +12,45 @@ import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; -import seedu.address.model.answerable.AnswerSet; -import seedu.address.model.category.Category; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Question; public class JsonAdaptedAnswerableTest { private static final String INVALID_QUESTION = " "; private static final String INVALID_DIFFICULTY = "+651234"; - private static final String INVALID_CATEGORY = " "; - private static final String INVALID_TAG = "#friend"; + private static final String INVALID_CATEGORY = ""; private static final String VALID_QUESTION = B_ANSWERABLE.getQuestion().toString(); - //TODO: Remove Dependency - private static final AnswerSet VALID_ANSWER = B_ANSWERABLE.getAnswerSet(); + private static final List VALID_CORRECT_ANSWER = B_ANSWERABLE.getCorrectAnswerSet().stream() + .map(JsonAdaptedAnswer::new) + .collect(Collectors.toList()); + private static final List VALID_WRONG_ANSWER = B_ANSWERABLE.getWrongAnswerSet().stream() + .map(JsonAdaptedAnswer::new) + .collect(Collectors.toList()); private static final String VALID_DIFFICULTY = B_ANSWERABLE.getDifficulty().toString(); - private static final String VALID_CATEGORY = B_ANSWERABLE.getCategory().toString(); - private static final List VALID_TAGS = B_ANSWERABLE.getTags().stream() + private static final List VALID_CATEGORIES = B_ANSWERABLE.getCategories().stream() .map(JsonAdaptedCategory::new) .collect(Collectors.toList()); @Test public void toModelType_validPersonDetails_returnsPerson() throws Exception { - JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(B_ANSWERABLE); - assertEquals(B_ANSWERABLE, person.toModelType()); + JsonAdaptedAnswerable answerable = new JsonAdaptedAnswerable(B_ANSWERABLE); + assertEquals(B_ANSWERABLE, answerable.toModelType()); } @Test public void toModelType_invalidName_throwsIllegalValueException() { JsonAdaptedAnswerable person = - new JsonAdaptedAnswerable(INVALID_QUESTION, VALID_ANSWER, VALID_DIFFICULTY, VALID_CATEGORY, VALID_TAGS); + new JsonAdaptedAnswerable(INVALID_QUESTION, VALID_CORRECT_ANSWER, VALID_WRONG_ANSWER, VALID_DIFFICULTY, + VALID_CATEGORIES); String expectedMessage = Question.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullName_throwsIllegalValueException() { - JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(null, VALID_ANSWER, VALID_DIFFICULTY, VALID_CATEGORY, VALID_TAGS); + JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(null, VALID_CORRECT_ANSWER, VALID_WRONG_ANSWER, + VALID_DIFFICULTY, VALID_CATEGORIES); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Question.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -56,39 +58,24 @@ public void toModelType_nullName_throwsIllegalValueException() { @Test public void toModelType_invalidDifficulty_throwsIllegalValueException() { JsonAdaptedAnswerable person = - new JsonAdaptedAnswerable(VALID_QUESTION, VALID_ANSWER, INVALID_DIFFICULTY, VALID_CATEGORY, VALID_TAGS); + new JsonAdaptedAnswerable(VALID_QUESTION, VALID_CORRECT_ANSWER, VALID_WRONG_ANSWER, INVALID_DIFFICULTY, VALID_CATEGORIES); String expectedMessage = Difficulty.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @Test public void toModelType_nullDifficulty_throwsIllegalValueException() { - JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(VALID_QUESTION, VALID_ANSWER, null, VALID_CATEGORY, VALID_TAGS); + JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(VALID_QUESTION, VALID_CORRECT_ANSWER, VALID_WRONG_ANSWER, null, VALID_CATEGORIES); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Difficulty.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } - @Test - public void toModelType_invalidAddress_throwsIllegalValueException() { - JsonAdaptedAnswerable person = - new JsonAdaptedAnswerable(VALID_QUESTION, VALID_ANSWER, VALID_DIFFICULTY, INVALID_CATEGORY, VALID_TAGS); - String expectedMessage = Category.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - - @Test - public void toModelType_nullAddress_throwsIllegalValueException() { - JsonAdaptedAnswerable person = new JsonAdaptedAnswerable(VALID_QUESTION, VALID_ANSWER, VALID_DIFFICULTY, null, VALID_TAGS); - String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Category.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); - } - @Test public void toModelType_invalidTags_throwsIllegalValueException() { - List invalidTags = new ArrayList<>(VALID_TAGS); - invalidTags.add(new JsonAdaptedCategory(INVALID_TAG)); + List invalidCategories = new ArrayList<>(VALID_CATEGORIES); + invalidCategories.add(new JsonAdaptedCategory(INVALID_CATEGORY)); JsonAdaptedAnswerable person = - new JsonAdaptedAnswerable(VALID_QUESTION, VALID_ANSWER, VALID_DIFFICULTY, VALID_CATEGORY, invalidTags); + new JsonAdaptedAnswerable(VALID_QUESTION, VALID_CORRECT_ANSWER, VALID_WRONG_ANSWER, VALID_DIFFICULTY, invalidCategories); assertThrows(IllegalValueException.class, person::toModelType); } diff --git a/src/test/java/seedu/address/testutil/AnswerableBuilder.java b/src/test/java/seedu/address/testutil/AnswerableBuilder.java index 9ca7e166a62..fb0ca822847 100644 --- a/src/test/java/seedu/address/testutil/AnswerableBuilder.java +++ b/src/test/java/seedu/address/testutil/AnswerableBuilder.java @@ -9,7 +9,6 @@ import seedu.address.model.category.Category; import seedu.address.model.answerable.Difficulty; import seedu.address.model.answerable.Mcq; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.util.SampleDataUtil; @@ -18,27 +17,26 @@ */ public class AnswerableBuilder { - public static final String DEFAULT_QUESTION = "Greenfield projects are easier than greenfield projects"; + public static final String DEFAULT_QUESTION = "Greenfield projects are easier than brownfield projects"; public static final String DEFAULT_DIFFICULTY = "1"; - public static final String DEFAULT_CATEGORY = "brownfield"; - private static final Answer correctAnswer = new Answer("CORRECT"); - private static final Set correctAnswerSet = new HashSet<>(Arrays.asList(correctAnswer)); - private static final Answer wrongAnswer = new Answer("WRONG"); - private static final Set wrongAnswerSet = new HashSet<>(Arrays.asList(wrongAnswer)); - private static final AnswerSet defaultAnswerSet = new AnswerSet(correctAnswerSet, wrongAnswerSet); + public static final String DEFAULT_CATEGORY = "CATEGORY"; + private static final Answer defaultCorrectAnswer = new Answer("CORRECT"); + private static final Answer defaultWrongAnswer = new Answer("WRONG"); private Question question; - //TODO: Implement Answerable - private AnswerSet answer; + private Set correctAnswerSet; + private Set wrongAnswerSet; private Difficulty difficulty; private Set categories; public AnswerableBuilder() { question = new Question(DEFAULT_QUESTION); //TODO: Implement Answerable - answer = defaultAnswerSet; difficulty = new Difficulty(DEFAULT_DIFFICULTY); + correctAnswerSet = new HashSet<>(Arrays.asList(defaultCorrectAnswer)); + wrongAnswerSet = new HashSet<>(Arrays.asList(defaultWrongAnswer)); categories = new HashSet<>(); + categories.add(new Category(DEFAULT_CATEGORY)); } /** @@ -47,7 +45,8 @@ public AnswerableBuilder() { public AnswerableBuilder(Answerable answerableToCopy) { question = answerableToCopy.getQuestion(); //TODO: Implement Answerable - answer = answerableToCopy.getAnswerSet(); + correctAnswerSet = new HashSet<>(answerableToCopy.getCorrectAnswerSet()); + wrongAnswerSet = new HashSet<>(answerableToCopy.getWrongAnswerSet()); difficulty = answerableToCopy.getDifficulty(); categories = new HashSet<>(answerableToCopy.getCategories()); } @@ -61,27 +60,28 @@ public AnswerableBuilder withQuestion(String name) { } /** - * Sets the {@code Question} of the {@code Answerable} that we are building. + * Sets the Correct Answer Set of the {@code Answerable} that we are building. */ //TODO: Implement Answerable - public AnswerableBuilder withAnswerSet(AnswerSet answerSet) { - this.answer = answerSet; + public AnswerableBuilder withCorrectAnswerSet(Set correctAnswerSet) { + this.correctAnswerSet = correctAnswerSet; return this; } /** - * Parses the {@code tags} into a {@code Set} and set it to the {@code Answerable} that we are building. + * Sets the Wrong Answer Set of the {@code Answerable} that we are building. */ - public AnswerableBuilder withTags(String ... tags) { - this.categories = SampleDataUtil.getTagSet(tags); + //TODO: Implement Answerable + public AnswerableBuilder withWrongAnswerSet(Set wrongAnswerSet) { + this.wrongAnswerSet = wrongAnswerSet; return this; } /** - * Sets the {@code Category} of the {@code Answerable} that we are building. + * Parses the {@code categories} into a {@code Set} and set it to the {@code Answerable} that we are building. */ - public AnswerableBuilder withCategory(String address) { - this.category = new Category(address); + public AnswerableBuilder withCategories(String ... categories) { + this.categories = SampleDataUtil.getCategorySet(categories); return this; } @@ -95,7 +95,7 @@ public AnswerableBuilder withDifficulty(String difficulty) { public Answerable build() { //TODO: Implement Answerable - return new Mcq(question, answer, difficulty, categories); + return new Mcq(question, correctAnswerSet, wrongAnswerSet, difficulty, categories); } } diff --git a/src/test/java/seedu/address/testutil/AnswerableUtil.java b/src/test/java/seedu/address/testutil/AnswerableUtil.java index f8b237a786a..b396975086f 100644 --- a/src/test/java/seedu/address/testutil/AnswerableUtil.java +++ b/src/test/java/seedu/address/testutil/AnswerableUtil.java @@ -4,7 +4,7 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_CORRECT; import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION; import static seedu.address.logic.parser.CliSyntax.PREFIX_DIFFICULTY; -import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; +import static seedu.address.logic.parser.CliSyntax.PREFIX_QUESTION_TYPE; import static seedu.address.logic.parser.CliSyntax.PREFIX_WRONG; import java.util.Set; @@ -12,8 +12,8 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.EditCommand; import seedu.address.model.answerable.Answer; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Answerable; +import seedu.address.model.category.Category; /** * A utility class for Answerable. @@ -36,15 +36,14 @@ public static String getAnswerableDetails(Answerable answerable) { sb.append(PREFIX_QUESTION_TYPE + "mcq" + " "); sb.append(PREFIX_QUESTION + answerable.getQuestion().fullQuestion + " "); sb.append(PREFIX_DIFFICULTY + answerable.getDifficulty().value + " "); - sb.append(PREFIX_CATEGORY + answerable.getCategory().value + " "); - answerable.getAnswerSet().getCorrectAnswerSet().stream().forEach( + answerable.getCorrectAnswerSet().stream().forEach( s -> sb.append(PREFIX_CORRECT + s.answer + " ") ); - answerable.getAnswerSet().getWrongAnswerSet().stream().forEach( + answerable.getWrongAnswerSet().stream().forEach( s -> sb.append(PREFIX_WRONG + s.answer + " ") ); - answerable.getTags().stream().forEach( - s -> sb.append(PREFIX_TAG + s.tagName + " ") + answerable.getCategories().stream().forEach( + s -> sb.append(PREFIX_CATEGORY + s.categoryName+ " ") ); return sb.toString(); } @@ -56,21 +55,29 @@ public static String getEditAnswerableDescriptorDetails(EditCommand.EditAnswerab StringBuilder sb = new StringBuilder(); descriptor.getQuestion().ifPresent(question -> sb.append(PREFIX_QUESTION).append(question.fullQuestion).append(" ")); descriptor.getDifficulty().ifPresent(difficulty -> sb.append(PREFIX_DIFFICULTY).append(difficulty.value).append(" ")); - descriptor.getCategory().ifPresent(address -> sb.append(PREFIX_CATEGORY).append(address.value).append(" ")); - if (descriptor.getTags().isPresent()) { - Set tags = descriptor.getTags().get(); + if (descriptor.getCategories().isPresent()) { + Set tags = descriptor.getCategories().get(); if (tags.isEmpty()) { - sb.append(PREFIX_TAG + " "); + sb.append(PREFIX_CATEGORY + " "); } else { - tags.forEach(s -> sb.append(PREFIX_TAG).append(s.tagName).append(" ")); + tags.forEach(s -> sb.append(PREFIX_CATEGORY).append(s.categoryName).append(" ")); } } - if (descriptor.getAnswerSet().isPresent()) { - AnswerSet answerSet = descriptor.getAnswerSet().get(); - Set correctAnswerSet = answerSet.getCorrectAnswerSet(); - Set wrongAnswerSet = answerSet.getWrongAnswerSet(); - correctAnswerSet.forEach( s -> sb.append(PREFIX_CORRECT + s.answer + " ")); - wrongAnswerSet.forEach( s -> sb.append(PREFIX_WRONG + s.answer + " ")); + if (descriptor.getCorrectAnswerSet().isPresent()) { + Set correctAnswerSet = descriptor.getCorrectAnswerSet().get(); + if (correctAnswerSet.isEmpty()) { + sb.append(PREFIX_CORRECT + " "); + } else { + correctAnswerSet.forEach( s -> sb.append(PREFIX_CORRECT + s.answer + " ")); + } + } + if (descriptor.getWrongAnswerSet().isPresent()) { + Set wrongAnswerSet = descriptor.getWrongAnswerSet().get(); + if (wrongAnswerSet.isEmpty()) { + sb.append(PREFIX_WRONG + " "); + } else { + wrongAnswerSet.forEach( s -> sb.append(PREFIX_WRONG + s.answer + " ")); + } } return sb.toString(); } diff --git a/src/test/java/seedu/address/testutil/EditAnswerableDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditAnswerableDescriptorBuilder.java index da504c398da..52c94708232 100644 --- a/src/test/java/seedu/address/testutil/EditAnswerableDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditAnswerableDescriptorBuilder.java @@ -6,9 +6,9 @@ import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditAnswerableDescriptor; +import seedu.address.model.answerable.Answer; import seedu.address.model.answerable.Answerable; import seedu.address.model.category.Category; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Question; import seedu.address.model.answerable.Difficulty; @@ -34,10 +34,10 @@ public EditAnswerableDescriptorBuilder(EditCommand.EditAnswerableDescriptor desc public EditAnswerableDescriptorBuilder(Answerable answerable) { descriptor = new EditCommand.EditAnswerableDescriptor(); descriptor.setQuestion(answerable.getQuestion()); - descriptor.setAnswerSet(answerable.getAnswerSet()); + descriptor.setCorrectAnswerSet(answerable.getCorrectAnswerSet()); + descriptor.setWrongAnswerSet(answerable.getWrongAnswerSet()); descriptor.setDifficulty(answerable.getDifficulty()); - descriptor.setCategory(answerable.getCategory()); - descriptor.setTags(answerable.getTags()); + descriptor.setCategories(answerable.getCategories()); } /** @@ -47,38 +47,37 @@ public EditAnswerableDescriptorBuilder withQuestion(String question) { descriptor.setQuestion(new Question(question)); return this; } - /** - * Sets the {@code Question} of the {@code EditAnswerableDescriptor} that we are building. + * Sets the Correct Answer Set of the {@code EditAnswerableDescriptor} that we are building. */ - public EditAnswerableDescriptorBuilder withAnswerSet(AnswerSet answerSet) { - //TODO: Implement Answerable - descriptor.setAnswerSet(answerSet); + public EditAnswerableDescriptorBuilder withCorrectAnswerSet(Set correctAnswerSet) { + descriptor.setCorrectAnswerSet(correctAnswerSet); return this; } + /** - * Sets the {@code Difficulty} of the {@code EditAnswerableDescriptor} that we are building. + * Sets the Wrong Answer Set of the {@code EditAnswerableDescriptor} that we are building. */ - public EditAnswerableDescriptorBuilder withDifficulty(String difficulty) { - descriptor.setDifficulty(new Difficulty(difficulty)); + public EditAnswerableDescriptorBuilder withWrongAnswerSet(Set wrongAnswerSet) { + descriptor.setWrongAnswerSet(wrongAnswerSet); return this; } /** - * Sets the {@code Category} of the {@code EditAnswerableDescriptor} that we are building. + * Sets the {@code Difficulty} of the {@code EditAnswerableDescriptor} that we are building. */ - public EditAnswerableDescriptorBuilder withCategory(String category) { - descriptor.setCategory(new Category(category)); + public EditAnswerableDescriptorBuilder withDifficulty(String difficulty) { + descriptor.setDifficulty(new Difficulty(difficulty)); return this; } /** - * Parses the {@code tags} into a {@code Set} and set it to the {@code EditAnswerableDescriptor} + * Parses the {@code tags} into a {@code Set} and set it to the {@code EditAnswerableDescriptor} * that we are building. */ - public EditAnswerableDescriptorBuilder withTags(String... tags) { - Set tagSet = Stream.of(tags).map(Tag::new).collect(Collectors.toSet()); - descriptor.setTags(tagSet); + public EditAnswerableDescriptorBuilder withCategories(String... tags) { + Set tagSet = Stream.of(tags).map(Category::new).collect(Collectors.toSet()); + descriptor.setCategories(tagSet); return this; } diff --git a/src/test/java/seedu/address/testutil/TypicalAnswerables.java b/src/test/java/seedu/address/testutil/TypicalAnswerables.java index 5a5a0c74e7f..f1b4d3c92ff 100644 --- a/src/test/java/seedu/address/testutil/TypicalAnswerables.java +++ b/src/test/java/seedu/address/testutil/TypicalAnswerables.java @@ -1,13 +1,11 @@ package seedu.address.testutil; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BOB; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND; -import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_QUESTION_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_ALPHA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_DIFFICULTY_BETA; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_UML; +import static seedu.address.logic.commands.CommandTestUtil.VALID_CATEGORY_GREENFIELD; import java.util.ArrayList; import java.util.Arrays; @@ -17,7 +15,6 @@ import seedu.address.model.AddressBook; import seedu.address.model.answerable.Answer; -import seedu.address.model.answerable.AnswerSet; import seedu.address.model.answerable.Answerable; /** @@ -25,36 +22,38 @@ */ public class TypicalAnswerables { private static final Answer correctAnswer = new Answer("CORRECT"); - private static final Set correctAnswerSet = new HashSet<>(Arrays.asList(correctAnswer)); + private static final Set defaultCorrectAnswerSet = new HashSet<>(Arrays.asList(correctAnswer)); private static final Answer wrongAnswer = new Answer("WRONG"); - private static final Set wrongAnswerSet = new HashSet<>(Arrays.asList(wrongAnswer)); - private static final AnswerSet defaultAnswerSet = new AnswerSet(correctAnswerSet, wrongAnswerSet); + private static final Set defaultWrongAnswerSet = new HashSet<>(Arrays.asList(wrongAnswer)); - public static final Answerable A_ANSWERABLE = new AnswerableBuilder().withQuestion("Is this a Question?") - .withAnswerSet(defaultAnswerSet).withCategory("Category A").withDifficulty("1") - .withTags("easy").build(); + public static final Answerable A_ANSWERABLE = new AnswerableBuilder().withQuestion("If a subclass imposes more " + + "restrictive conditions than its parent class, it violates Liskov Substitution Principle.") + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet) + .withDifficulty("1").withCategories("LSP", "SOLID", "Week 9").build(); public static final Answerable B_ANSWERABLE = new AnswerableBuilder().withQuestion("Brownfield or Greenfield?") - .withAnswerSet(defaultAnswerSet).withCategory("Requirements").withDifficulty("2") - .withTags("field", "introduction").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet) + .withDifficulty("1").withCategories("field", "introduction").build(); public static final Answerable C_ANSWERABLE = new AnswerableBuilder().withQuestion("Carl Kurz").withDifficulty("1") - .withAnswerSet(defaultAnswerSet).withCategory("wall street").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet).build(); public static final Answerable E_ANSWERABLE = new AnswerableBuilder().withQuestion("Elle Meyer").withDifficulty("1") - .withAnswerSet(defaultAnswerSet).withCategory("michegan ave").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet).build(); public static final Answerable F_ANSWERABLE = new AnswerableBuilder().withQuestion("Fiona Kunz").withDifficulty("1") - .withAnswerSet(defaultAnswerSet).withCategory("little tokyo").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet).build(); // Manually added public static final Answerable H_ANSWERABLE = new AnswerableBuilder().withQuestion("Hoon Meier").withDifficulty("1") - .withAnswerSet(defaultAnswerSet).withCategory("little india").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet).build(); public static final Answerable I_ANSWERABLE = new AnswerableBuilder().withQuestion("Ida Mueller").withDifficulty("1") - .withAnswerSet(defaultAnswerSet).withCategory("chicago ave").build(); + .withCorrectAnswerSet(defaultCorrectAnswerSet).withWrongAnswerSet(defaultWrongAnswerSet).build(); // Manually added - Answerable's details found in {@code CommandTestUtil} - public static final Answerable ALPHA = new AnswerableBuilder().withQuestion(VALID_QUESTION_AMY).withDifficulty(VALID_DIFFICULTY_AMY) - .withAnswerSet(defaultAnswerSet).withCategory(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build(); - public static final Answerable BETA = new AnswerableBuilder().withQuestion(VALID_QUESTION_BOB).withDifficulty(VALID_DIFFICULTY_BOB) - .withAnswerSet(defaultAnswerSet).withCategory(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND) - .build(); + public static final Answerable ALPHA = new AnswerableBuilder().withQuestion(VALID_QUESTION_ALPHA) + .withDifficulty(VALID_DIFFICULTY_ALPHA) .withCorrectAnswerSet(defaultCorrectAnswerSet) + .withWrongAnswerSet(defaultWrongAnswerSet).withCategories(VALID_CATEGORY_UML).build(); + public static final Answerable BETA = new AnswerableBuilder().withQuestion(VALID_QUESTION_BETA) + .withDifficulty(VALID_DIFFICULTY_BETA).withCorrectAnswerSet(defaultCorrectAnswerSet) + .withWrongAnswerSet(defaultWrongAnswerSet) + .withCategories(VALID_CATEGORY_GREENFIELD, VALID_CATEGORY_UML).build(); public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER