public void ClassLayout()
        {
            var ti = FastEquality.CreateTypeInfo(typeof(ClassInStruct));

            Assert.IsNotNull(ti.GetHashFn);
            Assert.IsNotNull(ti.EqualFn);
        }
Esempio n. 2
0
        public void EqualsPadding()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(EndPadding));

            Assert.IsTrue(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 2), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(1, 3), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new EndPadding(1, 2), new EndPadding(4, 2), typeInfo));
        }
        public void ClassLayout()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(ClassInStruct)).Layouts;

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = PtrAligned4Count, Aligned4 = true
            }, layout[0]);
        }
Esempio n. 4
0
        public void EndPaddingLayout()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(EndPadding)).Layouts;

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 3, Aligned4 = true
            }, layout[0]);
        }
Esempio n. 5
0
        public void EqualsInt4()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(int4));

            Assert.IsTrue(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 4), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(1, 2, 3, 5), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(0, 2, 3, 4), typeInfo));
            Assert.IsFalse(FastEquality.Equals(new int4(1, 2, 3, 4), new int4(5, 6, 7, 8), typeInfo));
        }
Esempio n. 6
0
        public void SimpleEmbeddedLayout()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(SimpleEmbedded)).Layouts;

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 5, Aligned4 = true
            }, layout[0]);
        }
Esempio n. 7
0
        public void PtrLayout()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(FloatPointer)).Layouts;

            Assert.AreEqual(1, layout.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = PtrAligned4Count, Aligned4 = true
            }, layout[0]);
        }
Esempio n. 8
0
        public void SimpleLayout()
        {
            var res = FastEquality.CreateTypeInfo(typeof(Simple)).Layouts;

            Assert.AreEqual(1, res.Length);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 2, Aligned4 = true
            }, res[0]);
        }
Esempio n. 9
0
        public void CorrectEqualsIsUsed()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(DoubleEquals));
            var a        = new DoubleEquals {
            };
            var b        = new DoubleEquals {
            };
            bool iseq    = FastEquality.Equals <DoubleEquals>(a, b, typeInfo);

            Assert.IsTrue(iseq);
        }
Esempio n. 10
0
        public void GetHashCodeInt4()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(int4));

            Assert.AreEqual(-270419516, FastEquality.GetHashCode(new int4(1, 2, 3, 4), typeInfo));
            Assert.AreEqual(-270419517, FastEquality.GetHashCode(new int4(1, 2, 3, 3), typeInfo));
            Assert.AreEqual(1, FastEquality.GetHashCode(new int4(0, 0, 0, 1), typeInfo));
            Assert.AreEqual(16777619, FastEquality.GetHashCode(new int4(0, 0, 1, 0), typeInfo));
            Assert.AreEqual(0, FastEquality.GetHashCode(new int4(0, 0, 0, 0), typeInfo));

            // Note, builtin .GetHashCode() returns different values even for all zeros...
        }
Esempio n. 11
0
        public void BytePaddding()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(BytePadding)).Layouts;

            Assert.AreEqual(2, layout.Length);

            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 2, Aligned4 = false
            }, layout[0]);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 4, count = 1, Aligned4 = true
            }, layout[1]);
        }
Esempio n. 12
0
        public void AlignSplitLayout()
        {
            var layout = FastEquality.CreateTypeInfo(typeof(AlignSplit)).Layouts;

            Assert.AreEqual(2, layout.Length);

            Assert.AreEqual(new FastEquality.Layout {
                offset = 0, count = 3, Aligned4 = true
            }, layout[0]);
            Assert.AreEqual(new FastEquality.Layout {
                offset = 16, count = 2, Aligned4 = true
            }, layout[1]);
        }
Esempio n. 13
0
        public void EqualsEnum()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(EnumStruct));

            var a = new EnumStruct {
                nephew = Nephew.Huey
            };
            var b = new EnumStruct {
                nephew = Nephew.Dewey
            };

            Assert.IsTrue(FastEquality.Equals(a, a, typeInfo));
            Assert.IsFalse(FastEquality.Equals(a, b, typeInfo));
        }
Esempio n. 14
0
        public void TypeHash()
        {
            int[] hashes =
            {
                FastEquality.CreateTypeInfo(typeof(Simple)).Hash,
                FastEquality.CreateTypeInfo(typeof(SimpleEmbedded)).Hash,
                FastEquality.CreateTypeInfo(typeof(BytePadding)).Hash,
                FastEquality.CreateTypeInfo(typeof(AlignSplit)).Hash,
                FastEquality.CreateTypeInfo(typeof(EndPadding)).Hash,
                FastEquality.CreateTypeInfo(typeof(FloatPointer)).Hash,
                FastEquality.CreateTypeInfo(typeof(ClassInStruct)).Hash,
                FastEquality.CreateTypeInfo(typeof(FixedArrayStruct)).Hash,
                FastEquality.CreateTypeInfo(typeof(EnumStruct)).Hash
            };

            Assert.AreEqual(hashes.Distinct().Count(), hashes.Length);
        }
        public unsafe void EqualsFixedArray()
        {
            var typeInfo = FastEquality.CreateTypeInfo(typeof(FixedArrayStruct));

            var a = new FixedArrayStruct();

            a.array[0] = 123;
            a.array[1] = 234;
            a.array[2] = 345;

            var b = a;

            Assert.IsTrue(FastEquality.Equals(a, b, typeInfo));

            b.array[1] = 456;

            Assert.IsFalse(FastEquality.Equals(a, b, typeInfo));
        }
Esempio n. 16
0
        public void ForgettingGetHashCodeIsAnError()
        {
            var ex = Assert.Throws <ArgumentException>(() => FastEquality.CreateTypeInfo(typeof(TypeWithoutHashCodeOverride)));

            Assert.IsTrue(ex.Message.Contains("GetHashCode"));
        }
Esempio n. 17
0
        public void ManagedComponentGetHashCode()
        {
            {
                var typeInfo = FastEquality.CreateTypeInfo(typeof(EcsTestManagedComponent));
                var obj1     = new EcsTestManagedComponent()
                {
                    value = "SomeString"
                };
                var obj12 = new EcsTestManagedComponent()
                {
                    value = "SomeString"
                };
                var obj2 = new EcsTestManagedComponent()
                {
                    value = "SomeOtherString"
                };
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj1, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj12, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj2, typeInfo));
            }

            {
                var typeInfo    = FastEquality.CreateTypeInfo(typeof(ComponentWithUnityObjectArray));
                var tex1        = new UnityEngine.Texture2D(512, 512);
                var tex2        = new UnityEngine.Texture2D(512, 512);
                var tex3        = new UnityEngine.Texture2D(512, 512);
                var stringList1 = new List <string>()
                {
                    "yo", "hi", "hej", "hello"
                };
                var stringList12 = new List <string>()
                {
                    "yo", "hi", "hej", "hello"
                };
                var stringList2 = new List <string>()
                {
                    "yo", "hi", "hey", "hello"
                };

                var obj1 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj12 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj13 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList12, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj2 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex2, tex2 }
                };
                var obj3 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex1, null }
                };
                var obj4 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList1, Texture = tex1, Objects = new[] { tex1 }
                };
                var obj5 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList2, Texture = tex1, Objects = new[] { tex2, tex3 }
                };
                var obj6 = new ComponentWithUnityObjectArray()
                {
                    Strings = stringList2, Texture = tex2, Objects = new[] { tex3, tex1 }
                };
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj1, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj12, typeInfo));
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj13, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj2, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj3, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj4, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj5, typeInfo));
                Assert.AreNotEqual(FastEquality.ManagedGetHashCode(obj1, typeInfo), FastEquality.ManagedGetHashCode(obj6, typeInfo));
            }

            {
                var typeInfo = FastEquality.CreateTypeInfo(typeof(ComponentOverridesGetHashCode));
                var obj      = new ComponentOverridesGetHashCode();
                Assert.AreEqual(FastEquality.ManagedGetHashCode(obj, typeInfo), FastEquality.ManagedGetHashCode(obj, typeInfo));
                Assert.IsTrue(obj.GetHashCodeWasCalled);
            }
        }