Exemplo n.º 1
0
        public void RemoveRandom()
        {
            var rd = new RouletteDictionary <string, int>();

            for (int i = 0; i < 10; i++)
            {
                rd[i.ToString()] = i;
            }

            bool removed = rd.RemoveRandom();

            Assert.True(removed);
            Assert.Equal(9, rd.Count);
        }
Exemplo n.º 2
0
        public void RemoveRandomWithCondition()
        {
            var rd = new RouletteDictionary <string, int>();

            for (int i = 0; i < 10; i++)
            {
                rd[i.ToString()] = i;
            }

            // remove all 5 even numbers using RemoveRandom
            for (int i = 0; i < 5; i++)
            {
                bool removed = rd.RemoveRandom((val) => val % 2 == 0);
                Assert.True(removed);
            }

            // make sure everything left is odd.
            Assert.Equal(5, rd.Count);
            foreach (int val in rd.Values)
            {
                Assert.True(val % 2 == 1);
            }
        }