Exemple #1
0
        public void Encode_IdentityTransform_ResultsInSameNumber()
        {
            var coder = new ShortCoder("0123456789", 0);

            var valueToEncode = (Int64)0;
            var encodedResult = coder.Encode(valueToEncode);
            Assert.AreEqual(encodedResult, valueToEncode.ToString());

            valueToEncode = Int64.MaxValue;
            encodedResult = coder.Encode(valueToEncode);
            Assert.AreEqual(encodedResult, valueToEncode.ToString());
        }
Exemple #2
0
        public void Decode_IdentityTransform_ResultsInSameNumber()
        {
            var coder = new ShortCoder("0123456789", 0);

            var valueToDecode = ((Int64)0).ToString();
            var decodedResult = coder.Decode(valueToDecode);
            Assert.AreEqual(decodedResult.ToString(), valueToDecode);

            valueToDecode = Int64.MaxValue.ToString();
            decodedResult = coder.Decode(valueToDecode);
            Assert.AreEqual(decodedResult.ToString(), valueToDecode);
        }
Exemple #3
0
        public void EncodeDecode_RoundTrip()
        {
            var coder = new ShortCoder("abcdefg012345678", 1234);
            var rand = new Random();

            for (int x = 0; x < 100; x++)
            {
                var startValue = rand.Next();
                var encodedValue = coder.Encode(startValue);
                var decodedValue = coder.Decode(encodedValue);

                Assert.AreEqual(startValue, decodedValue, string.Format("Value was {0}, expected {1}", decodedValue, startValue));
            }
        }