public void ShouldNotAddIfAlreadyExists()
            {
                // ReSharper disable once UseObjectOrCollectionInitializer
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                set.Add(0);
                set.Add(1);
                set.Add(2);
                set.Add(3);
                set.Count.Should().Be(4);
                set.Should().ContainInOrder(0, 1, 2, 3);
            }
Exemplo n.º 2
0
            public void ShouldBeAbleToAccessNewlyAddedItem()
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                // we loop serveral turns on the full set
                for (var i = 0; i < 3 * set.Count; i++)
                {
                    int real;
                    set.TryNext(out real).Should().BeTrue();
                    real.Should().Be(i % set.Count);
                }

                // we add a new item into the set
                set.Add(4);

                // we loop again and everything is in set
                for (var i = 0; i < 3 * set.Count; i++)
                {
                    int real;
                    set.TryNext(out real).Should().BeTrue();
                    real.Should().Be(i % set.Count);
                }
            }
            public void ShouldAddNew()
            {
                // ReSharper disable once UseObjectOrCollectionInitializer
                var set = new ConcurrentRoundRobinSet <int>();

                set.Add(1);
                set.Count.Should().Be(1);
                set.ToList().Should().ContainInOrder(1);
            }
            public void ShouldBeAbleToAccessNewlyAddedItem(int times)
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                // we loop serveral turns on the full set
                for (var j = 0; j < times; j++)
                {
                    for (var i = 0; i < set.Count; i++)
                    {
                        int real;
                        set.TryNext(out real).Should().BeTrue();
                        real.Should().Be(i);
                    }
                }

                // we add a new item into the set
                set.Add(4);

                // we loop again and everything is in set
                for (var j = 0; j < times; j++)
                {
                    int real;

                    // first we got the newly added out
                    set.TryNext(out real).Should().BeTrue();
                    real.Should().Be(4);

                    for (var i = 0; i < set.Count - 1; i++)
                    {
                        set.TryNext(out real).Should().BeTrue();
                        real.Should().Be(i);
                    }
                }
            }