Skip to content

Commit

Permalink
Update tests and ModuleUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyaohhh committed Oct 17, 2023
1 parent e94eb94 commit 8f92654
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalModules.CS2030S;

import java.util.Arrays;
import java.util.List;
Expand All @@ -31,7 +31,7 @@
import seedu.address.testutil.EditPersonDescriptorBuilder;
import seedu.address.testutil.ModuleBuilder;
import seedu.address.testutil.PersonBuilder;
import seedu.address.testutil.PersonUtil;
import seedu.address.testutil.ModuleUtil;

public class AddressBookParserTest {

Expand All @@ -53,17 +53,17 @@ public void parseCommand_clear() throws Exception {
@Test
public void parseCommand_delete() throws Exception {
DeleteCommand command = (DeleteCommand) parser.parseCommand(
DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased());
assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command);
DeleteCommand.COMMAND_WORD + " " + CS2030S);
assertEquals(new DeleteCommand(CS2030S.getModuleCode()), command);
}

@Test
public void parseCommand_edit() throws Exception {
Person person = new PersonBuilder().build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder(person).build();
Module module = new ModuleBuilder().build();
EditModuleDescriptor descriptor = new EditModuleDescriptorBuilder(module).build();
EditCommand command = (EditCommand) parser.parseCommand(EditCommand.COMMAND_WORD + " "
+ INDEX_FIRST_PERSON.getOneBased() + " " + PersonUtil.getEditPersonDescriptorDetails(descriptor));
assertEquals(new EditCommand(INDEX_FIRST_PERSON, descriptor), command);
+ CS2030S + " " + ModuleUtil.getEditModuleDescriptorDetails(descriptor));
assertEquals(new EditCommand(CS2030S, descriptor), command);
}

@Test
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/seedu/address/testutil/ModuleUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.address.testutil;

import static seedu.address.logic.parser.CliSyntax.PREFIX_CODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_SEMESTER;
import static seedu.address.logic.parser.CliSyntax.PREFIX_YEAR;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.EditCommand.EditModuleDescriptor;
import seedu.address.model.module.Module;


/**
* A utility class for Module.
*/
public class ModuleUtil {
/**
* Returns an add command string for adding the {@code person}.
*/
public static String getAddCommand(Module module) {
return AddCommand.COMMAND_WORD + " " + getModuleDetails(module);
}

/**
* Returns the part of command string for the given {@code person}'s details.
*/
public static String getModuleDetails(Module module) {
StringBuilder sb = new StringBuilder();
sb.append(PREFIX_CODE + module.getModuleCode().toString() + " ");
sb.append(PREFIX_YEAR + module.getYearTaken().year.toString() + " ");
sb.append(PREFIX_SEMESTER + module.getSemesterTaken().semester.toString() + " ");
sb.append(PREFIX_GRADE + module.getGrade().toString() + " ");
return sb.toString();
}

/**
* Returns the part of command string for the given {@code EditModuleDescriptor}'s details.
*/
public static String getEditModuleDescriptorDetails(EditModuleDescriptor descriptor) {
StringBuilder sb = new StringBuilder();
descriptor.getYear().ifPresent(year -> sb.append(PREFIX_YEAR).append(year.toString()).append(" "));
descriptor.getSemester().ifPresent(semester -> sb.append(PREFIX_SEMESTER).append(semester.toString()).append(" "));
descriptor.getGrade().ifPresent(grade -> sb.append(PREFIX_GRADE).append(grade.toString()).append(" "));

return sb.toString();
}
}

0 comments on commit 8f92654

Please sign in to comment.