Exemplo n.º 1
0
        [Test] public void Base32()
        {
            {
                var data = new byte[] { 0xff };
                var enc  = Base32Encoding.ToString(data);
                var dec  = Base32Encoding.ToBytes(enc);
                Assert.Equal(enc.Length, Base32Encoding.EncodedLength(data.Length));
                Assert.Equal(dec.Length, Base32Encoding.DecodedLength(enc));
                Assert.Equal(0, Array_.Compare(data, 0, data.Length, dec, 0, dec.Length));
            }
            {
                var data = new byte[256];
                for (int i = 0; i != data.Length; ++i)
                {
                    data[i] = (byte)i;
                }
                var enc = Base32Encoding.ToString(data);
                var dec = Base32Encoding.ToBytes(enc);
                Assert.Equal(enc.Length, Base32Encoding.EncodedLength(data.Length));
                Assert.Equal(dec.Length, Base32Encoding.DecodedLength(enc));
                Assert.Equal(0, Array_.Compare(data, 0, data.Length, dec, 0, dec.Length));
            }
            var rand = new Random(42);

            for (int i = 0; i != 100; ++i)
            {
                var data = new byte[rand.Next(16000)];
                rand.NextBytes(data);
                var enc = Base32Encoding.ToString(data);
                var dec = Base32Encoding.ToBytes(enc);
                Assert.Equal(enc.Length, Base32Encoding.EncodedLength(data.Length));
                Assert.Equal(dec.Length, Base32Encoding.DecodedLength(enc));
                Assert.Equal(0, Array_.Compare(data, 0, data.Length, dec, 0, dec.Length));
            }
        }