How to write unit tests for testing some method.

Jan 29 2022 7:40 PM

Task is to write unit tests for testing the KwHpConverter method. It is possible to use the software framework as desired. It is necessary to define a larger number of test cases and try to find a test case that will end in failure. Errors that you detect in the testing process need to be corrected. Here is code an methode:

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {

            double result = 0;

            Console.WriteLine("Please, enter value: ");
            double value = double.Parse(Console.ReadLine());

            Console.WriteLine("Convert to (enter kw or hp(sad)");
            string convertTo = Console.ReadLine();

            if(convertTo == "kw")
            {
                result = KwHpConverter(value, "kw");
            } else
            {
                result = KwHpConverter(value, "hp");
            }

            Console.WriteLine(result);

        }

        private static double KwHpConverter (double inputValue, string convertTo)
        {
            if(convertTo == "hp")
            {
                return inputValue / 0.745699872;
            } else
            {
                return inputValue * 0.745699872;
            }
        }

    }

}

 


Answers (3)