Пример #1
0
 protected bool Equals(GenericTestClassWithInternalObjectSerializer <T1, T2> other)
 {
     return(BooleanFalse == other.BooleanFalse &&
            BooleanTrue == other.BooleanTrue &&
            Char == other.Char &&
            SByte == other.SByte &&
            Byte == other.Byte &&
            Int16 == other.Int16 &&
            UInt16 == other.UInt16 &&
            Int32 == other.Int32 &&
            UInt32 == other.UInt32 &&
            Int64 == other.Int64 &&
            UInt64 == other.UInt64 &&
            Single.Equals(other.Single) &&
            Double.Equals(other.Double) &&
            Decimal == other.Decimal &&
            String == other.String &&
            DateTime == other.DateTime &&
            DateTimeOffset == other.DateTimeOffset &&
            NonGenericType == other.NonGenericType &&
            GenericTypeDefinition == other.GenericTypeDefinition &&
            ClosedConstructedGenericType == other.ClosedConstructedGenericType &&
            NullReference == other.NullReference &&
            Enum_S8 == other.Enum_S8 &&
            Enum_U8 == other.Enum_U8 &&
            Enum_S16 == other.Enum_S16 &&
            Enum_U16 == other.Enum_U16 &&
            Enum_S32 == other.Enum_S32 &&
            Enum_U32 == other.Enum_U32 &&
            Enum_S64 == other.Enum_S64 &&
            Enum_U64 == other.Enum_U64 &&
            SerializableObject.SequenceEqual(other.SerializableObject) &&
            ByteArrayEqualityComparer.AreEqual(Buffer1, other.Buffer1) &&
            ByteArrayEqualityComparer.AreEqual(Buffer2, other.Buffer2));
 }
Пример #2
0
        /// <summary>
        /// Takes a state snapshot of the map. Only records it as a new state if the state has changed since the last snapshot.
        /// If the state has changed, all forward states are destroyed. So if you undo a few times then call this, you cannot redo those undos anymore.
        /// </summary>
        /// <returns>True if a new state snapshot was taken; false if the state has not changed.</returns>
        public bool Snapshot()
        {
            // Serilize the whole map as binary into memory
            byte[] serialized = BinaryValueWriter.CreateAndWrite(w => Map.Save(w, DynamicEntityFactory, MapBase.MapSaveFlags.DoNotSort));

            // Check if the state changed since the last time
            if (_stateIndex >= 0 && ByteArrayEqualityComparer.AreEqual(_states[_stateIndex], serialized))
            {
                return(false);
            }

            // Remove all forward (redo) states
            if (_states.Count > _stateIndex + 1)
            {
                _states.RemoveRange(_stateIndex + 1, _states.Count - _stateIndex - 1);
            }

            // Remove old states
            if (_states.Count > _maxStates)
            {
                _states.RemoveRange(0, _cropAmount);
            }

            // Push in new state
            _states.Add(serialized);
            _stateIndex = _states.Count - 1;

            return(true);
        }
        public void DifferentLengthTest()
        {
            byte[] a      = new byte [] { 1, 2, 3, 4, 5 };
            byte[] b      = new byte [] { 1, 2, 3, 4, 5, 6 };
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsFalse(actual);
        }
        public void SameTest1()
        {
            byte[] a      = new byte[] { 1, 2, 3, 4, 5, 6, 1, 3, 5 };
            byte[] b      = a;
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsTrue(actual);
        }
        public void SameLengthTest()
        {
            byte[] a      = new byte[] { 1, 2, 3, 4 };
            byte[] b      = new byte[] { 1, 2, 4, 4 };
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsFalse(actual);
        }
        public void EmptyTest3()
        {
            byte[] a      = new byte[0];
            byte[] b      = new byte[0];
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsTrue(actual);
        }
        public void EmptyTest2()
        {
            byte[] a      = new byte[] { 1, 2, 3, 4, 5 };
            byte[] b      = new byte[0];
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsFalse(actual);
        }
        public void NullTest3()
        {
            byte[] a      = null;
            byte[] b      = null;
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsTrue(actual);
        }
        public void NullTest2()
        {
            byte[] a      = null;
            byte[] b      = new byte[] { 1, 2, 3, 4, 5, 6 };
            bool   actual = ByteArrayEqualityComparer.AreEqual(a, b);

            Assert.IsFalse(actual);
        }
Пример #10
0
        public void RandomEqualTest()
        {
            SafeRandom rnd = new SafeRandom();

            for (int loop = 0; loop < 100000; loop++)
            {
                byte[] a = new byte[rnd.Next(1, 100)];
                rnd.NextBytes(a);

                byte[] b = DeepCopy(a);

                bool actual = ByteArrayEqualityComparer.AreEqual(a, b);
                Assert.IsTrue(actual);
            }
        }
Пример #11
0
        public void RandomNotEqualTest()
        {
            SafeRandom rnd = new SafeRandom();

            for (int loop = 0; loop < 1000000; loop++)
            {
                byte[] a = new byte[rnd.Next(1, 100)];
                rnd.NextBytes(a);

                byte[] b = DeepCopy(a);

                b[rnd.Next(0, b.Length)]++; // Increment at a random index

                bool actual = ByteArrayEqualityComparer.AreEqual(a, b);
                Assert.IsFalse(actual);
            }
        }