public virtual void TestRandomBinaryRoundTrip() { sbyte[] binary = new sbyte[MAX_RANDOM_BINARY_LENGTH]; char[] encoded = new char[MAX_RANDOM_BINARY_LENGTH * 10]; sbyte[] decoded = new sbyte[MAX_RANDOM_BINARY_LENGTH]; for (int testNum = 0; testNum < NUM_RANDOM_TESTS; ++testNum) { int numBytes = Random().Next(MAX_RANDOM_BINARY_LENGTH - 1) + 1; // Min == 1 for (int byteNum = 0; byteNum < numBytes; ++byteNum) { binary[byteNum] = (sbyte)Random().Next(0x100); } int encodedLen = IndexableBinaryStringTools.GetEncodedLength(binary, 0, numBytes); if (encoded.Length < encodedLen) { encoded = new char[ArrayUtil.Oversize(encodedLen, RamUsageEstimator.NUM_BYTES_CHAR)]; } IndexableBinaryStringTools.Encode(binary, 0, numBytes, encoded, 0, encodedLen); int decodedLen = IndexableBinaryStringTools.GetDecodedLength(encoded, 0, encodedLen); IndexableBinaryStringTools.Decode(encoded, 0, encodedLen, decoded, 0, decodedLen); Assert.AreEqual(BinaryDump(binary, numBytes), BinaryDump(decoded, decodedLen), "Test #" + (testNum + 1) + ": Round trip decode/decode returned different results:" + "\n original: " + BinaryDump(binary, numBytes) + "\nencodedBuf: " + CharArrayDump(encoded, encodedLen) + "\ndecodedBuf: " + BinaryDump(decoded, decodedLen)); } }
public virtual void TestAllNullInput() { sbyte[] binary = new sbyte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int encodedLen = IndexableBinaryStringTools.GetEncodedLength(binary, 0, binary.Length); char[] encoded = new char[encodedLen]; IndexableBinaryStringTools.Encode(binary, 0, binary.Length, encoded, 0, encoded.Length); int decodedLen = IndexableBinaryStringTools.GetDecodedLength(encoded, 0, encoded.Length); sbyte[] decoded = new sbyte[decodedLen]; IndexableBinaryStringTools.Decode(encoded, 0, encoded.Length, decoded, 0, decoded.Length); Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), "Round trip decode/decode returned different results:" + "\n original: " + BinaryDump(binary, binary.Length) + "\ndecodedBuf: " + BinaryDump(decoded, decoded.Length)); }
public virtual void TestSingleBinaryRoundTrip() { sbyte[] binary = new sbyte[] { (sbyte)0x23, unchecked((sbyte)0x98), (sbyte)0x13, unchecked((sbyte)0xE4), (sbyte)0x76, (sbyte)0x41, unchecked((sbyte)0xB2), unchecked((sbyte)0xC9), (sbyte)0x7F, (sbyte)0x0A, unchecked((sbyte)0xA6), unchecked((sbyte)0xD8) }; int encodedLen = IndexableBinaryStringTools.GetEncodedLength(binary, 0, binary.Length); char[] encoded = new char[encodedLen]; IndexableBinaryStringTools.Encode(binary, 0, binary.Length, encoded, 0, encoded.Length); int decodedLen = IndexableBinaryStringTools.GetDecodedLength(encoded, 0, encoded.Length); sbyte[] decoded = new sbyte[decodedLen]; IndexableBinaryStringTools.Decode(encoded, 0, encoded.Length, decoded, 0, decoded.Length); Assert.AreEqual(BinaryDump(binary, binary.Length), BinaryDump(decoded, decoded.Length), "Round trip decode/decode returned different results:\noriginal: " + BinaryDump(binary, binary.Length) + "\n encoded: " + CharArrayDump(encoded, encoded.Length) + "\n decoded: " + BinaryDump(decoded, decoded.Length)); }
public virtual void TestEmptyInput() { sbyte[] binary = new sbyte[0]; int encodedLen = IndexableBinaryStringTools.GetEncodedLength(binary, 0, binary.Length); char[] encoded = new char[encodedLen]; IndexableBinaryStringTools.Encode(binary, 0, binary.Length, encoded, 0, encoded.Length); int decodedLen = IndexableBinaryStringTools.GetDecodedLength(encoded, 0, encoded.Length); sbyte[] decoded = new sbyte[decodedLen]; IndexableBinaryStringTools.Decode(encoded, 0, encoded.Length, decoded, 0, decoded.Length); Assert.AreEqual(decoded.Length, 0, "decoded empty input was not empty"); }