示例#1
0
        public void TestGetMinResistance_WithKnownValue()
        {
            Services.UseCase.ResistorComputations resistor = new Services.UseCase.ResistorComputations(new Infrastructure.ExceptionManager.DatabaseLogger());
            double maxResistance = 0;

            maxResistance = resistor.GetMinResistance(10.0, 10);

            Assert.IsTrue(maxResistance == 9);
        }
示例#2
0
        public void TestResistance_WithKnownValue()
        {
            Services.UseCase.ResistorComputations resistor = new Services.UseCase.ResistorComputations(new Infrastructure.ExceptionManager.DatabaseLogger());
            double resistance = 0;

            resistance = resistor.GetResistance(26, 0);

            Assert.IsTrue(resistance == 26);
        }
        public JsonResult CalculateOhms(List <string> selectedColors)
        {
            Services.UseCase.ResistorComputations resistor = new Services.UseCase.ResistorComputations(new Infrastructure.ExceptionManager.FileLogger());


            // This section will return the computation results for a 4 strip resistor
            if (selectedColors.Count == 4)
            {
                var results = resistor.GetAllComputedValues(selectedColors[0], selectedColors[1], selectedColors[2], selectedColors[3]);

                return(Json(new
                {
                    Resistance = results.resistance,
                    Tolerance = results.tolerance,
                    MaxResistance = results.maxresistance,
                    MinResistance = results.minresistance
                }));
            }


            // If we wanted to design for the other resistor types (5,6 band) we could place the code in the following
            // section for count = 5,6... although I would refactor this by modifying the IOhmValueCalculator interface
            // to accomodate all the resistor types.
            if (selectedColors.Count == 5)
            {
                // 5,6 color resistor code would be implemented here...

                return(Json(new
                {
                    Resistance = 0,
                    Tolerance = 0,
                    MaxResistance = 0,
                    MinResistance = 0
                }));
            }


            // -------------------------------------------------


            // If an undefined resistor type is submitted, return blank results.
            return(Json(new
            {
                Resistance = 0,
                Tolerance = 0,
                MaxResistance = 0,
                MinResistance = 0
            }));
        }
示例#4
0
        public void TestAllValidToleranceColors()
        {
            Services.UseCase.ResistorComputations resistor = new Services.UseCase.ResistorComputations(new Infrastructure.ExceptionManager.DatabaseLogger());
            List <string> colors = new List <string>()
            {
                "Brown", "Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Gray", "Gold", "Silver"
            };
            double multiplier = 0;

            for (int i = 0; i < colors.Count; i++)
            {
                multiplier = resistor.GetTolerance(colors[i]);

                Assert.IsTrue(multiplier != -33);
            }
        }
示例#5
0
        public void CalculateOhmValue()
        {
            Services.UseCase.ResistorComputations resistor = new Services.UseCase.ResistorComputations(new Infrastructure.ExceptionManager.DatabaseLogger());
            Dictionary <string, int> banda = new Dictionary <string, int>();
            Dictionary <string, int> bandb = new Dictionary <string, int>();
            int result = 0;

            // Assign test data
            banda.Add("Brown", 1);
            banda.Add("Red", 2);
            banda.Add("Orange", 3);
            banda.Add("Yellow", 4);
            banda.Add("Green", 5);
            banda.Add("Blue", 6);
            banda.Add("Violet", 7);
            banda.Add("Gray", 8);
            banda.Add("White", 9);

            bandb.Add("Black", 0);
            bandb.Add("Brown", 1);
            bandb.Add("Red", 2);
            bandb.Add("Orange", 3);
            bandb.Add("Yellow", 4);
            bandb.Add("Green", 5);
            bandb.Add("Blue", 6);
            bandb.Add("Violet", 7);
            bandb.Add("Gray", 8);
            bandb.Add("White", 9);


            for (int i = 0; i < banda.Count; i++)
            {
                result = resistor.CalculateOhmValue(banda.ElementAt(i).Key, "blue", "red", "gold");

                Assert.IsTrue(result == Convert.ToInt32(banda.ElementAt(i).Value.ToString() + "6"));
            }

            for (int i = 0; i < bandb.Count; i++)
            {
                result = resistor.CalculateOhmValue("blue", bandb.ElementAt(i).Key, "red", "gold");

                Assert.IsTrue(result == Convert.ToInt32("6" + bandb.ElementAt(i).Value.ToString()));
            }
        }