Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtest.sh syntax errors #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions src/main/java/Contacts1.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public class Contacts1 {
private static final String COMMAND_ADD_WORD = "add";
private static final String COMMAND_ADD_DESC = "Adds a person to contacts.";
private static final String COMMAND_ADD_PARAMETERS = "NAME "
+ PERSON_DATA_PREFIX_PHONE + "PHONE_NUMBER "
+ PERSON_DATA_PREFIX_EMAIL + "EMAIL";
+ PERSON_DATA_PREFIX_PHONE + "PHONE_NUMBER "
+ PERSON_DATA_PREFIX_EMAIL + "EMAIL";
private static final String COMMAND_ADD_EXAMPLE = COMMAND_ADD_WORD + " John Doe p/98765432 e/[email protected]";

private static final String COMMAND_LIST_WORD = "list";
Expand Down Expand Up @@ -87,7 +87,7 @@ public class Contacts1 {
* The number of data elements for a single person.
*/
private static final int PERSON_DATA_COUNT = 3;

/**
* Maximum number of persons that can be held.
*/
Expand Down Expand Up @@ -192,8 +192,8 @@ private static void exitProgram() {
/**
* Executes the command as specified by the {@code userInputString}
*
* @param userInputString raw input from user
* @return feedback about how the command was executed
* @param userInputString raw input from user
* @return feedback about how the command was executed
*/
private static String executeCommand(String userInputString) {
final String[] commandTypeAndParams = splitCommandWordAndArgs(userInputString);
Expand All @@ -219,11 +219,11 @@ private static String executeCommand(String userInputString) {
/**
* Splits raw user input into command word and command arguments string
*
* @return size 2 array; first element is the command type and second element is the arguments string
* @return size 2 array; first element is the command type and second element is the arguments string
*/
private static String[] splitCommandWordAndArgs(String rawUserInput) {
final String[] split = rawUserInput.trim().split("\\s+", 2);
return split.length == 2 ? split : new String[] { split[0] , "" }; // else case: no parameters
return split.length == 2 ? split : new String[]{split[0], ""}; // else case: no parameters
}

/**
Expand Down Expand Up @@ -349,7 +349,6 @@ private static void showToUser(String... message) {
/**
* Shows the list of persons to the user.
* The list will be indexed, starting from 1.
*
*/
private static void showToUser(String[][] persons) {
String listAsString = getDisplayString(persons);
Expand All @@ -365,8 +364,8 @@ private static String getDisplayString(String[][] persons) {
final String[] person = persons[i];
final int displayIndex = i + 1;
messageAccumulator.append('\t')
.append(getIndexedPersonListElementMessage(displayIndex, person))
.append(LS);
.append(getIndexedPersonListElementMessage(displayIndex, person))
.append(LS);
}
return messageAccumulator.toString();
}
Expand All @@ -375,7 +374,7 @@ private static String getDisplayString(String[][] persons) {
* Constructs a prettified listing element message to represent a person and their data.
*
* @param visibleIndex visible index for this listing
* @param person to show
* @param person to show
* @return formatted listing message with index
*/
private static String getIndexedPersonListElementMessage(int visibleIndex, String[] person) {
Expand Down Expand Up @@ -456,7 +455,7 @@ private static String getEmailFromPerson(String[] person) {
/**
* Creates a person from the given data.
*
* @param name of person
* @param name of person
* @param phone without data prefix
* @param email without data prefix
* @return constructed person
Expand All @@ -474,7 +473,7 @@ private static String[] makePersonFromData(String name, String phone, String ema
*
* @param encoded string to be decoded
* @return if cannot decode: empty Optional
* else: Optional containing decoded person
* else: Optional containing decoded person
*/
private static String[] decodePersonFromString(String encoded) {
// check that we can extract the parts of a person from the encoded string
Expand Down Expand Up @@ -535,7 +534,7 @@ private static String extractPhoneFromPersonString(String encoded) {
return removePrefixSign(encoded.substring(indexOfPhonePrefix, encoded.length()).trim(),
PERSON_DATA_PREFIX_PHONE);

// phone is middle arg, target is from own prefix to next prefix
// phone is middle arg, target is from own prefix to next prefix
} else {
return removePrefixSign(
encoded.substring(indexOfPhonePrefix, indexOfEmailPrefix).trim(),
Expand All @@ -558,7 +557,7 @@ private static String extractEmailFromPersonString(String encoded) {
return removePrefixSign(encoded.substring(indexOfEmailPrefix, encoded.length()).trim(),
PERSON_DATA_PREFIX_EMAIL);

// email is middle arg, target is from own prefix to next prefix
// email is middle arg, target is from own prefix to next prefix
} else {
return removePrefixSign(
encoded.substring(indexOfEmailPrefix, indexOfPhonePrefix).trim(),
Expand Down Expand Up @@ -615,7 +614,9 @@ private static boolean isValidEmail(String email) {
* ===============================================
*/

/** Returns usage info for all commands */
/**
* Returns usage info for all commands
*/
private static String getUsageInfoForAllCommands() {
return getUsageInfoForAddCommand() + LS
+ getUsageInfoForViewCommand() + LS
Expand All @@ -624,32 +625,42 @@ private static String getUsageInfoForAllCommands() {
+ getUsageInfoForHelpCommand();
}

/** Returns the string for showing 'add' command usage instruction */
/**
* Returns the string for showing 'add' command usage instruction
*/
private static String getUsageInfoForAddCommand() {
return String.format(MESSAGE_COMMAND_HELP, COMMAND_ADD_WORD, COMMAND_ADD_DESC) + LS
+ String.format(MESSAGE_COMMAND_HELP_PARAMETERS, COMMAND_ADD_PARAMETERS) + LS
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_ADD_EXAMPLE) + LS;
}

/** Returns string for showing 'clear' command usage instruction */
/**
* Returns string for showing 'clear' command usage instruction
*/
private static String getUsageInfoForClearCommand() {
return String.format(MESSAGE_COMMAND_HELP, COMMAND_CLEAR_WORD, COMMAND_CLEAR_DESC) + LS
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_CLEAR_EXAMPLE) + LS;
}

/** Returns the string for showing 'view' command usage instruction */
/**
* Returns the string for showing 'view' command usage instruction
*/
private static String getUsageInfoForViewCommand() {
return String.format(MESSAGE_COMMAND_HELP, COMMAND_LIST_WORD, COMMAND_LIST_DESC) + LS
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_LIST_EXAMPLE) + LS;
}

/** Returns string for showing 'help' command usage instruction */
/**
* Returns string for showing 'help' command usage instruction
*/
private static String getUsageInfoForHelpCommand() {
return String.format(MESSAGE_COMMAND_HELP, COMMAND_HELP_WORD, COMMAND_HELP_DESC) + LS
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_HELP_EXAMPLE);
}

/** Returns the string for showing 'exit' command usage instruction */
/**
* Returns the string for showing 'exit' command usage instruction
*/
private static String getUsageInfoForExitCommand() {
return String.format(MESSAGE_COMMAND_HELP, COMMAND_EXIT_WORD, COMMAND_EXIT_DESC) + LS
+ String.format(MESSAGE_COMMAND_HELP_EXAMPLE, COMMAND_EXIT_EXAMPLE) + LS;
Expand All @@ -665,9 +676,9 @@ private static String getUsageInfoForExitCommand() {
/**
* Removes sign(p/, d/, etc) from parameter string
*
* @param s Parameter as a string
* @param sign Parameter sign to be removed
* @return string without the sign
* @param s Parameter as a string
* @param sign Parameter sign to be removed
* @return string without the sign
*/
private static String removePrefixSign(String s, String sign) {
return s.replace(sign, "");
Expand Down
3 changes: 2 additions & 1 deletion text-ui-test/runtest.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fi

# compile the code into the bin folder, terminates if error occurred
if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Contacts0.java
# if ! javac -cp ../src -Xlint:none -d ../bin ../src/main/java/Contacts0.java
then
echo "********** BUILD FAILURE **********"
exit 1
Expand All @@ -23,7 +24,7 @@ fi
java -classpath ../bin Contacts0 < input.txt > ACTUAL.TXT

# compare the output to the expected output
diff ACTUAL.TXT EXPECTED.TXT
diff ACTUAL.TXT EXPECTED.txt
if [ $? -eq 0 ]
then
echo "Test result: PASSED"
Expand Down