forked from AY2324S2-CS2103T-T11-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow typing a prefix of the role to specify the role
- Loading branch information
Showing
5 changed files
with
129 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,7 @@ Shows a message listing out all the available commands and their purpose. | |
Format: `help` | ||
|
||
For more information regarding the comamnd formats and examples, press `F1` to open up a help window (as shown in the picture below). | ||
To close the help window, you can simply press `esc` on your keyboard (other methods such as `alt`+`F4` and clicking on | ||
To close the help window, you can simply press `esc` on your keyboard (other methods such as `alt`+`F4` and clicking on | ||
the red `X` button on the top right corner of the window also works). | ||
|
||
 | ||
|
@@ -91,13 +91,17 @@ A person can have any number of tags (including 0) | |
</div> | ||
|
||
Examples: | ||
* `add n/John Doe p/98765432 e/[email protected] r/STUDENT a/PGPR c/CS2101` | ||
* `add n/John Doe p/98765432 e/[email protected] r/student a/PGPR c/CS2101` | ||
* `add n/Betsy Crowe t/friend e/[email protected] r/TA a/COM2-0102 c/ST2334` | ||
|
||
Unlike the `edit` command, `t/` with an empty tag is not supported. | ||
If you want to not include any tag, leave out `t/TAG` entirely. | ||
Similarly, `p/` without any phone number is not supported, if you want to not specify the phone number, leave out `p/PHONE` entirely. | ||
|
||
The allowed roles are `Student`, `TA`, or `Professor`. | ||
The input is case-insensitive, and you can type an unambiguous prefix to specify the role. | ||
For example, you can type `r/s` instead of `r/student` as shown above. | ||
|
||
### Listing all persons : `list` | ||
|
||
Shows a list of all persons in the address book. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package seedu.address.model.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class RoleTest { | ||
|
||
@Test | ||
public void valueOf_null_throwsNullPointerException() { | ||
assertThrows(NullPointerException.class, () -> Role.valueOf(null)); | ||
} | ||
|
||
@Test | ||
public void valueOf_invalidRole_throwsIllegalArgumentException() { | ||
String invalidRole = ""; | ||
assertThrows(IllegalArgumentException.class, () -> Role.valueOf(invalidRole)); | ||
} | ||
|
||
@Test | ||
public void valueOf_validRole_success() { | ||
String validRole = "STUDENT"; | ||
assertEquals(Role.valueOf(validRole), Role.STUDENT); | ||
} | ||
|
||
@Test | ||
public void isValidRole() { | ||
// null role | ||
assertThrows(NullPointerException.class, () -> Role.isValidRole(null)); | ||
|
||
// invalid roles | ||
assertFalse(Role.isValidRole("")); // empty string | ||
assertFalse(Role.isValidRole(" ")); // spaces only | ||
assertFalse(Role.isValidRole("professor")); // non-uppercase | ||
assertFalse(Role.isValidRole("STUDENT ")); // spaces at the end | ||
assertFalse(Role.isValidRole(" STUDENT")); // spaces at the front | ||
assertFalse(Role.isValidRole("STUDENT123")); // numbers within characters | ||
assertFalse(Role.isValidRole("STUDENT-")); // special characters | ||
|
||
// valid roles | ||
assertTrue(Role.isValidRole("STUDENT")); | ||
assertTrue(Role.isValidRole("PROFESSOR")); | ||
assertTrue(Role.isValidRole("TA")); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
Role role = Role.STUDENT; | ||
|
||
// same values -> returns true | ||
assertTrue(role.equals(Role.STUDENT)); | ||
|
||
// same object -> returns true | ||
assertTrue(role.equals(role)); | ||
|
||
// null -> returns false | ||
assertFalse(role.equals(null)); | ||
|
||
// different types -> returns false | ||
assertFalse(role.equals(5.0f)); | ||
|
||
// different values -> returns false | ||
assertFalse(role.equals(Role.PROFESSOR)); | ||
} | ||
|
||
@Test | ||
public void hashcode() { | ||
Role role = Role.STUDENT; | ||
|
||
// same values -> returns same hash code | ||
assertEquals(role.hashCode(), Role.STUDENT.hashCode()); | ||
|
||
// different values -> returns different hash code | ||
assertNotEquals(role.hashCode(), Role.PROFESSOR.hashCode()); | ||
} | ||
} |