예제 #1
0
        public void EmptyLazinatorListWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>();
            var c = l.CloneLazinatorTyped();

            c.Count().Should().Be(0);
        }
예제 #2
0
        public void LazinatorListDirtinessWithNestedStructs()
        {
            LazinatorList <ExampleStructContainingStruct> l = new LazinatorList <ExampleStructContainingStruct>()
            {
                new ExampleStructContainingStruct()
                {
                    MyExampleStructContainingClasses = new ExampleStructContainingClasses()
                    {
                        MyChar = 'Q'
                    }
                }
            };

            l.SerializeLazinator();
            var c = l.CloneLazinatorTyped();

            // consider original list, which should be clean
            l.IsDirty.Should().BeFalse();
            l.DescendantIsDirty.Should().BeFalse();
            l[0].IsDirty.Should().BeFalse();
            l[0].MyExampleStructContainingClasses.IsDirty.Should().BeFalse();
            // now consider clone
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeFalse();
            c[0].IsDirty.Should().BeFalse();
            c[0].MyExampleStructContainingClasses.IsDirty.Should().BeFalse();
            c[0].MyExampleStructContainingClasses.MyChar.Should().Be('Q');
        }
예제 #3
0
        public void LazinatorListWithEightByteContainer()
        {
            LazinatorList <EightByteLengthsContainer> l = new LazinatorList <EightByteLengthsContainer>()
            {
                new EightByteLengthsContainer()
                {
                    Contents = new EightByteLengths()
                    {
                        Example = GetExample(0)
                    }
                },
                new EightByteLengthsContainer()
                {
                    Contents = new EightByteLengths()
                    {
                        Example = GetExample(1)
                    }
                },
                null
            };
            var l2 = l.CloneLazinatorTyped();

            ExampleEqual(l[0].Contents.Example, l2[0].Contents.Example).Should().BeTrue();
            ExampleEqual(l[1].Contents.Example, l2[1].Contents.Example).Should().BeTrue();
            l2[2].Should().BeNull();
        }
예제 #4
0
        public void LazinatorListWithStructsWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>()
            {
                3
            };

            var c = l.CloneLazinatorTyped();

            c[0].WrappedValue.Should().Be(3);

            c = l.CloneLazinatorTyped();
            c.Insert(0, 2);
            var c2 = c.CloneLazinatorTyped();

            c2[0].WrappedValue.Should().Be(2);
            c2[1].WrappedValue.Should().Be(3);

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

            c3[0].WrappedValue.Should().Be(3);
            c3[1].WrappedValue.Should().Be(4);
            c3.Add(5);
            c3[2].Should().Be(5);

            c = c2.CloneLazinatorTyped();
            var accessed = c[1];
            var c2b      = c.CloneLazinatorTyped();

            c2b[0].WrappedValue.Should().Be(2);
            c2b[1].WrappedValue.Should().Be(3);
        }
예제 #5
0
        public void FreeInMemoryObjects_LazinatorList()
        {
            var typical1 = GetTypicalExample();

            typical1.SerializeLazinator();
            var typical2              = GetTypicalExample();
            var origValue             = typical2.MyChild1.MyLong;
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                typical1, typical2
            };

            l.SerializeLazinator();
            l.FreeInMemoryObjects();
            typical2.MyChild1.MyLong = 46523496; // should not affect the list now
            l[0].MyChild1.MyLong.Should().Be(origValue);
            l[1].MyChild1.MyLong.Should().Be(origValue);

            const long revisedValue = -123456789012345;

            l[0].MyChild1.MyLong = revisedValue;
            l.SerializeLazinator();
            l.FreeInMemoryObjects();
            l[0].MyChild1.MyLong.Should().Be(revisedValue);
            l[1].MyChild1.MyLong.Should().Be(origValue);
        }
예제 #6
0
        public void LazinatorListItemParentSet()
        {
            LazinatorList <ExampleChild> l = new LazinatorList <ExampleChild>()
            {
                new ExampleChild(),
                new ExampleChild()
            };

            l[0].LazinatorParents.LastAdded.Should().Be(l);
            l[1].LazinatorParents.LastAdded.Should().Be(l);
            var c = l.CloneLazinatorTyped();

            c[0].LazinatorParents.LastAdded.Should().Be(c);
            c[1].LazinatorParents.LastAdded.Should().Be(c);
            var c2 = l.CloneLazinatorTyped();

            c2.Insert(0, new ExampleChild());
            c2[1].LazinatorParents.LastAdded.Should().Be(c2);
            var c3  = l.CloneLazinatorTyped();
            var lc3 = c3.ToList();

            lc3[1].LazinatorParents.LastAdded.Should().Be(c3);
            var c4  = l.CloneLazinatorTyped();
            var lc4 = c4.AsEnumerable().ToList();

            lc4[1].LazinatorParents.LastAdded.Should().Be(c4);
            var c5 = l.CloneLazinatorTyped();

            c5[0] = new ExampleChild();
            c5[0].LazinatorParents.LastAdded.Should().Be(c5);
        }
예제 #7
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
        }
예제 #8
0
        private void GetHashAndBucket(TKey key, LazinatorList <DictionaryBucket <TKey, TValue> > buckets, out uint hash, out DictionaryBucket <TKey, TValue> bucket)
        {
            // This method is for use when using a replacement set of buckets.
            EnsureBucketsExist();
            hash = key.GetBinaryHashCode32();
            int bucketIndex = (int)(hash % buckets.Count);

            bucket = GetBucketAtIndex(bucketIndex, buckets);
        }
예제 #9
0
        public LazinatorGeneralTree <T> AddChild(T child)
        {
            if (Children == null)
            {
                Children = new LazinatorList <LazinatorGeneralTree <T> >();
            }
            LazinatorGeneralTree <T> childTree = CreateTree(child);

            return(AddChildTree(childTree));
        }
예제 #10
0
 public LazinatorGeneralTree <T> AddChildTree(LazinatorGeneralTree <T> childTree)
 {
     if (Children == null)
     {
         Children = new LazinatorList <LazinatorGeneralTree <T> >();
     }
     Children.Add(childTree);
     SetChildInformation(childTree, Children.Count - 1, true);
     return(childTree);
 }
예제 #11
0
 protected internal void InsertChildTree(LazinatorGeneralTree <T> childTree, int index)
 {
     if (Children == null)
     {
         Children = new LazinatorList <LazinatorGeneralTree <T> >();
     }
     Children.Insert(index, childTree);
     OnAddChild(childTree);
     ResetDescendantIndices();
 }
예제 #12
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);
        }
예제 #13
0
        public void CanCloneListOfLazinatorsAndThenEnsureUpToDate()
        {
            var l = new LazinatorList <Example>()
            {
                GetTypicalExample(), GetTypicalExample()
            };
            var l2 = l.CloneLazinatorTyped();
            var l3 = l.CloneLazinatorTyped();

            l.SerializeLazinator();
        }
예제 #14
0
        public void LazinatorListEnumerateNodesWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };
            var c        = l.CloneLazinatorTyped();
            var results2 = c.EnumerateAllNodes().ToList();

            results2[0].Should().Be(c);
            results2[1].LazinatorParents.LastAdded.Should().Be(c);
        }
예제 #15
0
        public void CanCloneListOfStructsAndThenEnsureUpToDate()
        {
            // Note: This works because of IsStruct parameter in ReplaceBuffer. Without that parameter, the last call would lead to disposal of memory still needed.
            var l = new LazinatorList <WInt32>()
            {
                1
            };
            var l2 = l.CloneLazinatorTyped();
            var l3 = l.CloneLazinatorTyped();

            l.SerializeLazinator();
        }
예제 #16
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());
        }
예제 #17
0
 private void LazinateChildren()
 {
     if (LazinatorMemoryStorage.Length == 0)
     {
         _Children = null;
     }
     else
     {
         LazinatorMemory childData = GetChildSlice(LazinatorMemoryStorage, _Children_ByteIndex, _Children_ByteLength, null);
         _Children = DeserializationFactory.Instance.CreateBaseOrDerivedType(201, (c, p) => new LazinatorList <LazinatorGeneralTree <T> >(c, p), childData, this);
     }
     _Children_Accessed = true;
 }
예제 #18
0
 private void LazinateMyStructList()
 {
     if (LazinatorMemoryStorage.Length == 0)
     {
         _MyStructList = null;
     }
     else
     {
         LazinatorMemory childData = GetChildSlice(LazinatorMemoryStorage, _MyStructList_ByteIndex, _MyStructList_ByteLength, null);
         _MyStructList = DeserializationFactory.Instance.CreateBaseOrDerivedType(201, (c, p) => new LazinatorList <WByte>(c, p), childData, this);
     }
     _MyStructList_Accessed = true;
 }
예제 #19
0
 private void LazinateBuckets()
 {
     if (LazinatorMemoryStorage.Length == 0)
     {
         _Buckets = null;
     }
     else
     {
         LazinatorMemory childData = GetChildSlice(LazinatorMemoryStorage, _Buckets_ByteIndex, _Buckets_ByteLength, null);
         _Buckets = DeserializationFactory.Instance.CreateBaseOrDerivedType(201, (c, p) => new LazinatorList <DictionaryBucket <TKey, TValue> >(c, p), childData, this);
     }
     _Buckets_Accessed = true;
 }
예제 #20
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);
        }
예제 #21
0
        /// <summary>
        /// Orders the item at each level of the tree, by something other than the item at each level.
        /// </summary>
        public void Order <T2>(Func <LazinatorGeneralTree <T>, T2> orderByItem) where T2 : IComparable <T2>
        {
            var children = GetChildren();

            Children = new LazinatorList <LazinatorGeneralTree <T> >(children.OrderBy(x => orderByItem(x)), false);
            foreach (var child in Children)
            {
                child.Order(orderByItem);
            }
            if (ParentTree == null)
            {
                ResetDescendantIndices();
            }
        }
예제 #22
0
        /// <summary>
        /// Orders the item at each level of the tree, by the item at each level.
        /// </summary>
        public void Order()
        {
            var children = GetChildren();

            Children = new LazinatorList <LazinatorGeneralTree <T> >(children.OrderBy(x => x.Item), false);
            foreach (var child in Children)
            {
                child.Order();
            }
            if (ParentTree == null)
            {
                ResetDescendantIndices();
            }
        }
예제 #23
0
        private DictionaryBucket <TKey, TValue> GetBucketAtIndex(int index, LazinatorList <DictionaryBucket <TKey, TValue> > buckets = null)
        {
            if (buckets == null)
            {
                buckets = Buckets;
            }
            var bucket = buckets[index];

            if (bucket == null)
            {
                bucket         = new DictionaryBucket <TKey, TValue>();
                buckets[index] = bucket;
            }
            return(bucket);
        }
예제 #24
0
        public void ChangeToObjectAppearingTwiceInLazinatorListAffectsBoth()
        {
            LazinatorList <ExampleChild> e = new LazinatorList <ExampleChild>()
            {
                new ExampleChild(),
                new ExampleChild()
                {
                    MyLong = -123456
                }
            };
            var c = e.CloneLazinatorTyped();

            c[0]        = c[1];
            c[0].MyLong = -987;
            var c2 = c.CloneLazinatorTyped();

            c2[0].MyLong.Should().Be(-987);
            c2[1].MyLong.Should().Be(-987);
        }
예제 #25
0
        public void LazinatorListRemoveAllWorks()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>()
            {
                2, 3, 4, 5, 6
            };

            l.RemoveAll(x => x % 2 == 0);
            var results = l.ToList().Select(x => x.WrappedValue);

            results.SequenceEqual(new int[] { 3, 5 }).Should().BeTrue();

            l = new LazinatorList <WInt32>()
            {
                2, 3, 4, 5, 6
            };
            l.RemoveAll(x => x % 2 == 1);
            results = l.ToList().Select(x => x.WrappedValue);
            results.SequenceEqual(new int[] { 2, 4, 6 }).Should().BeTrue();

            l = new LazinatorList <WInt32>()
            {
                2, 3, 4, 5, 6
            };
            l.RemoveAll(x => x > 6);
            results = l.ToList().Select(x => x.WrappedValue);
            results.SequenceEqual(new int[] { 2, 3, 4, 5, 6 }).Should().BeTrue();

            l = new LazinatorList <WInt32>()
            {
                2, 3, 4, 5, 6
            };
            l.RemoveAll(x => x <= 6);
            results = l.ToList().Select(x => x.WrappedValue);
            results.SequenceEqual(new int[] { }).Should().BeTrue();

            l = new LazinatorList <WInt32>()
            {
            };
            l.RemoveAll(x => x <= 6);
            results = l.ToList().Select(x => x.WrappedValue);
            results.SequenceEqual(new int[] { }).Should().BeTrue();
        }
예제 #26
0
        public void LazinatorListDirtinessWithStructs()
        {
            LazinatorList <WInt32> l = new LazinatorList <WInt32>()
            {
                new WInt32(3)
            };

            l.SerializeLazinator();
            var c = l.CloneLazinatorTyped();

            // consider original list, which should be clean
            l.IsDirty.Should().BeFalse();
            l.DescendantIsDirty.Should().BeFalse();
            l[0].IsDirty.Should().BeFalse();
            // now consider clone
            c.IsDirty.Should().BeFalse();
            c.DescendantIsDirty.Should().BeFalse();
            c[0].IsDirty.Should().BeFalse();
        }
예제 #27
0
        public void LazinatorListEnumeratorWorks()
        {
            LazinatorList <Example> l = new LazinatorList <Example>()
            {
                GetExample(1), GetExample(1)
            };
            var results = l.ToList();

            results[0].LazinatorParents.LastAdded.Should().Be(l);
            results[1].LazinatorParents.LastAdded.Should().Be(l);
            var c = l.CloneLazinatorTyped();

            results = c.ToList();
            results[0].LazinatorParents.LastAdded.Should().Be(c);
            results[1].LazinatorParents.LastAdded.Should().Be(c);
            c = l.CloneLazinatorTyped();
            foreach (var result in c)
            {
                result.LazinatorParents.LastAdded.Should().Be(c);
            }
        }
예제 #28
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);
        }
예제 #29
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);
        }
예제 #30
0
        public void LazinatorListForEachLazinatorWorks()
        {
            LazinatorList <WString> l = new LazinatorList <WString>()
            {
                "hello", "world"
            };
            StringBuilder sb = new StringBuilder();
            var           c  = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, true, true);

            sb.ToString().Should().Be("helloworld");
            l  = l.CloneLazinatorTyped();
            sb = new StringBuilder();
            c  = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, true, true);
            sb.ToString().Should().Be("");
            c = l.ForEachLazinator(x =>
            {
                if (x is WString ws)
                {
                    sb.Append(ws.WrappedValue);
                }
                return(x);
            }, false, true); // now deserialize
            sb.ToString().Should().Be("helloworld");
        }