[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);
            }
        }
        public override void DoLoad()
        {
            StringKeyDictionary dict = new StringKeyDictionary();

            dict.Add(BACKGROUND_SPRITE_KEY, _backgroundSprite);
            DoLoadImpl(dict, false);
        }
        public void Replace()
        {         //****************************************
            var MyRecords = new StringKeyDictionary <int>();

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

            MyRecords.Add("A", 1);
            MyRecords.Add("B", 2);
            MyRecords.Add("C", 3);
            MyRecords.Add("D", 4);
            MyRecords["B"] = 84;

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

            Assert.AreEqual(84, MyRecords["B"]);
        }
        public void RemoveAll()
        {         //****************************************
            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);
            }

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

            Records.RemoveAll((pair) => { if (Random.Next() > int.MaxValue / 2)
                                          {
                                              return(Dictionary.Remove(pair.Key));
                                          }
                                          return(false); });

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

            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);
        }
        public void AddCapacity()
        {         //****************************************
            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);
            }

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

            Assert.AreEqual(1024, 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);
        }
        [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;
                }
            }
        }
예제 #7
0
파일: EvalVisitor.cs 프로젝트: rexzh/RexToy
        public override object Visit(HashNode obj)
        {
            StringKeyDictionary <object> tuple = new StringKeyDictionary <object>();

            foreach (var kvp in obj.KVPairs)
            {
                tuple.Add(kvp.Key, kvp.Value.Accept(this));
            }
            return(tuple);
        }
        public void AddExists()
        {         //****************************************
            var MyRecords = new StringKeyDictionary <int>();

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

            MyRecords.Add("A", 84);

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

            try
            {
                MyRecords.Add("A", 84);

                Assert.Fail("Add succeeded");
            }
            catch (ArgumentException)
            {
            }
        }
        public void ClearAdd()
        {         //****************************************
            var Random  = Initialise();
            var Records = new StringKeyDictionary <int>(1024);

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

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

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

            Records.Clear();

            foreach (var Pair in YieldRandom(Random, 1024))
            {
                Records.Add(Pair.Key, Pair.Value);
            }
        }
        public void AddRangePrePopulated()
        {         //****************************************
            var Random  = Initialise();
            var Records = new StringKeyDictionary <int>();

            var Dictionary = new Dictionary <string, int>(1024);
            var SecondSet  = new List <KeyValuePair <string, int> >(512);

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

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

                if (Records.Count < 512)
                {
                    Records.Add(Pair.Key, Pair.Value);
                }
                else
                {
                    SecondSet.Add(Pair);
                }
            }

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

            Records.AddRange(SecondSet);

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

            Assert.AreEqual(1024, 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);
        }
        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);
        }
        [Test()]  //, Repeat(2)]
        public void EnumerateValues()
        {         //****************************************
            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);
            }

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

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

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

            Thread.Sleep(1);
        }
        public void RemoveRange()
        {         //****************************************
            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);
            }

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

            foreach (var Key in Enumerable.Skip <string>(Records.Keys, 256).Take(256))
            {
                Dictionary.Remove(Key);
            }

            Records.RemoveRange(256, 256);

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

            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);
        }
예제 #14
0
 public void TestAdd()
 {
     _dict.Add("three", 3);
 }
예제 #15
0
 public IgnoreCaseStringDictTest()
 {
     _dict = new StringKeyDictionary <int>(true);
     _dict.Add("One", 1);
     _dict.Add("Two", 2);
 }
예제 #16
0
 public IgnoreCaseStringDictTest()
 {
     _dict = new StringKeyDictionary<int>(true);
     _dict.Add("One", 1);
     _dict.Add("Two", 2);
 }