Skip to content

Commit

Permalink
Merge branch 'master' into feat/phoneValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
alphajae11 committed Apr 14, 2024
2 parents 2504e8f + 42c51b5 commit cbbbc8a
Show file tree
Hide file tree
Showing 13 changed files with 458 additions and 34 deletions.
374 changes: 351 additions & 23 deletions docs/UserGuide.md

Large diffs are not rendered by default.

Binary file added docs/images/UG-Basics/assign-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UG-Basics/charge-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/UG-Basics/filter-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UG-Basics/find-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UG-Basics/owe-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 20 additions & 3 deletions src/main/java/seedu/address/model/cca/Cca.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import static seedu.address.commons.util.AppUtil.checkArgument;
import static seedu.address.logic.parser.CliSyntax.NIL_FIELD;

import java.util.HashSet;
import java.util.Set;
/**
* Represents a CCA in the address book.
* Guarantees: immutable; name is valid as declared in {@link #isValidCCAName(String)}
* Guarantees: immutable; name is valid as declared in {@link #isValidCcaName(String)}
*/
public class Cca {

Expand All @@ -21,14 +23,28 @@ public class Cca {
/**
* Constructs a {@code Cca}.
*
* @param CCAName A valid CCA name.
* @param ccaName A valid CCA name.
*/
public Cca(String ccaName) {
requireNonNull(ccaName);
checkArgument(isValidCcaName(ccaName), MESSAGE_CONSTRAINTS);
this.ccaName = ccaName;
}

/**
* Creates a set of Cca objects from a set of Cca names.
*
* @param ccaNames
* @return
*/
public static Set<Cca> createCcaSet(String... ccaNames) {
Set<Cca> ccaSet = new HashSet<>();
for (String ccaName : ccaNames) {
ccaSet.add(new Cca(ccaName));
}
return ccaSet;
}

/**
* Returns true if a given string is a valid Cca name.
*/
Expand All @@ -37,7 +53,8 @@ public static boolean isValidCcaName(String test) {
}

/**
* Checks if other is the same Cca by checking only the name.
* Checks if other is the same Cca by checking only the name.(Test only)
*
* @param other
* @return
*/
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphabetical characters and spaces, and it should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[a-zA-Z\\s]+";

public final String fullName;

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/seedu/address/model/roles/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static seedu.address.commons.util.AppUtil.checkArgument;
import static seedu.address.logic.parser.CliSyntax.NIL_FIELD;

import java.util.HashSet;
import java.util.Set;
/**
* Represents a Role in the address book.
* Guarantees: immutable; name is valid as declared in {@link #isValidRoleName(String)}
Expand All @@ -29,6 +31,21 @@ public Role(String roleName) {
this.roleName = roleName;
}

/**
* Creates a set of Role objects from a set of role names.(Test only)
*
* @param roleNames
* @return Set of role Objects
*/
public static Set<Role> createRoleSet(String... roleNames) {
requireNonNull(roleNames);
Set<Role> roles = new HashSet<>();
for (String roleName : roleNames) {
roles.add(new Role(roleName));
}
return roles;
}

/**
* Returns true if a given string is a valid role name.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/storage/JsonAdaptedCCA.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import seedu.address.model.cca.Cca;

/**
* Jackson-friendly version of {@link CCA}.
* Jackson-friendly version of {@link Cca}.
*/
class JsonAdaptedCca {

Expand Down
60 changes: 59 additions & 1 deletion src/test/java/seedu/address/logic/commands/OweCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Part of the code is adpatated from original AB3 Code. All credits and thanks to the original
// Part of the code is adapted from original AB3 Code. All credits and thanks to the original
// CS2103T teaching team for this.
package seedu.address.logic.commands;

Expand All @@ -17,6 +17,17 @@
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.amount.Amount;
import seedu.address.model.attendance.Attendance;
import seedu.address.model.attendance.Sessions;
import seedu.address.model.cca.Cca;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Metadata;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.roles.Role;


/**
* Contains integration tests (interaction with the Model) and unit tests for
Expand All @@ -42,6 +53,53 @@ public void testGetIndex() {
assertEquals(expectedIndex, oweCommand.getIndex());
}

// The testGetAmount() is adapted from ChatGPT. (Reason: Quick add a simple test)
@Test
public void testGetAmount() {
Amount expectedAmount = new Amount("100.0");
OweCommand oweCommand = new OweCommand(INDEX_FIRST_PERSON, expectedAmount);
assertEquals(expectedAmount, oweCommand.getAmount());
}
@Test
public void testCreateOwedPerson() {
// Arrange

Person personToOwe = new Person(new Name("temp"), new Phone("94351252"),
new Email("[email protected]"), new Address("secret"), Role.createRoleSet("member"),
Cca.createCcaSet(), new Amount("100.0"), new Attendance("3"), new Sessions("5"),
new Metadata("eating"));
Amount amount = new Amount("100.0");

// Act
Person owedPerson = OweCommand.createOwedPerson(personToOwe, amount);

// Assert
assertEquals(personToOwe.getName(), owedPerson.getName());
assertEquals(personToOwe.getPhone(), owedPerson.getPhone());
assertEquals(personToOwe.getEmail(), owedPerson.getEmail());
assertEquals(personToOwe.getAddress(), owedPerson.getAddress());
assertEquals(personToOwe.getRoles(), owedPerson.getRoles());
assertEquals(personToOwe.getCcas(), owedPerson.getCcas());
assertEquals(amount, owedPerson.getAmount());
assertEquals(personToOwe.getAtt(), owedPerson.getAtt());
assertEquals(personToOwe.getSess(), owedPerson.getSess());
assertEquals(personToOwe.getMetadata(), owedPerson.getMetadata());
}

@Test
public void testToString() {
// Arrange
Index index = Index.fromOneBased(5);
Amount amount = new Amount("100.00");
OweCommand oweCommand = new OweCommand(index, amount);

// Act
String result = oweCommand.toString();

// Assert
String expected = "OweCommand{ index: " + index + ", amount: " + amount + "}";
assertEquals(expected, result);
}
@Test
public void equals() {
Amount amount = new Amount("10.00");
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/seedu/address/model/person/EmailTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public void isValidEmail() {
assertFalse(Email.isValidEmail("[email protected]")); // domain name starts with a hyphen
assertFalse(Email.isValidEmail("[email protected]")); // domain name ends with a hyphen
assertFalse(Email.isValidEmail("[email protected]")); // top level domain has less than two chars
assertFalse(Email.isValidEmail("something@org.")); // should return false
assertFalse(Email.isValidEmail("something@gov.")); // should return false
assertFalse(Email.isValidEmail("something@net.")); // should return false

// valid email
assertTrue(Email.isValidEmail("[email protected]")); // underscore in local part
Expand All @@ -64,6 +67,9 @@ public void isValidEmail() {
assertTrue(Email.isValidEmail("[email protected]")); // long domain name
assertTrue(Email.isValidEmail("[email protected]")); // long local part
assertTrue(Email.isValidEmail("[email protected]")); // more than one period in domain
assertTrue(Email.isValidEmail("[email protected]")); // test org website
assertTrue(Email.isValidEmail("[email protected]")); // test gov website
assertTrue(Email.isValidEmail("[email protected]")); // test net website
}

@Test
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/seedu/address/model/person/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,14 @@ public void isValidName() {

// invalid name
assertFalse(Name.isValidName("")); // empty string
assertFalse(Name.isValidName(" ")); // spaces only
assertFalse(Name.isValidName("^")); // only non-alphanumeric characters
assertFalse(Name.isValidName("peter*")); // contains non-alphanumeric characters

// valid name
assertTrue(Name.isValidName("peter jack")); // alphabets only
assertTrue(Name.isValidName("12345")); // numbers only
assertTrue(Name.isValidName("peter the 2nd")); // alphanumeric characters
assertTrue(Name.isValidName("peter the second")); // alphanumeric characters
assertTrue(Name.isValidName("Capital Tan")); // with capital letters
assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names
assertTrue(Name.isValidName("David Roger Jackson Ray Jr")); // long names
}

@Test
Expand Down

0 comments on commit cbbbc8a

Please sign in to comment.