Skip to content

Commit

Permalink
Merge pull request AY2324S1-CS2103T-W10-1#202 from LHeng1/branch-fix-…
Browse files Browse the repository at this point in the history
…ui-compare

Fix compare command output bug
  • Loading branch information
LHeng1 authored Nov 13, 2023
2 parents 96c3b63 + f48e699 commit 8a11f80
Show file tree
Hide file tree
Showing 5 changed files with 285 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ public class CompareCommandParser implements Parser<CompareCommand> {
public CompareCommand parse(String args) throws ParseException {
try {
String[] splitArgs = args.trim().split("\\s+");
if (splitArgs.length != 2) {
throw new ParseException("Invalid command format!\n"
+ "Please follow the format: compare INDEX1 INDEX2.\n"
+ "Parameters: INDEX (must be positive integers)");
}
Index index1 = ParserUtil.parseIndex(splitArgs[0]);
Index index2 = ParserUtil.parseIndex(splitArgs[1]);
return new CompareCommand(index1, index2);
} catch (ParseException pe) {
throw new ParseException("Error: Please provide valid indices for both applicants."
+ "Follow the format: compare INDEX1 INDEX2.", pe);
throw new ParseException("Invalid command format!\n"
+ "Please follow the format: compare INDEX1 INDEX2.\n"
+ "Parameters: INDEX (must be positive integers)");
}
}
}
18 changes: 11 additions & 7 deletions src/main/java/seedu/address/ui/CompareWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public CompareWindow(Person person1, Person person2) {
//person1 stuff
Gpa gpa1 = person1.getGpa();
PreviousGrade mGrade1 = person1.getPreviousGrade();
InterviewScore interviewScore1 = person1.getInterviewScore().get();
InterviewScore interviewScore1 = null;
String interviewScoreString1;

if (person1.getInterviewScore().isPresent()) {
interviewScore1 = person1.getInterviewScore().get();
interviewScoreString1 = interviewScore1.toString();
} else {
interviewScoreString1 = "-";
Expand All @@ -98,10 +99,11 @@ public CompareWindow(Person person1, Person person2) {
//person2 stuff
Gpa gpa2 = person2.getGpa();
PreviousGrade mGrade2 = person2.getPreviousGrade();
InterviewScore interviewScore2 = person2.getInterviewScore().get();
InterviewScore interviewScore2 = null;
String interviewScoreString2;

if (person1.getInterviewScore().isPresent()) {
if (person2.getInterviewScore().isPresent()) {
interviewScore2 = person2.getInterviewScore().get();
interviewScoreString2 = interviewScore2.toString();
} else {
interviewScoreString2 = "-";
Expand Down Expand Up @@ -136,10 +138,12 @@ public CompareWindow(Person person1, Person person2) {
gpa2Highlight.setOpacity(0.33);
}

if (interviewScore1.compareTo(interviewScore2) > 0) {
iScore1Highlight.setOpacity(0.33);
} else if (interviewScore1.compareTo(interviewScore2) < 0) {
iScore2Highlight.setOpacity(0.33);
if (interviewScoreString1 != "-" && interviewScoreString2 != "-") {
if (interviewScore1.compareTo(interviewScore2) > 0) {
iScore1Highlight.setOpacity(0.33);
} else if (interviewScore1.compareTo(interviewScore2) < 0) {
iScore2Highlight.setOpacity(0.33);
}
}

if (mGrade1.compareTo(mGrade2) < 0) {
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/seedu/address/logic/commands/CompareCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.testutil.AnotherPersonBuilder;
import seedu.address.testutil.PersonBuilder;

public class CompareCommandTest {

@Test
public void execute_sameIndex_throwsCommandException() {
Model model = new ModelManager();
model.addPerson(new PersonBuilder().build());
model.addPerson(new AnotherPersonBuilder().build());

CompareCommand compareCommand = new CompareCommand(Index.fromOneBased(1),
Index.fromOneBased(1));
assertThrows(CommandException.class, () -> compareCommand.execute(model),
"Error: Please provide distinct indices. " + "You cannot compare the same applicant.");
}

@Test
public void execute_invalidIndex_throwsCommandException() {
Model model = new ModelManager();
model.addPerson(new PersonBuilder().build());
model.addPerson(new AnotherPersonBuilder().build());

CompareCommand compareCommand = new CompareCommand(Index.fromOneBased(1), Index.fromOneBased(3));
assertThrows(CommandException.class, () -> compareCommand.execute(model),
"Error: One or both of the specified applicants were not found in the list.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package seedu.address.logic.parser;

import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.logic.parser.exceptions.ParseException;

public class CompareCommandParserTest {

private final CompareCommandParser parser = new CompareCommandParser();


@Test
public void parse_invalidFormat_throwsParseException() {
assertThrows(ParseException.class, () -> parser.parse("invalidArgs"));
}

@Test
public void parse_missingIndex_throwsParseException() {
assertThrows(ParseException.class, () -> parser.parse("1"));
}

@Test
public void parse_invalidIndexFormat_throwsParseException() {
assertThrows(ParseException.class, () -> parser.parse("one two"));
}

@Test
public void parse_extraArgs_throwsParseException() {
assertThrows(ParseException.class, () -> parser.parse("1 2 3"));
}
}
195 changes: 195 additions & 0 deletions src/test/java/seedu/address/testutil/AnotherPersonBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
package seedu.address.testutil;

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

import seedu.address.model.attachment.Attachment;
import seedu.address.model.person.Comment;
import seedu.address.model.person.Email;
import seedu.address.model.person.Gpa;
import seedu.address.model.person.InterviewScore;
import seedu.address.model.person.IsBookmarked;
import seedu.address.model.person.IsHidden;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.PreviousGrade;
import seedu.address.model.person.StudentNumber;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;

/**
* A utility class to help with building another Person object besides the first Person.
*/
public class AnotherPersonBuilder {

public static final String DEFAULT_STUDENT_NUMBER = "A0616616B";
public static final String DEFAULT_NAME = "Bob Cee";
public static final String DEFAULT_PHONE = "91234567";
public static final String DEFAULT_EMAIL = "[email protected]";
public static final double DEFAULT_GPA = 3.5;
public static final String DEFAULT_PREVIOUS_GRADE = "B+";
public static final boolean DEFAULT_IS_HIDDEN = false;
public static final boolean DEFAULT_BOOKMARK = false;

private StudentNumber studentNo;
private Name name;
private Phone phone;
private Email email;
private Gpa gpa;
private PreviousGrade previousGrade;
private Optional<InterviewScore> interviewScore;
private Optional<Comment> comment;
private Set<Tag> tags;
private List<Attachment> attachments;
private IsHidden isHidden;
private IsBookmarked isBookmarked;

/**
* Creates a {@code AnotherPersonBuilder} with the default details.
*/
public AnotherPersonBuilder() {
studentNo = new StudentNumber(DEFAULT_STUDENT_NUMBER);
name = new Name(DEFAULT_NAME);
phone = new Phone(DEFAULT_PHONE);
email = new Email(DEFAULT_EMAIL);
gpa = new Gpa(DEFAULT_GPA);
previousGrade = new PreviousGrade(DEFAULT_PREVIOUS_GRADE);
interviewScore = Optional.empty();
comment = Optional.empty();
tags = new HashSet<>();
isHidden = new IsHidden(DEFAULT_IS_HIDDEN);
attachments = List.of();
isBookmarked = new IsBookmarked(DEFAULT_BOOKMARK);
}

/**
* Initializes the PersonBuilder with the data of {@code personToCopy}.
*/
public AnotherPersonBuilder(Person personToCopy) {
studentNo = personToCopy.getStudentNumber();
name = personToCopy.getName();
phone = personToCopy.getPhone();
email = personToCopy.getEmail();
gpa = personToCopy.getGpa();
previousGrade = personToCopy.getPreviousGrade();
interviewScore = personToCopy.getInterviewScore();
comment = personToCopy.getComment();
tags = new HashSet<>(personToCopy.getTags());
isHidden = personToCopy.getIsHidden();
attachments = personToCopy.getAttachments();
isBookmarked = personToCopy.getIsBookmarked();
}

/**
* Sets the {@code Name} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withName(String name) {
this.name = new Name(name);
return this;
}

/**
* Sets the {@code StudentNumber} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withStudentNumber(String studentNo) {
this.studentNo = new StudentNumber(studentNo);
return this;
}

/**
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the
* {@code Person} that we are building.
*/
public AnotherPersonBuilder withTags(String... tags) {
this.tags = SampleDataUtil.getTagSet(tags);
return this;
}

/**
* Parses the {@code pathStrings} into a {@code List<File>} and set it to the
* {@code Person} that we are building.
*/
public AnotherPersonBuilder withAttachments(String... pathStrings) {
this.attachments = SampleDataUtil.getAttachments(pathStrings);
return this;
}

/**
* Sets the {@code Gpa} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withGpa(double gpa) {
this.gpa = new Gpa(gpa);
return this;
}

/**
* Sets the {@code PreviousGrade} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withPreviousGrade(String grade) {
this.previousGrade = new PreviousGrade(grade);
return this;
}

/**
* Sets the {@code InterviewScore} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withInterviewScore(double interviewScore) {
this.interviewScore = Optional.of(new InterviewScore(interviewScore));
return this;
}

/**
* Sets the {@code Comment} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withComment(String comment) {
this.comment = Optional.of(new Comment(comment));
return this;
}

/**
* Sets the {@code Phone} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withPhone(String phone) {
this.phone = new Phone(phone);
return this;
}

/**
* Sets the {@code Email} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withEmail(String email) {
this.email = new Email(email);
return this;
}

/**
* Sets the {@code isHidden} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withHidden(boolean isHidden) {
this.isHidden = new IsHidden(isHidden);
return this;
}

/**
* Sets the {@code Bookmark} of the {@code Person} that we are building.
*/
public AnotherPersonBuilder withBookmark(boolean isBookmarked) {
this.isBookmarked = new IsBookmarked(isBookmarked);
return this;
}

/**
* Builds a person from the attributes configured before this.
*
* @return The person.
*/
public Person build() {
return new Person(studentNo, name, phone, email, gpa, previousGrade, interviewScore, comment, tags, attachments,
isHidden, isBookmarked);
}

}

0 comments on commit 8a11f80

Please sign in to comment.