Ejemplo n.º 1
0
        public void TryAddOrGetMany(ushort offset, int n, int repetitions)
        {
            var random = new Random();

            var dict = new Dictionary <ushort, Node>();
            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 (dict.ContainsKey(seq));

                    Assert.True(tree.TryAddOrGet(new Protocol.Ordinal(seq), Allocator, out Node node));
                    Assert.NotNull(node);
                    Assert.False(tree.IsEmpty);
                    dict.Add(seq, node);
                }

                foreach (var kv in dict)
                {
                    Assert.False(tree.TryAddOrGet(new Protocol.Ordinal(kv.Key), Allocator, out Node node));
                    Assert.NotNull(node);
                    Assert.False(tree.IsEmpty);
                }
            }
        }
Ejemplo n.º 2
0
        public void TryAddOrGetOne(ushort seq)
        {
            var tree = new Carambolas.Net.Channel.Inbound.Node.Tree <Node>();

            Assert.True(tree.TryAddOrGet(new Protocol.Ordinal(seq), Allocator, out Node node1));
            Assert.NotNull(node1);
            Assert.False(tree.IsEmpty);

            Assert.False(tree.TryAddOrGet(new Protocol.Ordinal(seq), Allocator, out Node node2));
            Assert.False(tree.IsEmpty);

            Assert.Same((object)node1, (object)node2);
        }