Skip to content

Commit

Permalink
Add a runtests.sh #6 (#10)
Browse files Browse the repository at this point in the history
[6] Add a runtests.sh
  • Loading branch information
ndt93 authored and damithc committed Aug 11, 2016
1 parent f33e570 commit 150cec8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ hs_err_pid*

# Temp files used for testing
test/actual.txt
test/localrun.bat
test/localrun.bat
/bin/
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ Example:

**Mac/Unix/Linux**

Create a script similar to the windows version.
You can use the `diff` command in place of the `FC` command.
1. Open a terminal window in the `test` folder
2. Run the `runtests.sh` script
3. If the script reports that there is no difference between `actual.txt` and `expected.txt`,
the test has passed.

**Troubleshooting test failures**

Expand Down Expand Up @@ -353,4 +355,4 @@ Some suggested enhancements:

* **Bug reports, Suggestions** : Post in our [issue tracker](https://github.com/se-edu/addressbook-level1/issues)
if you noticed bugs or have suggestions on how to improve.
* **Contributing** : We welcome pull requests. Follow the process described [here](https://github.com/oss-generic/process)
* **Contributing** : We welcome pull requests. Follow the process described [here](https://github.com/oss-generic/process)
35 changes: 22 additions & 13 deletions src/seedu/addressbook/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
* ====================================================================
*/

import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Scanner;
import java.util.Set;

/* ==============NOTE TO STUDENTS======================================
* This class header comment below is brief because details of how to
Expand Down Expand Up @@ -242,7 +251,7 @@ private static void echoUserCommand(String userCommand) {
* Processes the program main method run arguments.
* If a valid storage file is specified, sets up that file for storage.
* Otherwise sets up the default file for storage.
*
*
* @param args full program arguments passed to application main method
*/
private static void processProgramArgs(String[] args) {
Expand Down Expand Up @@ -321,7 +330,7 @@ private static void loadDataFromStorage() {

/**
* Executes the command as specified by the {@code userInputString}
*
*
* @param userInputString raw input from user
* @return feedback about how the command was executed
*/
Expand Down Expand Up @@ -382,7 +391,7 @@ private static String executeAddPerson(String commandArgs) {

// checks if args are valid (decode result will not be present if the person is invalid)
if (!decodeResult.isPresent()) {
return getMessageForInvalidCommandInput(COMMAND_WORD_ADD, getUsageInfoForAddCommand());
return getMessageForInvalidCommandInput(COMMAND_ADD_WORD, getUsageInfoForAddCommand());
}

// add the person as specified
Expand All @@ -406,7 +415,7 @@ private static String getMessageForSuccessfulAddPerson(String[] addedPerson) {
/**
* Finds and lists all persons in address book whose name contains any of the argument keywords.
* Keyword matching is case sensitive.
*
*
* @param commandArgs full command args string from the user
* @return feedback display message for the operation result
*/
Expand Down Expand Up @@ -456,13 +465,13 @@ private static ArrayList<String[]> getPersonsWithNameContainingAnyKeyword(Collec

/**
* Deletes person identified using last displayed index.
*
*
* @param commandArgs full command args string from the user
* @return feedback display message for the operation result
*/
private static String executeDeletePerson(String commandArgs) {
if (!isDeletePersonArgsValid(commandArgs)) {
return getMessageForInvalidCommandInput(COMMAND_WORD_DELETE, getUsageInfoForDeleteCommand());
return getMessageForInvalidCommandInput(COMMAND_DELETE_WORD, getUsageInfoForDeleteCommand());
}
final int targetVisibleIndex = extractTargetIndexFromDeletePersonArgs(commandArgs);
if (!isDisplayIndexValidForLastPersonListingView(targetVisibleIndex)) {
Expand Down Expand Up @@ -521,7 +530,7 @@ private static String getMessageForSuccessfulDelete(String[] deletedPerson) {

/**
* Clears all persons in the address book.
*
*
* @return feedback display message for the operation result
*/
private static String executeClearAddressBook() {
Expand Down Expand Up @@ -806,7 +815,7 @@ private static void initialiseAddressBookModel(ArrayList<String[]> persons) {
ALL_PERSONS.addAll(persons);
}


/*
* ===========================================
* PERSON METHODS
Expand Down Expand Up @@ -1074,7 +1083,7 @@ private static String getUsageInfoForAllCommands() {

/**
* Builds string for showing 'add' command usage instruction
*
*
* @return 'add' command usage instruction
*/
private static String getUsageInfoForAddCommand() {
Expand Down Expand Up @@ -1154,10 +1163,10 @@ 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 Priority string without p/
*/
private static String removePrefixSign(String s, String sign) {
Expand Down
22 changes: 22 additions & 0 deletions test/runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# create ../bin directory if not exists
if [ ! -d "../bin" ]
then
mkdir ../bin
fi

# compile the code into the bin folder
javac ../src/seedu/addressbook/Addressbook.java -d ../bin

# run the program, feed commands from input.txt file and redirect the output to the actual.txt
java -classpath ../bin seedu.addressbook.AddressBook < input.txt > actual.txt

# compare the output to the expected output
diff actual.txt expected.txt
if [ $? -eq 0 ]
then
echo "Test result: PASSED"
else
echo "Test result: FAILED"
fi

0 comments on commit 150cec8

Please sign in to comment.