Skip to content

Commit

Permalink
Merge pull request #320 from TVageesan/master
Browse files Browse the repository at this point in the history
Finish BuffBuddy
  • Loading branch information
nirala-ts authored Nov 12, 2024
2 parents 56d1602 + b770f5b commit 004ca15
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 31 deletions.
38 changes: 19 additions & 19 deletions src/main/java/BuffBuddy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.util.NoSuchElementException;

/**
* Represents the main class of the BuffBuddy application, a fitness tracking
* program designed to manage user commands, interact with storage, display UI messages,
* and maintain a history of commands and user programs.
*/
* Represents the main class of the BuffBuddy application, a fitness tracking
* program designed to manage user commands, interact with storage, display UI messages,
* and maintain a history of commands and user programs.
*/

public class BuffBuddy {
private static final String DEFAULT_FILE_PATH = "./data/data.json";
Expand All @@ -33,34 +33,34 @@ public BuffBuddy(String filePath) {
ui.showMessage(storage.getMessage());
}

/**
* Main entry point for the BuffBuddy application.
* Initializes a BuffBuddy instance with the default file path and
* starts the main command handling loop.
*
* @param args Command-line arguments (unused).
*/
/**
* Main entry point for the BuffBuddy application.
* Initializes a BuffBuddy instance with the default file path and
* starts the main command handling loop.
*
* @param args Command-line arguments (unused).
*/

public static void main(String[] args) {
new BuffBuddy(DEFAULT_FILE_PATH).run();
}

/**
* Runs the main program loop for BuffBuddy, displaying a welcome message,
* handling user commands, and displaying a farewell message upon exit.
*/
* Runs the main program loop for BuffBuddy, displaying a welcome message,
* handling user commands, and displaying a farewell message upon exit.
*/

public void run() {
ui.showWelcome();
handleCommands();
ui.showFarewell();
}

/**
* Handles the command processing loop, reading commands from the user,
* parsing them, executing the corresponding actions, and saving data.
* Exits the loop when an ExitCommand is issued.
*/
/**
* Handles the command processing loop, reading commands from the user,
* parsing them, executing the corresponding actions, and saving data.
* Exits the loop when an ExitCommand is issued.
*/

private void handleCommands() {
while(true) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/parser/ParserUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ public static int parseIndex(String indexString) {
return NULL_INTEGER;
}

int index = parseInteger(indexString) - 1;
int index = parseInteger(indexString);
validate(index);
index--;

logger.log(Level.INFO, "Successfully parsed index: {0}", index);
return index;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/parser/FlagParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void testGetStringByFlagEmptyFlag() {
@Test
void testGetIndexByFlagValidCase() {
assertEquals(0, flagParser.getIndexByFlag("/p"),
"Expected zero-based index '0' for flag '/p' with value '1'");
"Expected zero-based index '0' for flag '/p' with value '0'");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ void testParseInvalidCommand() {
// Tests for prepareCreateCommand
@Test
public void testPrepareCreateCommandValidInput() {
String argumentString = "MyProgram /d Day1 /e /name PushUps /set 3 /rep 15 /w 0 /c 50";
String argumentString = "MyProgram /d Day1 /e /name PushUps /set 3 /rep 15 /w 10 /c 50";

Day expectedDay = new Day("Day1");
expectedDay.insertExercise(new Exercise(3, 15, 0, 50, "PushUps"));
expectedDay.insertExercise(new Exercise(3, 15, 10, 50, "PushUps"));

ArrayList<Day> expectedDays = new ArrayList<>(List.of(expectedDay));
CreateProgrammeCommand expectedCommand = new CreateProgrammeCommand("MyProgram", expectedDays);
Expand All @@ -96,14 +96,14 @@ public void testPrepareCreateCommandNoDaysNoExercises() {

@Test
public void testPrepareCreateCommandMultipleDays() {
String argumentString = "MyProgram /d Day1 /e /name PushUps /set 3 /rep 15 /w 0 /c 50 /d " +
"Day2 /e /name SitUps /set 2 /rep 20 /w 0 /c 30";
String argumentString = "MyProgram /d Day1 /e /name PushUps /set 3 /rep 15 /w 10 /c 50 /d " +
"Day2 /e /name SitUps /set 2 /rep 20 /w 10 /c 30";

Day day1 = new Day("Day1");
day1.insertExercise(new Exercise(3, 15, 0, 50, "PushUps"));
day1.insertExercise(new Exercise(3, 15, 10, 50, "PushUps"));

Day day2 = new Day("Day2");
day2.insertExercise(new Exercise(2, 20, 0, 30, "SitUps"));
day2.insertExercise(new Exercise(2, 20, 10, 30, "SitUps"));

ArrayList<Day> expectedDays = new ArrayList<>(Arrays.asList(day1, day2));
CreateProgrammeCommand expectedCommand = new CreateProgrammeCommand("MyProgram", expectedDays);
Expand All @@ -116,14 +116,14 @@ public void testPrepareCreateCommandMultipleDays() {
@Test
public void testPrepareCreateCommandMultipleDaysMultipleExercises() {
String argumentString = "MyProgram " +
"/d Day1 /e /name PushUps /set 3 /rep 15 /w 0 /c 50 " +
"/e /name SitUps /set 2 /rep 20 /w 0 /c 30 " +
"/d Day1 /e /name PushUps /set 3 /rep 15 /w 10 /c 50 " +
"/e /name SitUps /set 2 /rep 20 /w 10 /c 30 " +
"/d Day2 /e /name Squats /set 4 /rep 10 /w 20 /c 100 " +
"/e /name Lunges /set 3 /rep 12 /w 15 /c 80";

Day day1 = new Day("Day1");
day1.insertExercise(new Exercise(3, 15, 0, 50, "PushUps"));
day1.insertExercise(new Exercise(2, 20, 0, 30, "SitUps"));
day1.insertExercise(new Exercise(3, 15, 10, 50, "PushUps"));
day1.insertExercise(new Exercise(2, 20, 10, 30, "SitUps"));

Day day2 = new Day("Day2");
day2.insertExercise(new Exercise(4, 10, 20, 100, "Squats"));
Expand Down

0 comments on commit 004ca15

Please sign in to comment.