Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions src/main/BalancedBrackets.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,10 @@

public class BalancedBrackets {
/**
* The function BalancedBrackets should return true if and only if
* the input string has a set of "balanced" brackets.
*
* That is, whether it consists entirely of pairs of opening/closing
* brackets (in that order), none of which mis-nest. We consider a bracket
* to be square-brackets: [ or ].
*
* The string may contain non-bracket characters as well.
*
* These strings have balanced brackets:
* "[LaunchCode]", "Launch[Code]", "[]LaunchCode", "", "[]"
*
* While these do not:
* "[LaunchCode", "Launch]Code[", "[", "]["
*
* @param str - to be validated
* @return true if balanced, false otherwise
*/
*
* @param str - to be validated
* @return true if balanced, false otherwise
*/
public static boolean hasBalancedBrackets(String str) {
int brackets = 0;
for (char ch : str.toCharArray()) {
Expand Down
26 changes: 25 additions & 1 deletion src/test/BalancedBracketsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@
import static org.junit.Assert.*;

public class BalancedBracketsTest {

/*
* RECOMMENDED: Be agnostic about the code that was written for the class
* that you are testing. Write all the tests that you think you'll need,
* in order to test the BalancedBrackets class FIRST, without looking at
* the code in the BalancedBrackets.java directly; all that you need to
* know in order to write a good test is knowing what the code is supposed
* to do.
*
* Write the tests; run them; and THEN compare the code in the class that
* you were testing with your tests, to find out whether the class, the
* tests, or both need fixing.
*
* ABOUT THE CLASS BalancedBrackets....
*
* The function BalancedBrackets should return true if and only if
* the input string has a set of "balanced" brackets.
*
* That is, whether it consists entirely of pairs of opening/closing
* brackets (in that order), none of which mis-nest. We consider a bracket
* to be square-brackets: [ or ].
*
* The string may contain non-bracket characters as well.
*
*/
//TODO: add tests here

@Test
public void emptyTest() {
assertEquals(true, true);
Expand Down