public void Z85RegularShouldHaveSameResultsAsSpanVersionTest(int seed, uint byteLength) { // arrange var data = new Span <byte>(MyData.CreatePseudoRandomByteArray(byteLength, seed)); var outputEncode = new Span <char>(new char[byteLength * 2]); var outputDecode = new Span <byte>(new byte[byteLength]); // act var resultEncodeRegular = Z85Extended.Encode(data.ToArray()); var resultEncodeSpan = Z85.Encode(data, outputEncode, out var encodeBytesConsumed, out var encodeCharsWritten); var resultDecodeRegular = Z85Extended.Decode(resultEncodeRegular); var resultDecodeSpan = Z85.Decode(outputEncode.Slice(0, encodeCharsWritten), outputDecode, out var decodeCharsConsumed, out var decodeBytesWritten); // assert // encode resultEncodeSpan.Should().Be(OperationStatus.Done); encodeBytesConsumed.Should().Be(data.Length); encodeCharsWritten.Should().Be(resultEncodeRegular.Length); outputEncode.Slice(0, encodeCharsWritten).ToString().Should().Be(resultEncodeRegular); // decode resultDecodeSpan.Should().Be(OperationStatus.Done); decodeCharsConsumed.Should().Be(resultEncodeRegular.Length); decodeBytesWritten.Should().Be(resultDecodeRegular.Length); outputDecode.Slice(0, decodeBytesWritten).ToArray().Should().BeEquivalentTo(resultDecodeRegular).And.BeEquivalentTo(data.ToArray()); }
public void GetDecodedSize_ThrowsException_WhenInputSizeIsNegativeTest(int inputSize) { // arrange // act Action act = () => Sut.GetDecodedSize(inputSize); // assert act.Should().Throw <ArgumentOutOfRangeException>(); }
public void GetDecodedSizeTest(int inputSize, int expectedOutput) { // arrange Span <char> input = new char[inputSize]; // act var result = Sut.GetDecodedSize(input); // assert result.Should().Be(expectedOutput); }
public void MultipleEncodedStringsDecodeToSameBytes() { // arrange const string encoded1 = "00000"; const string encoded2 = "%nSc1"; // act var result1 = Sut.Decode(encoded1); var result2 = Sut.Decode(encoded2); // assert Assert.Equal(result1, result2); }
public void EncodeTest(EncodeInputData scenario, EncodeExpectedData expectedResult) { // arrange Span <char> destination = scenario.CreateDestination().Span; // act var result = Sut.Encode( scenario.Source.Span, destination, out var bytesConsumed, out var charsWritten, scenario.IsFinalBlock); // assert expectedResult.AssertResult(result, bytesConsumed, charsWritten, destination); }
public void DecodeThrowsExceptionWhenInputHasWrongSizeTest(string encoded) { Assert.Throws <ArgumentOutOfRangeException>(() => Sut.Decode(encoded)); }
public void DecodeNullReturnsNullTest() { // ReSharper disable once AssignNullToNotNullAttribute Assert.Null(Sut.Decode(null)); }
public void DecodeTest(byte[] data, string encoded) { Assert.Equal(Sut.Decode(encoded), data); }
public void EncodeThrowsExceptionWhenInputHasWrongSizeTest(int length) { Assert.Throws <ArgumentOutOfRangeException>(() => Sut.Encode(new byte[length])); }
public void HelloWorldEncodeTest() { Assert.Equal(Sut.Encode(StrictZ85Samples.HelloWorldData), StrictZ85Samples.HelloWorldEncoded); }