예제 #1
0
        public SeriesTestResult SeriesTest(string input)
        {
            if (input.Length != bitsLength)
            {
                throw new ArgumentException("Length of array must be 20000/8");
            }

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

            int[] seriesOneArray = new int[6] {
                0, 0, 0, 0, 0, 0
            };
            int[] seriesZeroArray = new int[6] {
                0, 0, 0, 0, 0, 0
            };

            int series = 1;

            char temp = input[0];


            bool isOne = temp == '1';



            for (int i = 1; i < input.Length; i++)
            {
                if (input[i] == temp)
                {
                    series++;
                    temp = input[i];
                }
                else
                {
                    if (series >= 6)
                    {
                        if (isOne)
                        {
                            seriesOneArray[5]++;
                        }
                        else
                        {
                            seriesZeroArray[5]++;
                        }
                    }
                    else
                    {
                        if (isOne)
                        {
                            seriesOneArray[series - 1]++;
                        }
                        else
                        {
                            seriesZeroArray[series - 1]++;
                        }
                    }

                    temp   = input[i];
                    series = 1;
                    isOne  = !isOne;
                }

                if (i == input.Length - 1)
                {
                    if (series >= 6)
                    {
                        if (isOne)
                        {
                            seriesOneArray[5]++;
                        }
                        else
                        {
                            seriesZeroArray[5]++;
                        }
                    }
                    else
                    {
                        if (isOne)
                        {
                            seriesOneArray[series - 1]++;
                        }
                        else
                        {
                            seriesZeroArray[series - 1]++;
                        }
                    }
                }
            }

            SeriesTestResult result = new SeriesTestResult();

            result.SeriesOneArray  = seriesOneArray;
            result.SeriesZeroArray = seriesZeroArray;

            if (seriesOneArray[0] >= 2315 && seriesOneArray[0] <= 2685 && seriesOneArray[1] >= 1114 && seriesOneArray[1] <= 1386 && seriesOneArray[2] >= 527 && seriesOneArray[2] <= 723 &&
                seriesOneArray[3] >= 240 && seriesOneArray[3] <= 384 && seriesOneArray[4] >= 103 && seriesOneArray[4] <= 209 && seriesOneArray[5] >= 103 && seriesOneArray[5] <= 209 &&
                seriesZeroArray[0] >= 2315 && seriesZeroArray[0] <= 2685 && seriesZeroArray[1] >= 1114 && seriesZeroArray[1] <= 1386 && seriesZeroArray[2] >= 527 && seriesZeroArray[2] <= 723 &&
                seriesZeroArray[3] >= 240 && seriesZeroArray[3] <= 384 && seriesZeroArray[4] >= 103 && seriesZeroArray[4] <= 209 && seriesZeroArray[5] >= 103 && seriesZeroArray[5] <= 209)
            {
                result.TestPassed = true;
            }
            else
            {
                result.TestPassed = false;
            }

            return(result);
        }
예제 #2
0
        public SeriesTestResult SeriesTest(byte[] inputBytes)
        {
            if (inputBytes.Length != bitsLength / 8)
            {
                throw new ArgumentException("Length of array must be 20000/8");
            }

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

            int[] seriesOneArray = new int[6] {
                0, 0, 0, 0, 0, 0
            };
            int[] seriesZeroArray = new int[6] {
                0, 0, 0, 0, 0, 0
            };

            int series = 1;

            char temp  = input[0];
            bool isOne = temp == '1';

            for (int i = 1; i < input.Length; i++)
            {
                if (input[i] == temp)
                {
                    series++;
                    temp = input[i];
                }
                else
                {
                    if (series >= 6)
                    {
                        if (isOne)
                        {
                            seriesOneArray[5]++;
                        }
                        else
                        {
                            seriesZeroArray[5]++;
                        }
                    }
                    else
                    {
                        if (isOne)
                        {
                            seriesOneArray[series - 1]++;
                        }
                        else
                        {
                            seriesZeroArray[series - 1]++;
                        }
                    }

                    temp   = input[i];
                    series = 1;
                    isOne  = !isOne;
                }

                if (i == input.Length - 1)
                {
                    if (series >= 6)
                    {
                        if (isOne)
                        {
                            seriesOneArray[5]++;
                        }
                        else
                        {
                            seriesZeroArray[5]++;
                        }
                    }
                    else
                    {
                        if (isOne)
                        {
                            seriesOneArray[series - 1]++;
                        }
                        else
                        {
                            seriesZeroArray[series - 1]++;
                        }
                    }
                }
            }

            SeriesTestResult result = new SeriesTestResult();

            result.SeriesOneArray  = seriesOneArray;
            result.SeriesZeroArray = seriesZeroArray;

            if (seriesOneArray[0] >= 2315 && seriesOneArray[0] <= 2685 && seriesOneArray[1] >= 1114 && seriesOneArray[1] <= 1386 && seriesOneArray[2] >= 527 && seriesOneArray[2] <= 723 &&
                seriesOneArray[3] >= 240 && seriesOneArray[3] <= 384 && seriesOneArray[4] >= 103 && seriesOneArray[4] <= 209 && seriesOneArray[5] >= 103 && seriesOneArray[5] <= 209 &&
                seriesZeroArray[0] >= 2315 && seriesZeroArray[0] <= 2685 && seriesZeroArray[1] >= 1114 && seriesZeroArray[1] <= 1386 && seriesZeroArray[2] >= 527 && seriesZeroArray[2] <= 723 &&
                seriesZeroArray[3] >= 240 && seriesZeroArray[3] <= 384 && seriesZeroArray[4] >= 103 && seriesZeroArray[4] <= 209 && seriesZeroArray[5] >= 103 && seriesZeroArray[5] <= 209)
            {
                result.TestPassed = true;
            }
            else
            {
                result.TestPassed = false;
            }

            return(result);
        }