コード例 #1
0
        [Test()]  //, Repeat(2)]
        public void AddRemoveAll()
        {         //****************************************
            var Random  = Initialise();
            var Records = new StringKeyDictionary <int>(1024);

            //****************************************

            foreach (var Pair in YieldRandom(Random, 1024))
            {
                Records.Add(Pair.Key, Pair.Value);
            }

            //****************************************

            while (Records.Count > 0)
            {
                var Key = ((IList <KeyValuePair <string, int> >)Records)[Random.Next(0, Records.Count)].Key;

                Records.Remove(Key);
            }

            foreach (var Pair in YieldRandom(Random, 1024))
            {
                Records.Add(Pair.Key, Pair.Value);
            }
        }
コード例 #2
0
        [Test()]  //, Repeat(2)]
        public void AddRemove()
        {         //****************************************
            var Random  = Initialise();
            var Records = new StringKeyDictionary <int>();

            //****************************************

            foreach (var Pair in YieldRandom(Random, 16))
            {
                Records.Add(Pair.Key, Pair.Value);
            }

            var Inputs = new Queue <KeyValuePair <string, int> >(YieldRandom(Random, 1024));

            //****************************************

            for (var Index = 0; Index < 1024; Index++)
            {
                if (Index % 10 >= 5 && Records.Count > 0)
                {
                    var Key = ((IList <KeyValuePair <string, int> >)Records)[Random.Next(0, Records.Count)].Key;

                    Records.Remove(Key);
                }
                else
                {
                    var Pair = Inputs.Dequeue();

                    Records[Pair.Key] = Pair.Value;
                }
            }
        }
コード例 #3
0
        public void Remove()
        {         //****************************************
            var Random  = Initialise();
            var Records = new StringKeyDictionary <int>();

            var Dictionary = new Dictionary <string, int>(1024);

            //****************************************

            foreach (var Pair in YieldRandom(Random, 1024))
            {
                Dictionary.Add(Pair.Key, Pair.Value);
                Records.Add(Pair.Key, Pair.Value);
            }

            //****************************************

            for (var Index = 0; Index < 512; Index++)
            {
                var InnerIndex = Random.Next(Records.Count);

                var Key = Records.Keys[InnerIndex];

                Assert.IsTrue(Records.Remove(Key));
                Assert.IsTrue(Dictionary.Remove(Key));
            }

            //****************************************

            Assert.AreEqual(512, Records.Count, "Count incorrect");

            CollectionAssert.AreEquivalent(Dictionary, Records, "Collections don't match");

            foreach (var MyPair in Dictionary)
            {
                Assert.IsTrue(Records.TryGetValue(MyPair.Key, out var Value));
                Assert.AreEqual(MyPair.Value, Value);
            }

            Thread.Sleep(1);
        }