コード例 #1
0
        public void TestWrongBandColorResistors()
        {
            // Tests that we expect to return false.
            //Array format: bandAColor, bandBColor, bandCColor, bandDColor, correctResult
            string[][] bands = new string[3][];
            bands[0] = new string[] { "Red", "Red", "Orange", "Gold", "220" };
            bands[1] = new string[] { "Yellow", "Violet", "Brown", "Gold", "47" };
            bands[2] = new string[] { "Blue", "Gray", "Black", "Gold", "680" };

            foreach (var band in bands)
            {
                int    ohms      = new OhmCalculatorClass().CalculateOhmValue(band[0], band[1], band[2], band[3]);
                bool   result    = ohms.ToString().Equals(band[4]);
                string colorBand = band[0] + ", " + band[1] + ", " + band[2] + ", " + band[3];
                Assert.IsFalse(result,
                               String.Format("Expected for ({0}): {1}; Actual: {2}",
                                             colorBand, band[4], ohms));
            }
        }
コード例 #2
0
        public ActionResult Index(string bandAColorList, string bandBColorList, string MultiplierBandColorList, string ToleranceBandColorList)
        {
            string ohms                        = "";
            string message                     = "";
            string BandAColorSelected          = "Brown";
            string BandBColorSelected          = "Black";
            string MultiplierBandColorSelected = "Black";
            string ToleranceBandColorSelected  = "Brown";

            if (bandAColorList != null && bandBColorList != null && MultiplierBandColorList != null && ToleranceBandColorList != null)
            {
                try
                {
                    ohms                        = new OhmCalculatorClass().CalculateOhmAndTolerance(bandAColorList, bandBColorList, MultiplierBandColorList, ToleranceBandColorList);
                    message                     = "Resistor Value:";
                    BandAColorSelected          = bandAColorList;
                    BandBColorSelected          = bandBColorList;
                    MultiplierBandColorSelected = MultiplierBandColorList;
                    ToleranceBandColorSelected  = ToleranceBandColorList;
                }
                catch (ResistorBandColorException)
                {
                    message = "Wrong color band configuration";
                }
            }
            var model = new OhmViewModel {
                Message                     = message,
                OhmValue                    = ohms,
                BandAColorSelected          = BandAColorSelected,
                BandBColorSelected          = BandBColorSelected,
                MultiplierBandColorSelected = MultiplierBandColorSelected,
                ToleranceBandColorSelected  = ToleranceBandColorSelected,
            };

            return(View(model));
        }
コード例 #3
0
 public void TestColorWithoutMultiplier()
 {
     // Tests that we expect to throw ResistorBandColorException.
     int ohms = new OhmCalculatorClass().CalculateOhmValue("Red", "Red", "Gray", "Gold");
 }
コード例 #4
0
 public void TestFirstBandWithoutSignificantDigit()
 {
     // Tests that we expect to throw ResistorBandColorException.
     int ohms = new OhmCalculatorClass().CalculateOhmValue("Gold", "Red", "Orange", "Gold");
 }
コード例 #5
0
 public void TestNonExistenceColor()
 {
     // Tests that we expect to throw ResistorBandColorException.
     int ohms = new OhmCalculatorClass().CalculateOhmValue("Red", "Red", "Orange", "Purple");
 }