public void TestColorValueConversion() { // Color Value Codes string colorBlack = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Black); Assert.IsTrue(colorBlack == Color.Black.Name); string colorBrown = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Brown); Assert.IsTrue(colorBrown == Color.Brown.Name); string colorRed = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Red); Assert.IsTrue(colorRed == Color.Red.Name); string colorOrange = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Orange); Assert.IsTrue(colorOrange == Color.Orange.Name); string colorYellow = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Yellow); Assert.IsTrue(colorYellow == Color.Yellow.Name); string colorGreen = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Green); Assert.IsTrue(colorGreen == Color.Green.Name); string colorBlue = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Blue); Assert.IsTrue(colorBlue == Color.Blue.Name); string colorViolet = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Violet); Assert.IsTrue(colorViolet == Color.Violet.Name); string colorGray = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Gray); Assert.IsTrue(colorGray == Color.Gray.Name); string colorWhite = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.White); Assert.IsTrue(colorWhite == Color.White.Name); // Color Tolerance Codes string pctColorBrown = ResistanceColorCode.ToleranceValueToString(ResistanceColorCode.ColorPercentToleranceCode.Brown); Assert.IsTrue(pctColorBrown == Color.Brown.Name); string pctColorRed = ResistanceColorCode.ToleranceValueToString(ResistanceColorCode.ColorPercentToleranceCode.Red); Assert.IsTrue(pctColorRed == Color.Red.Name); }
public ResistanceColorCode GetColorCode(string color) { try { using (var context = new ElectronicsCalculatorDbContext()) { ResistanceColorCode code = new ResistanceColorCode(); code = (from c in context.ResistanceColorCodes where c.RingColor.Equals(color) select c).FirstOrDefault(); return(code); } } catch (Exception) { throw; } }
public void TestOhmValueCalculation() { string color_band_A = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Brown); string color_band_B = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Green); string color_band_C = ResistanceColorCode.ValueToString(ResistanceColorCode.ColorValueCode.Red); string color_band_D = ResistanceColorCode.ToleranceValueToString(ResistanceColorCode.ColorPercentToleranceCode.Silver); double[] results = calculator.CalculateOhmValue( color_band_A, color_band_B, color_band_C, color_band_D); // Check value = 1500 double expectedVal = 1500; Assert.IsTrue(results[0] == expectedVal); // check tolerance = 10 double expectedTol = 10; Assert.IsTrue(results[1] == expectedTol); }