public Sequence SearchLongestSequenceOfEqualNumbers(List<int> numbers,Sequence sequence)
        {
            int length = 1;
            int number = numbers[0];
            sequence.EqualNumber = numbers[0];
            sequence.Length = 1;
            for (int i = 1; i < numbers.Count; i++)
            {
                if (numbers[i] == numbers[i - 1])
                {
                    length++;
                }

                if (numbers[i] != numbers[i - 1] && length > sequence.Length)
                {
                    sequence.Length = length;
                    sequence.EqualNumber = numbers[i - 1];
                    length = 1;
                }

                if (length >= sequence.Length &&
                    numbers[i] == numbers[i - 1] &&
                    i == numbers.Count - 1)
                {
                    sequence.EqualNumber = numbers[i];
                    sequence.Length = length;
                    length = 1;
                }
            }

            return sequence;
        }
 public void TestSearcherToCountThreNumbersAndValue()
 {
     List<int> numbers = new List<int>();
     numbers = new List<int> { 0, 0, 0 };
     Sequence sequence = new Sequence();
     Searcher searcher = new Searcher();
     sequence = searcher.SearchLongestSequenceOfEqualNumbers(numbers, sequence);
     Assert.AreEqual(sequence.Length, 3);
     Assert.AreEqual(sequence.EqualNumber, 0);
 }
 public void TestSearcherToCountThreeEqualNumbersAtTheBeginingAndReturnRightValue()
 {
     List<int> numbers = new List<int>();
     numbers = new List<int> {2, 2, 2, 3, -2, -1, -1 };
     Sequence sequence = new Sequence();
     Searcher searcher = new Searcher();
     sequence = searcher.SearchLongestSequenceOfEqualNumbers(numbers, sequence);
     Assert.AreEqual(sequence.Length, 3);
     Assert.AreEqual(sequence.EqualNumber, 2);
 }
 public void TestSearcherToCountOneNumbersAndReturnRightValue()
 {
     List<int> numbers = new List<int>();
     numbers = new List<int> { 2 };
     Sequence sequence = new Sequence();
     Searcher searcher = new Searcher();
     sequence = searcher.SearchLongestSequenceOfEqualNumbers(numbers, sequence);
     Assert.AreEqual(sequence.Length, 1);
     Assert.AreEqual(sequence.EqualNumber, 2);
 }
 public static void Main()
 {
     List<int> numbers = new List<int>();
     numbers = new List<int> { 2, 3, -2, -1, -1 };
     // numbers = new List<int> { 2, 3, -2, -2, -2, -1, -1 };
     // numbers = new List<int> { 2, 3, -2, -1};
     // numbers = new List<int> { 2 };
     // numbers = new List<int> { 2, 2, 2, 3, -2, -1, -1 };
     // EnterNumbers(numbers);
     Sequence sequence = new Sequence();
     Searcher searcher = new Searcher();
     sequence = searcher.SearchLongestSequenceOfEqualNumbers(numbers, sequence);
     PrintSequence(sequence.EqualNumber, sequence.Length);
 }