コード例 #1
0
        public void RemoveAt()
        {         //****************************************
            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];

                Records.RemoveAt(InnerIndex);
                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);
        }