1
public static int ConvertToInt(string str, int firstIndex, int lenOfString)
    {
            int Stop = firstIndex + lenOfString;
            int Value = 0;
            bool isNegative = false;

            for (int i = firstIndex; i < Stop; i++)
             {
                    if (i == 0 && str[i] == '-')
                        {
                                isNegative = true;
                                continue;
                        }
                    if (str[i] < '0' || str[i] > '9')
                            throw new FormatException("Sorry!! It is not in Numeric Format.");

                        Value = (Value * 10) + (str[i] - 48);
                }

                    if (isNegative)
                        return (Value * -1);

            return Value;
    }

Above one is my part of code:

In above program I am converting string into Int. I go through from Here:

As I am new in Testing.I want to write all the possible positive and negative test cases for above program.for Testing purpose I am using NUnit framework.

How do I complete it?

Any help is appreciated.

Community
  • 1
  • 1
Ankit Raman
  • 79
  • 1
  • 14
  • Why would you want to do that? There is an infinite number of possibilities. Your tests should concentrate less on the happy trail and more on the error states. For instance ConvertToInt("-2", 0, 7) will throw an IndexOutOfBounds exception. That's much more valuable to know than the fact that it passes for 1000 positive and negative numbers. Write test to find bugs, not to validate code. – Palle Due Feb 23 '17 at 11:36
  • @PalleDue , If possible then please give me some more examples so that I could apply my ideas for further possibilities. – Ankit Raman Feb 23 '17 at 11:44

0 Answers0