public void NamedVersionWorks(byte red, byte green, byte blue, string nameValue) { var rgb = new RgbColor(red, green, blue); var name = rgb.Name; Assert.That(name.Value, Is.EqualTo(nameValue)); }
public void RgbVersionIsItself() { var original = new RgbColor(1, 2, 3); var copy = original.RedGreenBlue; Assert.That(original, Is.SameAs(copy)); }
//TODO: extension to convert a color to a wavelength measurement public static RgbColor FromHexString(string value) { if (value == null) { return null; } if (!value.StartsWith("#")) { return null; } if (value.Length != 7) { return null; } try { var red = HexToByte(value.Substring(1, 2)); var green = HexToByte(value.Substring(3, 2)); var blue = HexToByte(value.Substring(5, 2)); var result = new RgbColor(red, green, blue); return result; } catch (FormatException) { return null; } }
public void ItConvertsColorsToNames(byte red, byte green, byte blue, params string[] expected) { var color = new RgbColor(red, green, blue); var actual = _dictionary.Find(color); CollectionAssert.AreEqual(expected, actual); }
public void ItConvertsAnInvalidColorToAnEmptyList(byte red, byte green, byte blue) { var color = new RgbColor(red, green, blue); var actual = _dictionary.Find(color); CollectionAssert.IsEmpty(actual); }
public void ItSavesValuesCorrectly() { var color = new RgbColor(1, 2, 3); Assert.That(color.Red, Is.EqualTo(1)); Assert.That(color.Green, Is.EqualTo(2)); Assert.That(color.Blue, Is.EqualTo(3)); }
public IEnumerable<string> Find(RgbColor color) { if (color == null) { return null; } if (!_colorToName.ContainsKey(color)) { return new string[0]; } var result = _colorToName[color]; return result; }
public IEnumerable <string> Find(RgbColor color) { if (color == null) { return(null); } if (!_colorToName.ContainsKey(color)) { return(new string[0]); } var result = _colorToName[color]; return(result); }
public bool Equals(RgbColor other) { if (Red != other.Red) { return false; } if (Green != other.Green) { return false; } if (Blue != other.Blue) { return false; } return true; }
public bool Equals(RgbColor other) { if (Red != other.Red) { return(false); } if (Green != other.Green) { return(false); } if (Blue != other.Blue) { return(false); } return(true); }
private void Add(string name, RgbColor color) { name = name.ToLower(); _nameToColor.Add(name, color); List<string> namesForThisColor; if (_colorToName.ContainsKey(color)) { namesForThisColor = _colorToName[color]; } else { namesForThisColor = new List<string>(); _colorToName.Add(color, namesForThisColor); } namesForThisColor.Add(name); }
private void Add(string name, RgbColor color) { name = name.ToLower(); _nameToColor.Add(name, color); List <string> namesForThisColor; if (_colorToName.ContainsKey(color)) { namesForThisColor = _colorToName[color]; } else { namesForThisColor = new List <string>(); _colorToName.Add(color, namesForThisColor); } namesForThisColor.Add(name); }
public void ToHexStringWorks(string hexValue, byte red, byte green, byte blue) { var rgb = new RgbColor(red, green, blue); var actual = rgb.ToHexString(); Assert.That(actual, Is.EqualTo(hexValue)); }