Beispiel #1
0
        public void IsValidTest()
        {
            var c = new ValidParentheses();

            // example1
            var target = "()";
            var result = c.IsValid(target);

            Assert.IsTrue(result);

            // example2
            target = "()[]{}";
            result = c.IsValid(target);
            Assert.IsTrue(result);

            //example3
            target = "(]";
            result = c.IsValid(target);
            Assert.IsFalse(result);

            //example4
            target = "([)]";
            result = c.IsValid(target);
            Assert.IsFalse(result);

            //example5
            target = "{[]}";
            result = c.IsValid(target);
            Assert.IsTrue(result);
        }
        public void IsValidParentheses()
        {
            ValidParentheses isValidParentheses = new ValidParentheses();
            string           sample             = "((";

            Assert.AreEqual(isValidParentheses.IsValid(sample), false);
            sample = "(())";
            Assert.AreEqual(isValidParentheses.IsValid(sample), true);
            sample = "((])";
            Assert.AreEqual(isValidParentheses.IsValid(sample), false);
            sample = "([)]";
            Assert.AreEqual(isValidParentheses.IsValid(sample), false);
        }
Beispiel #3
0
        public void Test()
        {
            var s1 = "{{{{{{";
            var s2 = "(([]}))}";
            var s3 = "(())[]{}";
            var s4 = "(({[))]}";

            var valid = new ValidParentheses();

            Assert.False(valid.IsValid(s1));
            Assert.False(valid.IsValid(s2));
            Assert.True(valid.IsValid(s3));
            Assert.False(valid.IsValid(s4));
        }
        public void IsValid(string input, bool expected)
        {
            var sut    = new ValidParentheses();
            var actual = sut.IsValid(input);

            Assert.AreEqual(expected, actual);
        }
        public void DoesntTryToPopAnEmptyStack()
        {
            var vp = new ValidParentheses();

            // Assert.False(vp.IsValid("]"));
            Assert.False(vp.IsValid("){"));
        }
Beispiel #6
0
        public void ValidParenthesesTest(string input, bool expected)
        {
            var target = new ValidParentheses();

            var actual = target.IsValid(input);

            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public void TestAlgorithm(string s, bool expected)
        {
            var func = new ValidParentheses();

            var actual = func.IsValid(s);

            Assert.Equal(expected, actual);
        }
        public void TestMethod1(string s, bool expected)
        {
            // Arrange
            ValidParentheses question = new ValidParentheses();

            // Act
            bool actual = question.IsValid(s);

            // Assert
            Assert.AreEqual(expected, actual);
        }
        public void IsValidParentheses()
        {
            ValidParentheses l = new ValidParentheses();

            Assert.IsTrue(l.IsValid("()[]"));
            Assert.IsTrue(l.IsValid("[({})]"));
            Assert.IsTrue(l.IsValid("[({})]{}"));
            Assert.IsTrue(l.IsValid(""));

            Assert.IsFalse(l.IsValid("[[({})]"));
            Assert.IsFalse(l.IsValid("([)[]"));
            Assert.IsFalse(l.IsValid("([)]"));
            Assert.IsFalse(l.IsValid("{[{]]}{}[]"));
        }
Beispiel #10
0
        private static void ValidParenthesesTest()
        {
            Console.WriteLine("\n3 Valid Parentheses question:");

            ValidParentheses validParentheses = new ValidParentheses();

            IList <string> testStrings = new List <string> {
                "()",
                "()[]{}",
                "(]",
                "([)]",
                "{[]}"
            };

            foreach (string testString in testStrings)
            {
                Console.WriteLine("{0} -> {1}", testString, validParentheses.IsValid(testString));
            }
        }
Beispiel #11
0
        public void IsValidTestCase8()
        {
            var input = "(";

            ValidParentheses.IsValid(input).Should().BeFalse();
        }
        public void ValidParentheses_FromLeetCode(string input, bool expected)
        {
            var result = ValidParentheses.IsValid(input);

            result.Should().Equals(expected);
        }
        public void SingleBracketTypeClosesCorrectly(string parens)
        {
            var vp = new ValidParentheses();

            Assert.True(vp.IsValid(parens));
        }
Beispiel #14
0
 public void When_only_one_pair_Then_valid()
 {
     Assert.AreEqual(true, ValidParentheses.IsValid("()"));
 }
Beispiel #15
0
 public void When_without_end_Then_invalid()
 {
     Assert.AreEqual(false, ValidParentheses.IsValid("({)"));
 }
Beispiel #16
0
 public void When_single_end_Then_invalid()
 {
     Assert.AreEqual(false, ValidParentheses.IsValid(")"));
 }
Beispiel #17
0
        public void IsValidTestCase5()
        {
            var input = "{[]}";

            ValidParentheses.IsValid(input).Should().BeTrue();
        }
Beispiel #18
0
 public void When_two_pair_Then_valid()
 {
     Assert.AreEqual(true, ValidParentheses.IsValid("(){}"));
 }
        public void BracketsCloseInCorrectOrder(string parens)
        {
            var vp = new ValidParentheses();

            Assert.True(vp.IsValid(parens));
        }
Beispiel #20
0
        public void InputNullOrWhitespace_ReturnTrue(string input)
        {
            var result = _validParenthesis.IsValid(input);

            Assert.True(result, $"{input} is a valid parenthesis expression");
        }
Beispiel #21
0
 public void When_pair_crossed_Then_invalid()
 {
     Assert.AreEqual(false, ValidParentheses.IsValid("({)}"));
 }
Beispiel #22
0
 public void When_pair_contain_in_Then_valid()
 {
     Assert.AreEqual(true, ValidParentheses.IsValid("([]){}"));
 }
        public void BracketsClosingInWrongOrderShouldReturnFalse(string parens)
        {
            var vp = new ValidParentheses();

            Assert.False(vp.IsValid(parens));
        }