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

                set.TryNext(out value).Should().BeFalse();
                value.Should().Be(default(int));
            }
            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 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);
                    }
                }
            }
Esempio n. 6
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);
                }
            }
            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);
            }