Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public void RgbVersionIsItself()
        {
            var original = new RgbColor(1, 2, 3);
            var copy = original.RedGreenBlue;

            Assert.That(original, Is.SameAs(copy));
        }
Esempio n. 3
0
        //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;
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public void ItConvertsAnInvalidColorToAnEmptyList(byte red, byte green, byte blue)
        {
            var color = new RgbColor(red, green, blue);
            var actual = _dictionary.Find(color);

            CollectionAssert.IsEmpty(actual);
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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;
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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;
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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));
        }