예제 #1
0
        public void MinimumResistanceTest()
        {
            IOhmValueCalculator Calculator = new CalculateResistance();
            double result = Calculator.CalculateOhmValue("brown", "brown", "pink", "gray");

            Assert.AreEqual("0.011005499999999998", result);
        }
예제 #2
0
        public void BasicColorTest()
        {
            IOhmValueCalculator Calculator = new CalculateResistance();
            double result = Calculator.CalculateOhmValue("brown", "red", "orange", "yellow");

            Assert.AreEqual("12600", result);
        }
예제 #3
0
        public void MaximumResistanceTest()
        {
            IOhmValueCalculator Calculator = new CalculateResistance();
            double result = Calculator.CalculateOhmValue("white", "white", "white", "silver");

            Assert.AreEqual("108900000000.00002", result);
        }
        public ActionResult GetResistanceValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor)
        {
            try
            {
                // initialize interface object
                IOhmValueCalculator objResistance = new CalculateResistance();

                // Call the method that calculates resistance value in ColorCodeCalculator class library
                double resultObject = objResistance.CalculateOhmValue(bandAColor, bandBColor, bandCColor, bandDColor);

                /// return JSON response
                return(Json(new { value = resultObject }));
            }
            catch (Exception ex)
            {
                return(Json(new { error = "Error when calculating resistance value: " + ex.Message }));
            }
        }
예제 #5
0
        public void NullTest()
        {
            Exception result = null;

            try
            {
                IOhmValueCalculator Calculator = new CalculateResistance();

                Calculator.CalculateOhmValue(null, null, null, null);
            }
            catch (Exception ex)
            {
                result = ex;
                throw;
            }

            Assert.IsInstanceOfType(result, typeof(ArgumentException));
        }