示例#1
0
        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());
        }
示例#2
0
        public void GetDecodedSize_ThrowsException_WhenInputSizeIsNegativeTest(int inputSize)
        {
            // arrange

            // act
            Action act = () => Sut.GetDecodedSize(inputSize);

            // assert
            act.Should().Throw <ArgumentOutOfRangeException>();
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
 public void DecodeThrowsExceptionWhenInputHasWrongSizeTest(string encoded)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Sut.Decode(encoded));
 }
示例#7
0
 public void DecodeNullReturnsNullTest()
 {
     // ReSharper disable once AssignNullToNotNullAttribute
     Assert.Null(Sut.Decode(null));
 }
示例#8
0
 public void DecodeTest(byte[] data, string encoded)
 {
     Assert.Equal(Sut.Decode(encoded), data);
 }
示例#9
0
 public void EncodeThrowsExceptionWhenInputHasWrongSizeTest(int length)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Sut.Encode(new byte[length]));
 }
示例#10
0
 public void HelloWorldEncodeTest()
 {
     Assert.Equal(Sut.Encode(StrictZ85Samples.HelloWorldData), StrictZ85Samples.HelloWorldEncoded);
 }