public void ShouldBeAbleToRemoveItem(int times)
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                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);
                    }
                }

                set.Remove(3);

                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);
                    }
                }
            }
Example #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 ShouldReturnFalseIfNoElementInSet()
            {
                var set = new ConcurrentRoundRobinSet <int>();
                int value;

                set.TryNext(out value).Should().BeFalse();
                value.Should().Be(default(int));
            }
            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 ShouldRemove()
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                set.Remove(0);
                set.Remove(2);
                set.ToList().Should().ContainInOrder(1, 3);
            }
            public void ShouldNotMoveIfNotExists()
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1
                };

                set.Remove(3);
                set.Count.Should().Be(2);
                set.ToList().Should().ContainInOrder(0, 1);
            }
            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);
            }
            public void ShouldRoundRobin()
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                for (var i = 0; i < 10; i++)
                {
                    int real;
                    set.TryNext(out real).Should().BeTrue();
                    var expect = i % set.Count;
                    real.Should().Be(expect);
                }
            }
            public void ShouldClear()
            {
                // Given
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };
                int ignored;

                set.TryNext(out ignored);
                set.Index.Should().Be(1);

                // When
                set.Clear();

                // Then
                set.Should().BeEmpty();
                set.Index.Should().Be(0);
            }
            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);
                    }
                }
            }
Example #11
0
            public void ShouldBeAbleToRemoveItem()
            {
                var set = new ConcurrentRoundRobinSet <int> {
                    0, 1, 2, 3
                };

                for (var i = 0; i < 3 * set.Count; i++)
                {
                    int real;
                    set.TryNext(out real).Should().BeTrue();
                    var expect = i % set.Count;
                    real.Should().Be(expect);
                }

                set.Remove(3);

                for (var i = 0; i < 3 * set.Count; i++)
                {
                    int real;
                    set.TryNext(out real).Should().BeTrue();
                    var expect = i % set.Count;
                    real.Should().Be(expect);
                }
            }