public void Parse_InvalidStringResistorColor_ShouldThrowException()
 {
     Assert.Throws <Exception>(() =>
     {
         ResistorColorCode.ParseResistorColor("InvalidColor");
     });
 }
Esempio n. 2
0
        // Leaving "colorBandD" in the argument list since I don't want to change the original interface given in the problem. Depending on requirements,
        // the calculation below could be changed so that the resistance value is calculated based on the minimum tolerance range to ensure reliability.
        public double CalculateOhmValues(string colorBandA, string colorBandB, string colorBandC, string colorBandD)
        {
            var resistorBandA = _repository.FindBy(ResistorColorCode.ParseResistorColor(colorBandA));
            var resistorBandB = _repository.FindBy(ResistorColorCode.ParseResistorColor(colorBandB));
            var resistorBandC = _repository.FindBy(ResistorColorCode.ParseResistorColor(colorBandC));

            var digitValue = (resistorBandA.SignificantFigures.Value * 10 + resistorBandB.SignificantFigures.Value);
            var ohmValue   = digitValue * (decimal)resistorBandC.Multiplier.Value;

            return((double)ohmValue);
        }
        public ActionResult Calculate(OhmValueCalculatorPostModel postModel)
        {
            var ohmValue = _ohmValueCalculator.CalculateOhmValues(postModel.ColorBandA, postModel.ColorBandB,
                                                                  postModel.ColorBandC, postModel.ColorBandD);

            var tolerance = _resistorColorCodeRepository
                            .FindBy(ResistorColorCode.ParseResistorColor(postModel.ColorBandD))
                            .Tolerance;

            return(Json(new OhmValueCalculatorResponseModel
            {
                OhmValue = ohmValue.ToFormattedString(),
                Tolerance = tolerance?.ToString("P")
            }));
        }
        public void Parse_StringResistorColor_ReturnsCorrectResistorColorEnum()
        {
            var resistorColor = ResistorColorCode.ParseResistorColor("Black");

            resistorColor.ShouldBe(ResistorColor.Black);
        }