DEV Community

loading...

Discussion on: Daily Challenge #1 - String Peeler

Collapse
anilkhandei profile image
Anil Kumar Khandei

I am so many months late in the game so starting with the first one.

 public static string StringPeeler(string InputStr)
        {
            if (InputStr.Length <= 2)
            {
                return "invalid";
            }
            else
            {
                return InputStr.Substring(1, InputStr.Length - 2);
            }
        }

And also unit tested the same:

 [TestMethod]
        public void StringPeeler_InvalidTest()
        {
           var result= DEVToChallenges.StringPeeler("a");

            Assert.IsTrue(result == "invalid");
        }
        [TestMethod]
        public void StringPeeler_InvalidTestTwo()
        {
            var result = DEVToChallenges.StringPeeler("an");

            Assert.IsTrue(result == "invalid");
        }

        [TestMethod]
        public void StringPeeler_InvalidTestThree()
        {
            var result = DEVToChallenges.StringPeeler("ant");

            Assert.IsFalse(result == "invalid");
        }

        [TestMethod]
        public void StringPeeler_ValidTestOne()
        {
            var result = DEVToChallenges.StringPeeler("cobol");

            Assert.IsTrue(result == "obo");
        }
Forem Open with the Forem app