Beispiel #1
0
        public LongSeriesTestResult LongSeriesTests(string s)
        {
            if (s.Length != bitsLength)
            {
                throw new ArgumentException("Length of array must be 20000/8");
            }

            foreach (var item in s)
            {
                if (item != '1' && item != '0')
                {
                    throw new ArgumentException("Znaleziono zły znak: " + item);
                }
            }


            char temp      = s[0];
            int  series    = 1;
            int  maxSeries = 1;

            for (int i = 1; i < s.Length; i++)
            {
                if (s[i] == temp)
                {
                    series++;
                    temp = s[i];
                }
                else
                {
                    if (series > maxSeries)
                    {
                        maxSeries = series;
                    }
                    series = 1;
                    temp   = s[i];
                }
            }

            LongSeriesTestResult result = new LongSeriesTestResult();

            result.LongestSeries = maxSeries;
            if (maxSeries >= 26)
            {
                result.TestPassed = false;
            }
            else
            {
                result.TestPassed = true;
            }

            return(result);
        }
Beispiel #2
0
        public LongSeriesTestResult LongSeriesTests(byte[] input)
        {
            if (input.Length != bitsLength / 8)
            {
                throw new ArgumentException("Length of array must be 20000/8");
            }

            string s = String.Join("", input.Select(x => Convert.ToString(x, 2).PadLeft(8, '0')));

            char temp      = s[0];
            int  series    = 1;
            int  maxSeries = 1;

            for (int i = 1; i < s.Length; i++)
            {
                if (s[i] == temp)
                {
                    series++;
                    temp = s[i];
                }
                else
                {
                    if (series > maxSeries)
                    {
                        maxSeries = series;
                    }
                    series = 1;
                    temp   = s[i];
                }
            }

            LongSeriesTestResult result = new LongSeriesTestResult();

            result.LongestSeries = maxSeries;
            if (maxSeries >= 26)
            {
                result.TestPassed = false;
            }
            else
            {
                result.TestPassed = true;
            }

            return(result);
        }