diff --git a/src/main/BalancedBrackets.java b/src/main/BalancedBrackets.java index 5196fdbd..9fa1d3c3 100644 --- a/src/main/BalancedBrackets.java +++ b/src/main/BalancedBrackets.java @@ -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()) { diff --git a/src/test/BalancedBracketsTest.java b/src/test/BalancedBracketsTest.java index 3677ab96..0e6192df 100644 --- a/src/test/BalancedBracketsTest.java +++ b/src/test/BalancedBracketsTest.java @@ -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);