コード例 #1
0
        public void Add()
        {
            var list1   = new List <string>();
            var index1  = new SpeedyListIndex <string>(list1);
            var indices = TestUtility.GetPrivateField <StringIndex>(index1, "indices");

            index1.Add("test 1", 0);
            Assert.AreEqual(1, indices.Count);

            index1.Add(null, 10);
            Assert.AreEqual(1, indices.Count);

            index1.Add("test 2", 1);
            Assert.AreEqual(2, indices.Count);

            index1.Add("test 1", 2);
            Assert.AreEqual(2, indices.Count);
            Assert.AreEqual(2, indices["test 1"].Count);
            Assert.AreEqual(0, indices["test 1"][0]);
            Assert.AreEqual(2, indices["test 1"][1]);

            int count = 0;

            foreach (string key in indices.Keys)
            {
                switch (count)
                {
                case 0:
                    Assert.AreEqual("test 1", key);
                    break;

                case 1:
                    Assert.AreEqual("test 2", key);
                    break;
                }
                count++;
            }
            Assert.AreEqual(2, count);

            bool catched = false;

            try {
                var test = indices["test 1"][2];
            } catch (ArgumentOutOfRangeException) {
                catched = true;
            }
            Assert.IsTrue(catched);

            catched = false;
            try {
                var test = indices["test 1"][-1];
            } catch (ArgumentOutOfRangeException) {
                catched = true;
            }
            Assert.IsTrue(catched);

            index1.Clear();
            Assert.AreEqual(0, indices.Count);
        }
コード例 #2
0
        public void Contains()
        {
            var list1     = new List <string>();
            var index1    = new SpeedyListIndex <string>(list1);
            var indices   = TestUtility.GetPrivateField <StringIndex>(index1, "indices");
            var nullIndex = TestUtility.GetPrivateField <List <int> >(index1, "nullIndex");

            Assert.IsFalse(index1.Contains("test 1"));
            Assert.IsFalse(index1.Contains(null));

            index1.Add("test 1", 0);
            Assert.IsTrue(index1.Contains("test 1"));

            index1.Remove("test 1");
            Assert.IsFalse(index1.Contains("test 1"));

            index1.Remove("test 1");
            Assert.IsFalse(index1.Contains("test 1"));

            index1.Add("test 2", 1);
            Assert.IsFalse(index1.Contains("test 1"));
            Assert.IsTrue(index1.Contains("test 2"));

            index1.Add(null, 2);
            Assert.IsTrue(index1.Contains(null));

            index1.Add(null, 3);
            Assert.IsTrue(index1.Contains(null));

            index1.Remove(null);
            Assert.IsTrue(index1.Contains(null));

            index1.Remove(null);
            Assert.IsFalse(index1.Contains(null));

            index1.Remove(null);
            Assert.IsFalse(index1.Contains(null));
        }
コード例 #3
0
        public void IndexOf()
        {
            var list1   = new List <string>();
            var index1  = new SpeedyListIndex <string>(list1);
            var indices = TestUtility.GetPrivateField <StringIndex>(index1, "indices");

            index1.Add("test 1", 1);
            index1.Add("test 1", 3);
            index1.Add("test 1", 5);
            index1.Add("test 2", 2);
            index1.Add("test 3", 4);
            index1.Add(null, 6);
            Assert.AreEqual(1, index1.IndexOf("test 1"));

            index1.Remove("test 1");
            Assert.IsTrue(index1.Contains("test 1"));
            Assert.AreEqual(3, index1.IndexOf("test 1"));

            index1.Remove("test 1");
            Assert.IsTrue(index1.Contains("test 1"));
            Assert.AreEqual(5, index1.IndexOf("test 1"));

            index1.Remove("test 1");
            Assert.IsFalse(index1.Contains("test 1"));
            Assert.AreEqual(-1, index1.IndexOf("test 1"));

            index1.Remove("test 1");
            Assert.IsFalse(index1.Contains("test 1"));
            Assert.AreEqual(-1, index1.IndexOf("test 1"));

            Assert.IsTrue(index1.Contains("test 2"));
            Assert.IsTrue(index1.Contains("test 3"));
            Assert.AreEqual(2, index1.IndexOf("test 2"));
            Assert.AreEqual(4, index1.IndexOf("test 3"));
            Assert.AreEqual(-1, index1.IndexOf("test 4"));

            Assert.AreEqual(6, index1.IndexOf(null));
            index1.Remove(null);
            Assert.AreEqual(-1, index1.IndexOf(null));
            index1.Remove(null);
            Assert.AreEqual(-1, index1.IndexOf(null));
        }