forked from AY2425S1-CS2103T-T12-4/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement CommandHistory and testcases
- Loading branch information
1 parent
7f18962
commit 6fdc539
Showing
4 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package seedu.address.ui; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class CommandHistoryTest { | ||
|
||
private CommandHistory commandHistory; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
commandHistory = new CommandHistory(); | ||
} | ||
|
||
@Test | ||
public void testAddCommand() { | ||
commandHistory.addCommand("first command"); | ||
commandHistory.addCommand("second command"); | ||
|
||
// Moving back in history | ||
assertEquals("second command", commandHistory.getPreviousCommand()); | ||
assertEquals("first command", commandHistory.getPreviousCommand()); | ||
|
||
// Should return null as there's no more previous command | ||
assertNull(commandHistory.getPreviousCommand()); | ||
} | ||
|
||
@Test | ||
public void testNextCommand() { | ||
commandHistory.addCommand("first command"); | ||
commandHistory.addCommand("second command"); | ||
|
||
// Go back twice to previous commands | ||
commandHistory.getPreviousCommand(); | ||
commandHistory.getPreviousCommand(); | ||
|
||
// Moving forward in history | ||
assertEquals("second command", commandHistory.getNextCommand()); | ||
assertNull(commandHistory.getNextCommand()); // No further next command after latest | ||
} | ||
|
||
@Test | ||
public void testEmptyHistory() { | ||
// Initially, history should return null when getting previous/next command | ||
assertNull(commandHistory.getPreviousCommand()); | ||
assertNull(commandHistory.getNextCommand()); | ||
} | ||
|
||
@Test | ||
public void testMixedNavigation() { | ||
commandHistory.addCommand("first command"); | ||
commandHistory.addCommand("second command"); | ||
commandHistory.addCommand("third command"); | ||
|
||
// Navigate through commands | ||
assertEquals("third command", commandHistory.getPreviousCommand()); | ||
assertEquals("second command", commandHistory.getPreviousCommand()); | ||
|
||
// Moving forward should bring back "third command" | ||
assertEquals("third command", commandHistory.getNextCommand()); | ||
|
||
// After the latest command, there should be no more next command | ||
assertNull(commandHistory.getNextCommand()); | ||
} | ||
} |