Exemplo n.º 1
0
        public void TryRemoveFromEmptyTree(ushort seq)
        {
            var tree = new Carambolas.Net.Channel.Inbound.Node.Tree <Node>();

            Assert.False(tree.TryRemove(new Protocol.Ordinal(seq), out Node node));
            Assert.Null(node);
        }
Exemplo n.º 2
0
        public void TryAddManyThenRemove(ushort offset, int n, int repetitions)
        {
            var random = new Random();

            var set  = new HashSet <ushort>();
            var tree = new Carambolas.Net.Channel.Inbound.Node.Tree <Node>();

            for (int r = 0; r < repetitions; ++r)
            {
                for (int i = 0; i < n; ++i)
                {
                    ushort seq;
                    do
                    {
                        seq = (ushort)(offset + random.Next(0, Protocol.Ordinal.Window.Size - 1));
                    }while (set.Contains(seq));

                    Assert.True(tree.TryAdd(new Node()
                    {
                        SequenceNumber = new Protocol.Ordinal(seq)
                    }));
                    Assert.False(tree.IsEmpty);
                    set.Add(seq);
                }

                foreach (var seq in set)
                {
                    Assert.True(tree.TryRemove(new Protocol.Ordinal(seq), out Node node));
                    Assert.NotNull(node);
                    n--;
                    if (n > 0)
                    {
                        Assert.False(tree.IsEmpty);
                    }
                }

                Assert.True(tree.IsEmpty);
                set.Clear();
            }
        }