Skip to content

Commit

Permalink
Merge pull request #158 from Ftywan/testing
Browse files Browse the repository at this point in the history
Testing codes for job relevant classes
  • Loading branch information
Saif Uddin Mahmud committed Nov 8, 2018
2 parents e78ed51 + f32ea12 commit ba92b13
Show file tree
Hide file tree
Showing 26 changed files with 1,413 additions and 275 deletions.
8 changes: 4 additions & 4 deletions preferences.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"guiSettings" : {
"windowWidth" : 1616.0,
"windowHeight" : 876.0,
"windowWidth" : 1440.0,
"windowHeight" : 839.0,
"windowCoordinates" : {
"x" : -8,
"y" : -8
"x" : 0,
"y" : 23
}
},
"addressBookFilePath" : "data\\addressbook.xml",
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public static Long parseDuration(String duration) throws ParseException {
public static JobNote parseJobNote(String jobNote) throws ParseException {
requireNonNull(jobNote);
String trimJobNote = jobNote.trim();
if (!JobNote.isValidNote(jobNote)) {
if (!JobNote.isValidJobNote(jobNote)) {
throw new ParseException(Job.MESSAGE_NOTE_CONSTRAINTS);
}

Expand Down
29 changes: 17 additions & 12 deletions src/main/java/seedu/address/model/job/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Job {
public static final String MESSAGE_NAME_CONSTRAINTS =
"Job names should only contain alphanumeric characters and spaces, " + "and it should not be blank";
public static final String MESSAGE_NAME_CONSTRAINTS = "Job names should only contain alphanumeric characters and "
+ "spaces, " + "and it should not be blank";

public static final String MESSAGE_NOTE_CONSTRAINTS =
"Job notes should only contain alphanumeric characters and spaces, " + "and it should not be blank";
public static final String MESSAGE_NOTE_CONSTRAINTS = "Job notes should only contain alphanumeric characters and "
+ "spaces, " + "and it should not be blank";

public static final String MEEEAGE_PRIORITY_CONSTRAINTS = "Job priority can only be URGENT, HIGH and NORMAL";

Expand Down Expand Up @@ -243,9 +243,9 @@ public boolean isSameJob(Job otherJob) {
return true;
}

return otherJob != null && otherJob.getJobName().equals(getJobName()) && (
otherJob.getMachineName().equals(getMachineName()) || otherJob.getAddedTime().equals(getAddedTime())
|| otherJob.getOwner().equals(getOwner()));
return otherJob != null && otherJob.getJobName().equals(getJobName()) && (otherJob.getMachineName()
.equals(getMachineName()) || otherJob.getAddedTime().equals(getAddedTime()) || otherJob.getOwner()
.equals(getOwner()));
}

/**
Expand Down Expand Up @@ -312,6 +312,9 @@ private int statusRank(Status myStatus) {
*/
@Override
public boolean equals(Object other) {
if (!(other instanceof Job)) {
return false;
}
Job otherJob = (Job) other;

if (other == this) {
Expand All @@ -322,9 +325,11 @@ public boolean equals(Object other) {
return false;
}

return otherJob.getJobName().equals(getJobName()) && otherJob.getMachineName().equals(getMachineName())
&& otherJob.getOwner().equals(getOwner()) && otherJob.getAddedTime().equals(getAddedTime()) && otherJob
.getTags().equals(getTags());
return otherJob.getJobName().equals(getJobName()) && otherJob.getMachineName()
.equals(getMachineName()) && otherJob.getOwner().equals(getOwner()) && otherJob.getAddedTime().showTime()
.equals(getAddedTime().showTime()) && otherJob.getTags().equals(getTags()) && otherJob.getJobNote()
.equals(getJobNote()) && (otherJob.getPriority() == getPriority()) && (otherJob
.getDuration() == getDuration());
}

/**
Expand Down Expand Up @@ -354,8 +359,8 @@ public int hashCode() {

@Override
public String toString() {
return "Job name " + this.getJobName().toString() + "\nJob machine " + this.getMachineName().toString()
+ "\nJob Priority " + this.getPriority() + "\nJob status " + this.getStatus();
return "Job name " + this.getJobName().toString() + "\nJob machine " + this.getMachineName()
.toString() + "\nJob Priority " + this.getPriority() + "\nJob status " + this.getStatus();
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/job/JobNote.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public JobNote(String note) {
this.note = note;
}

public static boolean isValidNote(String test) {
public static boolean isValidJobNote(String test) {
return test.matches(NAME_VALIDATION_REGEX);
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/model/job/Priority.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ public static boolean isValidPriority(String priority) {
* if it return true
* else return false
*/

public static int isHigherPriority(Priority priority1, Priority priority2) {
public static boolean isHigherPriority(Priority priority1, Priority priority2) {
Integer priority1value = priority1 == URGENT ? 2 : priority1 == HIGH ? 1 : priority1 == NORMAL ? 0 : -1;
Integer priority2value = priority2 == URGENT ? 2 : priority2 == HIGH ? 1 : priority2 == NORMAL ? 0 : -1;

return priority1value > priority2value ? 1 : priority1value.equals(priority2value) ? 0 : -1;
return priority1value > priority2value;
}

}
39 changes: 36 additions & 3 deletions src/main/java/seedu/address/model/job/UniqueJobList.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void shift(Job toShift, int shiftBy) {
*/
public void remove(Job toRemove) {
requireNonNull(toRemove);
if (!internalList.remove(toRemove)) {
throw new JobNotFoundException();
}
internalList.remove(toRemove);
}

Expand All @@ -100,6 +103,26 @@ public void setJobs(List<Job> jobs) {
FXCollections.sort(internalList, new JobComparator());
}

/**
* Replaces the job {@code target} in the list with {@code editedJob}.
* {@code target} must exist in the list.
* The job identity of {@code editedJob} must not be the same as another existing job in the list.
*/
public void setJob(Job target, Job editedJob) {
requireAllNonNull(target, editedJob);

int index = internalList.indexOf(target);
if (index == -1) {
throw new JobNotFoundException();
}

if (!target.isSameJob(editedJob) && contains(editedJob)) {
throw new DuplicateJobException();
}

internalList.set(index, editedJob);
}

/**
* Returns a job by name
*/
Expand Down Expand Up @@ -128,12 +151,22 @@ public ObservableList<Job> asUnmodifiableObservableList() {
/**
* Returns a sorted list based on custom comparator
*/

public ObservableList<Job> asUnmodifiableObservableSortedList() {
FXCollections.sort(internalList, new JobComparator());
return FXCollections.unmodifiableObservableList(internalList);
}

/**
*
* checks whether the given object is equal to the UniqueJobList
*/
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof UniqueJobList // instanceof handles nulls
&& internalList.equals(((UniqueJobList) other).internalList));
}

/**
* Returns true if the list has no repetition
*/
Expand Down Expand Up @@ -177,9 +210,9 @@ public long getTotalTime() {
}

/**
* Replaces the person {@code target} in the list with {@code editedJob}.
* Replaces the job {@code target} in the list with {@code editedJob}.
* {@code target} must exist in the list.
* The person identity of {@code editedJob} must not be the same as another existing person in the list.
* The job identity of {@code editedJob} must not be the same as another existing job in the list.
*/
public void updateJob(Job target, Job editedJob) {
requireAllNonNull(target, editedJob);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MakerManagerJobs>
<jobs>
<name>bumblebee</name>
<machine>
<machineName>BumberbeePrinter</machineName>
<status>ENABLED</status>
</machine>
<startTime>30/10 00:37:23</startTime>
<name>IntertestingStuff</name>
<machine>MakerSpace1</machine>
<owner>
<name>Bumble bee</name>
<phone>85355255</phone>
<email>alice@gmail.com</email>
<address>123, Jurong West Ave 6, #08-111</address>
<name>Jun Jie</name>
<phone>000</phone>
<email>0@u.nus.edu</email>
<address>000</address>
</owner>
<addedTime>
<timeStamp>1541613643024</timeStamp>
</addedTime>
<startTime>
<timeStamp>1541613643024</timeStamp>
</startTime>
<priority>NORMAL</priority>
<duration>1.0</duration>
<note>This is bumberbee jobnote</note>
<duration>10800000</duration>
<status>QUEUED</status>
<requestDeletion>false</requestDeletion>
<note>Let us do some interesting stuff</note>
</jobs>
<jobs>
<name>bumblebee</name>
<machine>
<machineName>BumberbeePrinter</machineName>
<status>ENABLED</status>
</machine>
<startTime>30/10 00:37:23</startTime>
<name>IntertestingStuff</name>
<machine>MakerSpace1</machine>
<owner>
<name>Bumble bee</name>
<phone>85355255</phone>
<email>alice@gmail.com</email>
<address>123, Jurong West Ave 6, #08-111</address>
<name>Jun Jie</name>
<phone>000</phone>
<email>0@u.nus.edu</email>
<address>000</address>
</owner>
<addedTime>
<timeStamp>1541613643024</timeStamp>
</addedTime>
<startTime>
<timeStamp>1541613643024</timeStamp>
</startTime>
<priority>NORMAL</priority>
<duration>1.0</duration>
<note>This is bumberbee jobnote</note>
<duration>10800000</duration>
<status>QUEUED</status>
<requestDeletion>false</requestDeletion>
<note>Let us do some interesting stuff</note>
</jobs>
</MakerManagerJobs>
Loading

0 comments on commit ba92b13

Please sign in to comment.