Exemplo n.º 1
0
        public void TestRunLengthEncodeResults()
        {
            var sequence = new[] { 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6 };
            var expectedResult = Enumerable.Range(1, 6).Select(x => new KeyValuePair<int, int>(x, x));
            var result = sequence.RunLengthEncode();

            Assert.IsTrue(result.SequenceEqual(expectedResult));
        }
Exemplo n.º 2
0
        public void TestRunLengthEncodeCustomComparer()
        {
            var sequence = new[] { "a", "A", "a", "b", "b", "B", "B" };
            var result = sequence.RunLengthEncode(StringComparer.CurrentCultureIgnoreCase)
                                 .Select(kvp => new KeyValuePair<string, int>(kvp.Key.ToLower(), kvp.Value));
            var expectedResult = new[] {new KeyValuePair<string, int>("a", 3), 
                                         new KeyValuePair<string, int>("b", 4)};

            Assert.IsTrue(result.SequenceEqual(expectedResult));
        }