public void Test_GetColorNames()
        {
            var colors = ColorCodes.GetColorNames();

            colors.Should().NotBeNullOrEmpty();
            colors.Should().HaveCount(10);
        }
Пример #2
0
 public TCharAttr(AttributeBitMasks Attr, AttributeBitMasks Attr2, ColorCodes Fore, ColorCodes Back)
 {
     this.Attr  = Attr;
     this.Attr2 = Attr2;
     this.Fore  = Fore;
     this.Back  = Back;
 }
Пример #3
0
        public void BandBColorCodeTableLookupTest([ValueSource(typeof(OhnValueCalculatorTestData), "Colors")] ColorCodes x,
                                                  [ValueSourceAttribute(typeof(OhnValueCalculatorTestData), "BandBColumn")] Bands position,
                                                  [ValueSource(typeof(OhnValueCalculatorTestData), "BandBResults")] double ohm)
        {
            IOhmValueCalculator instance = CreateInstance();

            if (ohm >= 0)
            {
                var sutOhms = instance.TableLookup(x, position);
                Assert.AreEqual(sutOhms, ohm);
            }

            else
            {
                try
                {
                    var sutOhmsInvalid = instance.TableLookup(x, position);
                    Assert.AreEqual(true, false); //ohm < 0 denotes invalid table values, so it should not pass
                }
                catch
                {
                    Assert.AreEqual(true, true);//instead exception should occur
                }
            }
        }
Пример #4
0
        ////[TestCase("red", 1, 5)]
        ////[TestCase("red", 2, 100)]
        ////[TestCase("violet", 3, 4)]
        //[Test, Combinatorial]


        public void StringToEnumTest(string color, ColorCodes expectedCC)
        {
            ColorCodes sutColorCode = OhmValueCalculator.StringToEnum <ColorCodes>(color);

            //return sutColorCode;
            Assert.AreEqual(sutColorCode, expectedCC);
        }
Пример #5
0
        public int CalculateOhmValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor)
        {
            var color1 = ColorCodes.Parse(bandAColor);
            var color2 = ColorCodes.Parse(bandBColor);
            var color3 = ColorCodes.Parse(bandCColor);
            var color4 = ColorCodes.Parse(bandDColor);

            return(CalculateOhmValue(color1.FourBand.FirstPosition, color2.FourBand.SecondPosition, color3.FourBand.Multiplier));
        }
Пример #6
0
        public double[] FindTolerance(string bandDColor)
        {
            double[]   tolerance = new double[2];
            ColorCodes bandD     = StringToEnum <ColorCodes>(bandDColor);

            tolerance[0] = TableLookup(bandD, Bands.ToleranceDPositive);
            tolerance[1] = TableLookup(bandD, Bands.ToleranceDNegative);
            return(tolerance);
        }
Пример #7
0
        public void FindToleranceTest([ValueSource(typeof(OhnValueCalculatorTestData), "Colors")] ColorCodes x,
                                      [ValueSource(typeof(OhnValueCalculatorTestData), "BandDPositiveResults")] double positive,
                                      [ValueSource(typeof(OhnValueCalculatorTestData), "BandDResults")] double ohm)

        {
            //IOhmValueCalculator instance = CreateInstance();
            //double[] tolerance = instance.FindTolerance(x.ToString());
            //Assert.AreEqual(tolerance[0], positive);
            //Assert.AreEqual(tolerance[0], negative);
        }
        public ActionResult Calculator()
        {
            ViewBag.Message = "Electronic Color Code Calculator";
            ColorCodes colorCodes = new ColorCodes();

            Models.CalculatorViewModel viewModel = new Models.CalculatorViewModel();
            viewModel.ColorCodes = colorCodes.getColorCodes().Values;

            return(View(viewModel));
        }
Пример #9
0
 public virtual void SetCell(int Row, int Col, char c, ColorCodes ForeColor, ColorCodes BackColor, AttributeCodes Attribute)
 {
     if (Row < 0 || Row >= Rows || Col < 0 || Col >= Cols)
     {
         return;
     }
     TextData[Row, Col]      = c.ToString();
     ForeColorData[Row, Col] = ForeColor;
     BackColorData[Row, Col] = BackColor;
     AttributeData[Row, Col] = Attribute;
 }
Пример #10
0
        public double TableLookup(ColorCodes bandColor, Bands bandPosition)
        {
            int    column = (int)bandPosition + 1;
            double code   = ColorCodeTable[(int)bandColor, column];

            if (code < 0 && (bandPosition == Bands.SigDigA || bandPosition == Bands.SigDigB))
            {
                throw new ArgumentException("Invalid color placement");
            }

            return(code);
        }
Пример #11
0
 private MircColor colorize(ColorCodes colorCode)
 {
     if (color == String.Empty)
     {
         textColor = colorCode;
         color     = clear + (int)textColor;
     }
     else if (!color.Contains(','))
     {
         bgColor = colorCode;
         color   = clear + (int)textColor + "," + (int)bgColor;
     }
     return(this);
 }
Пример #12
0
        public int CalculateOhmValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor)
        {
            ColorCodes bandA = StringToEnum <ColorCodes>(bandAColor);
            ColorCodes bandB = StringToEnum <ColorCodes>(bandBColor);
            ColorCodes bandC = StringToEnum <ColorCodes>(bandCColor);
            ColorCodes bandD = StringToEnum <ColorCodes>(bandDColor);

            double bandAValue = TableLookup(bandA, Bands.SigDigA);
            double bandBValue = TableLookup(bandB, Bands.SigDigB);
            double bandCValue = TableLookup(bandC, Bands.MultiplierC);
            double bandDValue = TableLookup(bandD, Bands.ToleranceDNegative);

            int ohmValue = (int)((bandAValue * 10 + bandBValue) * bandCValue);

            return(ohmValue);
        }
Пример #13
0
        public ActionResult Index()
        {
            try
            {
                //Load dropdown values for Band A, Band B, Band C, and Band D
                ColorCodes colorCodes = new ColorCodes();

                //Return index view containing the color code calculator user interface
                return(View(colorCodes));
            }
            catch (Exception ex)
            {
                // if exception then return error as response
                return(Json(new { error = "Exception ocurred while loading select controls: " + ex.Message }));
            }
        }
Пример #14
0
        public MircColor Colorize(string colorName)
        {
            string[] colorCodesNames = Enum.GetNames(typeof(ColorCodes));

            string realColorName = colorCodesNames.FirstOrDefault(x => x.ToLower() == colorName.ToLower());

            if (realColorName != null)
            {
                ColorCodes newColor = (ColorCodes)Enum.Parse(typeof(ColorCodes), realColorName);
                return(colorize(newColor));
            }
            else
            {
                return(this);
            }
        }
Пример #15
0
 public static void Write(string str, char colouredChar)
 {
     char[] strArray = str.ToArray();
     foreach (var item in strArray)
     {
         if (item == colouredChar)
         {
             ColorCodes code = CurrentColorCode;
             Console.BackgroundColor = colorCodeDictionary[code];
             Console.Write(item);
             Console.BackgroundColor = ConsoleColor.Black;
         }
         else
         {
             Console.Write(item);
         }
     }
 }
        public void Test_Parse()
        {
            var result = ColorCodes.Parse("RED");

            result.Should().NotBeNull();
            result.Should().BeOfType <RedColorCode>();

            result = ColorCodes.Parse("white");
            result.Should().BeOfType <WhiteColorCode>();

            result = ColorCodes.Parse(" grey ");
            result.Should().BeOfType <GreyColorCode>();

            Action act = () => ColorCodes.Parse(String.Empty);

            act.Should().Throw <ArgumentNullException>();

            act = () => ColorCodes.Parse("CHARTREUSE");
            act.Should().Throw <ArgumentException>().And.Message.Should().Contain("Invalid color name specified");
        }
Пример #17
0
        public ActionResult GetResistanceValue(string bandAColor, string bandBColor, string bandCColor, string bandDColor)
        {
            try
            {
                ColorCodes colorCodes = new ColorCodes();
                // Call library method to calculcate the resistance value.
                double ohmValue = _ohmCalculator.CalculateOhmValue(bandAColor, bandBColor, bandCColor, bandDColor);

                var tolerance = colorCodes.Tolerance[bandDColor].Item2;

                string resistance = Formatters.FormatResistance(ohmValue, tolerance);

                /// return JSON response
                return(Json(new { resistance = resistance }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw ex;
            }
        }
        public void Test_Validate()
        {
            Action act = null;

            act = () => ColorCodes.Validate("");
            act.Should().Throw <ArgumentNullException>();

            act = () => ColorCodes.Validate(String.Empty);
            act.Should().Throw <ArgumentNullException>();

            act = () => ColorCodes.Validate(null);
            act.Should().Throw <ArgumentNullException>();

            act = () => ColorCodes.Validate("PINK");
            act.Should().Throw <ArgumentException>();

            act = () => ColorCodes.Validate("brown");
            act.Should().NotThrow();

            act = () => ColorCodes.Validate("RED");
            act.Should().NotThrow();
        }
        public ActionResult Calculator(Models.CalculatorViewModel viewModel)
        {
            ViewBag.Message = "Electronic Color Code Calculator";
            ColorCodes colorCodes = new ColorCodes();

            viewModel.ColorCodes = colorCodes.getColorCodes().Values;

            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            else
            {
                IOhmValueCalculator calculator = new OhmValueCalcuator(new ColorCodes());
                OhmRange            range      = calculator.CalculateOhmValueRange(viewModel.SelectedAColor, viewModel.SelectedBColor, viewModel.SelectedCColor, viewModel.SelectedDColor);

                viewModel.OhmValueMin = range.MinValue;
                viewModel.OhmValueMax = range.MaxValue;

                return(View(viewModel));
            }
        }
Пример #20
0
        public static string FormatResistance(double ohmValue, double tolerance)
        {
            ColorCodes colorCodes = new ColorCodes();
            string     resistance;

            //to show in Mega format
            if (ohmValue >= 100000000)
            {
                resistance = (ohmValue / 1000000).ToString("#,0M") + "Ω";
            }

            else if (ohmValue >= 10000000)
            {
                resistance = (ohmValue / 1000000).ToString("0.#") + "MΩ";
            }
            //to show in Kilo format
            else if (ohmValue >= 100000)
            {
                resistance = (ohmValue / 1000).ToString("#,0KΩ");
            }

            else if (ohmValue >= 10000)
            {
                resistance = (ohmValue / 1000).ToString("0.#") + "KΩ";
            }
            else
            {
                resistance = ohmValue.ToString() + "Ω";
            }

            if (ohmValue > 0)
            {
                resistance = resistance + "    " + " ±" + tolerance.ToString() + "%";
            }

            return(resistance);
        }
Пример #21
0
 public static string GetDescription(ColorCodes code)
 {
     return(Colors[(int)code]);
 }
Пример #22
0
 static void Main(string[] args)
 {
     int        intergerCode = 3;
     ColorCodes myColor      = (ColorCodes)intergerCode;
 }
Пример #23
0
        // Methods
        protected string GetTaskColorCode(bool isVip, DateTime created)
        {
            var dateDiff = (int)Math.Floor((DateTime.Now - created).TotalHours);

            return(ColorCodes.FirstOrDefault(c => c.Value == (isVip ? 3 : (dateDiff <= 2 ? dateDiff : 2))).Key);
        }
Пример #24
0
        public ColorCodes StringToEnumTest1(string color)
        {
            ColorCodes sutColorCode = OhmValueCalculator.StringToEnum <ColorCodes>(color);

            return(sutColorCode);
        }
Пример #25
0
 public static void SetColor(ColorCodes color)
 {
     SetConsoleTextAttribute(_handle, (int)color);
 }