Skip to content

Commit

Permalink
Merge pull request #33 from ChuaCleon/branch_SearchExpense
Browse files Browse the repository at this point in the history
Branch search expense
  • Loading branch information
ChuaCleon authored Oct 10, 2024
2 parents 0bef4d4 + c4f796e commit 8418614
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,13 @@ public static String displayExpensesWithDate(YearMonth month) {
*/
public static String searchExpenses(String keyword){
String result = "";
if (keyword.equals("")){
result = getEmptyDisplayMessage();
return result;
}
int counter = 1;
for (Expense expense : expenses) {
if (expense.getDescription().contains(keyword)){
if (expense.getDescription().toLowerCase().contains(keyword.toLowerCase())){
result += counter + ". " + expense.toString() + "\n";
counter++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,23 @@ void displayExpensesWithCategoryAndDate_incorrectMonth_expectEmptyDisplayString(
assertEquals(EMPTY_DISPLAY_STRING,
ExpenseManager.displayExpensesWithCategoryAndDate(category, yearMonth));
}

@Test
void searchExpense_noDescriptor_expectEmptyDisplayString(){
initializeTestContent();
assertEquals(EMPTY_DISPLAY_STRING, ExpenseManager.searchExpenses(""));
}

@Test
void searchExpense_descriptorProvidedNoFoundExpense_expectEmptyDisplayString(){
initializeTestContent();
assertEquals(EMPTY_DISPLAY_STRING, ExpenseManager.searchExpenses("RANDOMMESSAGE"));
}

@Test
void searchExpense_foundExpense_expectOutput(){
initializeTestContent();
assertEquals("1. Description: New Food Amount: 12.0 Date: 2024-02-12 Category: FOOD\n",
ExpenseManager.searchExpenses("New"));
}
}

0 comments on commit 8418614

Please sign in to comment.