コード例 #1
0
 public void Parse_InvalidStringResistorColor_ShouldThrowException()
 {
     Assert.Throws <Exception>(() =>
     {
         ResistorColorCode.ParseResistorColor("InvalidColor");
     });
 }
コード例 #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);
        }
コード例 #3
0
        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")
            }));
        }
コード例 #4
0
        public void Parse_StringResistorColor_ReturnsCorrectResistorColorEnum()
        {
            var resistorColor = ResistorColorCode.ParseResistorColor("Black");

            resistorColor.ShouldBe(ResistorColor.Black);
        }