public PokerTestResult PokerTest(string input) { if (input.Length != bitsLength) { throw new ArgumentException("Length of string must be 20000"); } foreach (var item in input) { if (item != '1' && item != '0') { throw new ArgumentException("Znaleziono zły znak: " + item); } } int[] valueArray = new int[16]; for (int i = 0; i < input.Length; i += 4) { string tempString = input.Substring(i, 4); int value = Convert.ToInt32(tempString, 2); valueArray[value]++; } int sum = 0; for (int i = 0; i < valueArray.Length; i++) { sum += (valueArray[i] * valueArray[i]); } double X = (16.0 / 5000.0) * sum - 5000.0; PokerTestResult result = new PokerTestResult(); result.ValueArray = valueArray; result.Result = X; if (X > 2.16 && X < 46.17) { result.TestPassed = true; } else { result.TestPassed = false; } return(result); }
public PokerTestResult PokerTest(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'))); Console.WriteLine(s); int[] valueArray = new int[16]; for (int i = 0; i < s.Length; i += 4) { string tempString = s.Substring(i, 4); byte value = Convert.ToByte(tempString, 2); valueArray[value]++; } int sum = 0; for (int i = 0; i < valueArray.Length; i++) { sum += (valueArray[i]) * (valueArray[i]); } double X = (16.0 / 5000.0) * sum - 5000.0; PokerTestResult result = new PokerTestResult(); result.ValueArray = valueArray; result.Result = X; if (X > 2.16 && X < 46.17) { result.TestPassed = true; } else { result.TestPassed = false; } return(result); }