Repository navigation
Add unit tests for the "Simple Bank System" problem. - #36
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds unit tests for the "Simple Bank System" problem (LeetCode #2043) and reorganizes the code structure by moving the Bank2043 class to the proper package location.
Changes:
- Added comprehensive unit tests (Bank2043Test.java) with two test cases including edge cases from LeetCode examples
- Moved Bank2043 class from
src/tosrc/main/java/com/leetcode/medium/for proper package organization - Updated class structure with cleaner variable naming (balance → accounts) and removed redundant
thiskeywords
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main/java/com/leetcode/medium/Bank2043.java | New implementation file with cleaner code structure, replacing the old file location |
| src/test/java/com/leetcode/medium/Bank2043Test.java | New comprehensive test file with helper method and two test cases |
| src/Bank2043.java | Old implementation file removed from incorrect location |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (account1 > accounts.length || account2 > accounts.length) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account1 < 1 || account2 < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account1 - 1] or accounts[account2 - 1].
| if (account > accounts.length) { | ||
| return false; |
There was a problem hiding this comment.
The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account - 1].
| if (account > accounts.length) { | ||
| return false; |
There was a problem hiding this comment.
The account validation is incomplete. It only checks if the account number exceeds the array length, but doesn't validate if the account number is less than 1. Account numbers should be valid positive integers (1-indexed). Add a check for account < 1 to prevent potential ArrayIndexOutOfBoundsException when accessing accounts[account - 1].
| @Test | ||
| void testExample1() { | ||
| call( | ||
| new String[]{"Bank", "withdraw", "transfer", "deposit", "transfer", "withdraw"}, | ||
| new Object[][]{ | ||
| new Object[]{new long[]{10, 100, 20, 50, 30}}, | ||
| new Object[]{3, 10}, | ||
| new Object[]{5, 1, 20}, | ||
| new Object[]{5, 20}, | ||
| new Object[]{3, 4, 15}, | ||
| new Object[]{10, 50} | ||
| }, | ||
| new Object[]{null, true, true, true, false, false} | ||
| ); | ||
| } |
There was a problem hiding this comment.
The test suite lacks coverage for edge cases, particularly invalid account numbers. Consider adding test cases for scenarios such as: account numbers that are 0, negative values, or exceed the number of accounts. These edge cases would help ensure the validation logic handles boundary conditions correctly.
No description provided.