Ejemplo n.º 1
0
        public void LazinatorListWorksWithPartialAccessAfterChange()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();

            l.Add(3);
            l.Add(4);
            var c = l.CloneLazinatorTyped();

            c[0] = 999999;
            var c2 = c.CloneLazinatorTyped();

            c2[1].WrappedValue.Should().Be(4);
        }
Ejemplo n.º 2
0
        public void TopNodesComparisonWorks()
        {
            ExampleChild c1 = new ExampleChild()
            {
                MyShort = 3
            };
            ExampleChild c2 = new ExampleChild()
            {
                MyShort = 3
            };

            LazinatorUtilities.TopNodesOfHierarchyEqual(c1, c2, out string comparison).Should().BeTrue();
            c2.MyShort = 5;
            LazinatorUtilities.TopNodesOfHierarchyEqual(c1, c2, out comparison).Should().BeFalse();

            LazinatorTuple <ExampleChild, ExampleChild> e1 = new LazinatorTuple <ExampleChild, ExampleChild>()
            {
                Item1 = new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 3
                    }
                },
                Item2 = null
            };
            var e2 = e1.CloneLazinatorTyped();

            LazinatorUtilities.TopNodesOfHierarchyEqual(e1, e2, out comparison).Should().BeTrue();
            e2.Item1.MyWrapperContainer.WrappedInt = 5;
            LazinatorUtilities.TopNodesOfHierarchyEqual(e1, e2, out comparison).Should().BeTrue(); // top node is still equal

            LazinatorList <ExampleChild> l1 = new LazinatorList <ExampleChild>()
            {
                new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 3
                    }
                }
            };
            LazinatorList <ExampleChild> l2 = new LazinatorList <ExampleChild>()
            {
                new ExampleChild()
                {
                    MyWrapperContainer = new WrapperContainer()
                    {
                        WrappedInt = 6
                    }
                }
            };

            LazinatorUtilities.TopNodesOfHierarchyEqual(l1, l2, out comparison).Should().BeTrue();
            l2.Add(null);
            LazinatorUtilities.TopNodesOfHierarchyEqual(l1, l2, out comparison).Should().BeFalse(); // number of elements differs
        }
Ejemplo n.º 3
0
        public void ShortLazinatorListWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();

            l.Add(3);
            var c      = l.CloneLazinatorTyped();
            var result = c[0];

            result.Should().Be(3);
        }
Ejemplo n.º 4
0
        void BinaryHashInList()
        {
            var wrapped              = new WInt32(1);
            var wrapped2             = new WInt32(1);
            LazinatorList <WInt32> x = new LazinatorList <WInt32>();

            x.Add(wrapped2);
            x.GetListMemberHash32(0).Should().Be(wrapped.GetBinaryHashCode32());
            var clone = x.CloneLazinatorTyped();

            clone.GetListMemberHash32(0).Should().Be(wrapped.GetBinaryHashCode32());
        }
Ejemplo n.º 5
0
        public void LazinatorListParentItemsWorks()
        {
            LazinatorList <ExampleChild> e = new LazinatorList <ExampleChild>();
            var child = new ExampleChild();

            e.Add(child);
            child.LazinatorParents.LastAdded.Should().Be(e);
            e.Add(child);
            child.LazinatorParents.LastAdded.Should().Be(e);
            e[0] = null;
            child.LazinatorParents.LastAdded.Should().Be(e);
            e[1] = null;
            child.LazinatorParents.Count.Should().Be(0);

            LazinatorList <ExampleChild> e2 = new LazinatorList <ExampleChild>();

            e.Add(child);
            e2.Add(child);
            child.LazinatorParents.Count.Should().Be(2);
            e2[0] = null;
            child.LazinatorParents.Count.Should().Be(1);
        }
Ejemplo n.º 6
0
        public void LazinatorListCountWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };

            l.Count.Should().Be(2);
            l.Add(null);
            l.Count.Should().Be(3);
            l.RemoveAt(1);
            l.Count.Should().Be(2);
            var c = l.CloneLazinatorTyped();

            c.Count.Should().Be(2);
            c.Insert(0, GetExample(1));
            c.Count.Should().Be(3);
            c.Add(GetExample(2));
            c.Count.Should().Be(4);
            c.RemoveAll(x => true);
            c.Count.Should().Be(0);
        }
Ejemplo n.º 7
0
        public void LazinatorListWorks(ContainerForLazinatorList containerOption, bool cloneAfterEachStep)
        {
            LazinatorListContainer nonGenericContainer = new LazinatorListContainer()
            {
            };
            LazinatorListContainerGeneric <ExampleChild> genericContainer = new LazinatorListContainerGeneric <ExampleChild>()
            {
            };
            LazinatorList <ExampleChild> withoutContainer = null;

            LazinatorList <ExampleChild> GetList()
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    return(withoutContainer);

                case ContainerForLazinatorList.NonGenericContainer:
                    return(nonGenericContainer.MyList);

                case ContainerForLazinatorList.GenericContainer:
                    return(genericContainer.MyList);
                }
                throw new NotImplementedException();
            }

            void SetList(LazinatorList <ExampleChild> value)
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    withoutContainer = value;
                    break;

                case ContainerForLazinatorList.NonGenericContainer:
                    nonGenericContainer.MyList = value;
                    break;

                case ContainerForLazinatorList.GenericContainer:
                    genericContainer.MyList = value;
                    break;
                }
            }

            SetList(new LazinatorList <ExampleChild>()
            {
            });

            LazinatorList <ExampleChild> list = new LazinatorList <ExampleChild>();

            for (int i = 0; i <= 3; i++)
            {
                AddItem(i);
                list.IsDirty.Should().BeTrue();
            }
            void AddItem(int i, int?insertIndex = null)
            {
                if (insertIndex is int insertIndexInt)
                {
                    GetList().Insert(insertIndexInt, GetExampleChild(i));
                    list.Insert(insertIndexInt, GetExampleChild(i));
                }
                else
                {
                    GetList().Add(GetExampleChild(i));
                    list.Add(GetExampleChild(i));
                }
            }

            void RemoveItem(int i, bool useRemoveAt)
            {
                if (useRemoveAt)
                {
                    GetList().RemoveAt(i);
                    list.RemoveAt(i);
                }
                else
                {
                    var item = GetList()[i];
                    GetList().Remove(item);
                    list.RemoveAt(i); // not testing this, so can just do this
                }
            }

            void Clear()
            {
                GetList().Clear();
                list.Clear();
                list.IsDirty.Should().BeTrue();
            }

            void CheckList()
            {
                for (int i = 0; i < list.Count; i++)
                {
                    var currentListItem = GetList()[i];
                    if (currentListItem == null)
                    {
                        list[i].Should().Be(null);
                    }
                    else
                    {
                        ExampleChildEqual(currentListItem, list[i]).Should().BeTrue();
                    }
                }
                // now check another way, using enumerables
                var zipped = GetList().Zip(list, (a, b) => (a, b));

                foreach (var zip in zipped)
                {
                    ExampleChildEqual(zip.a, zip.b).Should().BeTrue();
                }
            }

            void CloneList()
            {
                switch (containerOption)
                {
                case ContainerForLazinatorList.NoContainer:
                    SetList(GetList().CloneLazinatorTyped());
                    break;

                case ContainerForLazinatorList.NonGenericContainer:
                    nonGenericContainer = nonGenericContainer.CloneLazinatorTyped();
                    break;

                case ContainerForLazinatorList.GenericContainer:
                    genericContainer = genericContainer.CloneLazinatorTyped();
                    break;
                }
            }

            void CheckBeforeAndAfterSerialization()
            {
                CheckList();
                CloneList();
                CheckList();
                if (cloneAfterEachStep)
                {
                    CloneList();
                }
            }

            CheckBeforeAndAfterSerialization();
            CheckBeforeAndAfterSerialization(); // do it again
            AddItem(1);
            CheckBeforeAndAfterSerialization();
            AddItem(0);
            CheckBeforeAndAfterSerialization();
            AddItem(2, 1);
            CheckBeforeAndAfterSerialization();
            AddItem(0, 0);
            CheckBeforeAndAfterSerialization();
            RemoveItem(3, true);
            CheckBeforeAndAfterSerialization();
            RemoveItem(3, false);
            CheckBeforeAndAfterSerialization();
            RemoveItem(0, false);
            CheckBeforeAndAfterSerialization();
            RemoveItem(0, true);
            CheckBeforeAndAfterSerialization();
            Clear();
            CheckBeforeAndAfterSerialization();
        }